From f87574bd5b8041c74cdb2e7b184c73ec3b3630a8 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Mon, 10 Oct 2016 18:29:58 -0400 Subject: [PATCH 01/29] removed static GVALUES for now --- .grutrc | 5 +- histos/MakeHistos_e10010.cxx | 463 ++++++++++++++++++++++++++ libraries/TDetSystems/TS800/TS800.cxx | 35 +- 3 files changed, 493 insertions(+), 10 deletions(-) create mode 100644 histos/MakeHistos_e10010.cxx diff --git a/.grutrc b/.grutrc index 0389418a..6747e781 100644 --- a/.grutrc +++ b/.grutrc @@ -4,7 +4,8 @@ Unix.*.Root.MacroPath: .:$(GRUTSYS)/util:$(ROOTSYS)/macros #default MakeHistos library #GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosSourcesSim.so -GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosInBeam.so +#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosInBeam.so +GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010.so GRUT.GuiSetup: $(GRUTSYS)/gui_params.hist @@ -13,7 +14,7 @@ GRUT.GuiSetup: $(GRUTSYS)/gui_params.hist GRUT.SnapshotExt: GRUT.SnapshotDir: -#GRUT.DefaultCutFile: mycuts.root +GRUT.DefaultCutFile: mycuts.cuts #files to load at log in: Rint.Logon: $(GRUTSYS)/.grut_logon diff --git a/histos/MakeHistos_e10010.cxx b/histos/MakeHistos_e10010.cxx new file mode 100644 index 00000000..ac794884 --- /dev/null +++ b/histos/MakeHistos_e10010.cxx @@ -0,0 +1,463 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p43=0; +GCutG *incoming_s44=0; +GCutG *incoming_cl46=0; + +GCutG *outgoing_s44=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge()) ) + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 2000, 3000, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -2500, -1500, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 30000, 70000, + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TS800* s800, GCutG *incoming, GCutG *outgoing){ + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().Charge()) ) + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 4000, 0, 4000, + hit.GetDoppler(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 4000, 0, 4000, + hit.GetDoppler(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 1000, 0, 4000, + hit.GetDoppler(beta, 0)); + + // Time cut + if( gt_time && !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 4000, 0, 4000, + hit.GetDoppler(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 4000, 0, 4000, + hit.GetDoppler(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 1000, 0, 4000, + hit.GetDoppler(beta, 0)); + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p43) { + incoming_p43 = (GCutG*)gates->FindObject("incoming_p43"); + } + if(!incoming_s44) { + incoming_s44 = (GCutG*)gates->FindObject("in44S"); + } + if(!incoming_cl46) { + incoming_cl46 = (GCutG*)gates->FindObject("incoming_cl46"); + } + + if(!outgoing_s44) { + outgoing_s44 = (GCutG*)gates->FindObject("out44S"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p43); + IncomingS800(obj, s800, incoming_s44); + IncomingS800(obj, s800, incoming_cl46); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s44); + + DTA(obj, incoming_s44, outgoing_s44); + + if(gretina) { + + HandleGretina(obj, incoming_s44, outgoing_s44, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 4000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 4000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 500, 0, 4000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 500, 0, 4000, + hit.GetCoreEnergy()); + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + //std::cout << " After Gret Calorimeter" << std::endl; + if(numobj!=list->GetSize()) + list->Sort(); + //std::cout << " end" << std::endl; +} + diff --git a/libraries/TDetSystems/TS800/TS800.cxx b/libraries/TDetSystems/TS800/TS800.cxx index 78ef314f..35dbf5b9 100644 --- a/libraries/TDetSystems/TS800/TS800.cxx +++ b/libraries/TDetSystems/TS800/TS800.cxx @@ -24,8 +24,8 @@ bool TS800::fGlobalReset =false; -static double f_mafp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); -static double f_mxfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); +//static double f_mafp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); +//static double f_mxfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); @@ -189,6 +189,7 @@ float TS800::GetAFP() const{ return sqrt(-1); } float AFP = TMath::ATan((GetXFP(1)-GetXFP(0))/1073.0); + return AFP; } @@ -716,9 +717,27 @@ float TS800::GetTofE1_MTDC(float c1,float c2,int i) const { for(unsigned int x=0;x Date: Tue, 11 Oct 2016 14:36:43 -0400 Subject: [PATCH 02/29] filter stuff --- filters/Filter_e10010.cxx | 16 +- histos/MakeHistos_e10010.cxx | 26 ++- histos/MakeHistos_e10100.cxx | 369 ----------------------------------- 3 files changed, 27 insertions(+), 384 deletions(-) delete mode 100644 histos/MakeHistos_e10100.cxx diff --git a/filters/Filter_e10010.cxx b/filters/Filter_e10010.cxx index 7abd5d8d..63ec4c06 100644 --- a/filters/Filter_e10010.cxx +++ b/filters/Filter_e10010.cxx @@ -11,20 +11,26 @@ extern "C" bool FilterCondition(TRuntimeObjects& obj) { - TGretina *gretina = obj.GetDetector(); TS800 *s800 = obj.GetDetector(); - if(!s800) + if(!gretina) return false; - + + if(!s800){ + // printf("i am returning false ***\n"); fflush(stdout); + return false; + } //if((s800->GetTrigger().GetRegistr()&0x0002)>>1) // return true; + + // std::cout << s800->Size() << std::endl; + if(s800->GetTrigger().GetRegistr()==3) { - //printf("i am returning true\n"); fflush(stdout); + // printf("i am returning true\n"); fflush(stdout); return true; } - + // printf("i am returning false ***\n"); fflush(stdout); return false; diff --git a/histos/MakeHistos_e10010.cxx b/histos/MakeHistos_e10010.cxx index ac794884..90ac0076 100644 --- a/histos/MakeHistos_e10010.cxx +++ b/histos/MakeHistos_e10010.cxx @@ -164,16 +164,13 @@ bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { } -bool DTA(TS800* s800, GCutG *incoming, GCutG *outgoing){ +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return false; - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - if(!incoming || !outgoing) return false; @@ -184,7 +181,16 @@ bool DTA(TS800* s800, GCutG *incoming, GCutG *outgoing){ if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), s800->GetIonChamber().GetSum()) ) return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + return true; } bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ @@ -269,13 +275,13 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, std::string histname = Form("doppler_%s",outgoing->GetName()); obj.FillHistogram(dirname, histname, - 4000, 0, 4000, + 1000, 0, 4000, hit.GetDoppler(beta, 0)); histname = Form("doppler_s800_%s",outgoing->GetName()); TVector3 track = s800->Track(); obj.FillHistogram(dirname, histname, - 4000, 0, 4000, + 1000, 0, 4000, hit.GetDoppler(beta, &track)); histname = Form("doppler_theta_%s_t",outgoing->GetName()); @@ -292,12 +298,12 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, histname = Form("doppler_%s_t",outgoing->GetName()); obj.FillHistogram(dirname, histname, - 4000, 0, 4000, + 1000, 0, 4000, hit.GetDoppler(beta, 0)); histname = Form("doppler_s800_%s_t",outgoing->GetName()); obj.FillHistogram(dirname, histname, - 4000, 0, 4000, + 1000, 0, 4000, hit.GetDoppler(beta, &track)); histname = Form("doppler_theta_%s_t",outgoing->GetName()); diff --git a/histos/MakeHistos_e10100.cxx b/histos/MakeHistos_e10100.cxx deleted file mode 100644 index 8c23ffa7..00000000 --- a/histos/MakeHistos_e10100.cxx +++ /dev/null @@ -1,369 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -//#define Q1 15 -//#define Q2 7 -//#define Q3 8 -//#define Q4 16 -//#define Q5 9 -//#define Q6 14 -//#define Q7 17 -//#define Q8 6 -//#define Q9 19 - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p=0; -GCutG *incoming_s=0; -GCutG *incoming_cl=0; - -GCutG *outgoing_44s=0; - -bool OutgoingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge()) ) - return false; - dirname = Form("S800_%s",outgoing->GetName()); - } else { - dirname = "S800"; - } - histname = "incoming"; - obj.FillHistogram(dirname,histname,2000,-2500,-500,s800->GetOBJ_E1Raw_MESY(), - 2000,1500,4500, s800->GetXF_E1Raw_MESY()); - - - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname; - std::string histname; - if(incoming) { - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(),s800->GetXF_E1Raw_MESY()) ) - return false; - dirname = Form("S800_%s",incoming->GetName()); - } else { - dirname = "S800"; - } - - - TMTof &mtof = s800->GetMTof(); - - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetOBJ_E1Raw_MESY(), -// 2000,1500,4500, s800->GetXF_E1Raw_MESY()); -// -// -// histname = "time_x"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - - - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname,histname,20,0,20,j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname,histname,20,0,20,s800->GetTrigger().GetRegistr()); - - - return true; -} - - - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming,GCutG *outgoing,GCutG *time) { - - if(!incoming || !outgoing) - return false; - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(),s800->GetXF_E1Raw_MESY()) ) - return false; - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge()) ) - return false; - - std::string dirname = Form("gretina_%s",outgoing->GetName()); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = "doppler"; - TVector3 track = s800->Track(); - obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetDoppler(0.354,&track)); - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p) { - incoming_p = (GCutG*)gates->FindObject("incoming_p"); - } - if(!incoming_s) { - incoming_s = (GCutG*)gates->FindObject("incoming_s"); - } - if(!incoming_cl) { - incoming_cl = (GCutG*)gates->FindObject("incoming_cl"); - } - - if(!outgoing_44s) { - outgoing_44s = (GCutG*)gates->FindObject("outgoing_44s"); - } - - - - - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - // printf("I am here\n"); fflush(stdout); - - if(s800) { - dirname = "S800"; - - IncomingS800(obj,s800,0); - IncomingS800(obj,s800,incoming_p); - IncomingS800(obj,s800,incoming_s); - IncomingS800(obj,s800,incoming_cl); - - OutgoingS800(obj,s800,outgoing_44s); - - if(gretina) { - - HandleGretina(obj,incoming_s,outgoing_44s,0); - - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500,-250,250,s800->GetTimestamp()-hit.GetTimestamp(), - 1000,0,4000,hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500,-250,250,s800->GetTimestamp()-hit.GetTime(), - 1000,0,4000,hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500,-250,250,s800->GetTimestamp()-hit.GetTimestamp(), - 1000,0,4000,hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500,-250,250,s800->GetTimestamp()-hit.GetTime(), - 1000,0,4000,hit.GetCoreEnergy()); - } - } - - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - histname = "IonChamberSum"; - obj.FillHistogram(histname,4000,0,32000,s800->GetIonChamber().GetSum()); - } - //std::cout << " After Gret Calorimeter" << std::endl; - if(numobj!=list->GetSize()) - list->Sort(); - //std::cout << " end" << std::endl; -} - - - -bool FilterCondition(TRuntimeObjects& obj) { - - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - - if((s800->GetTrigger().GetRegistr()&0x0002)>>1) - return true; - - return false; - - -} - From b18bd4851aa8c9111741d9bec189b6a941270517 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Wed, 12 Oct 2016 01:30:21 -0400 Subject: [PATCH 03/29] Histos and filter mods --- filters/Filter_e10010.cxx | 8 +- histos/MakeHistos_e10010.cxx | 244 ++++++++++++++++++++++++++++++++++- 2 files changed, 245 insertions(+), 7 deletions(-) diff --git a/filters/Filter_e10010.cxx b/filters/Filter_e10010.cxx index 63ec4c06..2a2b4cc0 100644 --- a/filters/Filter_e10010.cxx +++ b/filters/Filter_e10010.cxx @@ -21,12 +21,14 @@ bool FilterCondition(TRuntimeObjects& obj) { // printf("i am returning false ***\n"); fflush(stdout); return false; } - //if((s800->GetTrigger().GetRegistr()&0x0002)>>1) - // return true; + + // std::cout << s800->Size() << std::endl; - if(s800->GetTrigger().GetRegistr()==3) { + + // if(s800->GetTrigger().GetRegistr()==3) { + if( s800->GetTrigger().GetRegistr()&0x0002 ){ // printf("i am returning true\n"); fflush(stdout); return true; } diff --git a/histos/MakeHistos_e10010.cxx b/histos/MakeHistos_e10010.cxx index 90ac0076..aeb9da18 100644 --- a/histos/MakeHistos_e10010.cxx +++ b/histos/MakeHistos_e10010.cxx @@ -239,6 +239,240 @@ bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ } +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + Int_t energyNChannels = 1000; + Double_t energyLlim = 0.; + Double_t energyUlim = 4000.; + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + // Preprocessing + if( hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ){ + + calorimeterEnergy += hit.GetCoreEnergy(); + + if( hit.HasInteractions() ) + hits.push_back(hit); + + } + } + + // Addback + obj.FillHistogram(dirname, + "calorimeter", + 1000, 0, 4000, + calorimeterEnergy); + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + // Find the largest IP in the cluster and save its position + // for Doppler correction. + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) + > firstHitEnergy){ + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; + firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1) + addbackType = "n0"; + else if(neighbors == 1 && cluster.size() == 2) + addbackType = "n1"; + else if(neighbors == 3 && cluster.size() == 3) + addbackType = "n2"; + else + addbackType = "ng"; + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + if(firstHitHoleNum < 10){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + if(firstHitHoleNum < 10){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + if(firstHitHoleNum < 10){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + return true; + +} + bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, GCutG *outgoing, GCutG *gt_time) { @@ -284,7 +518,7 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, 1000, 0, 4000, hit.GetDoppler(beta, &track)); - histname = Form("doppler_theta_%s_t",outgoing->GetName()); + histname = Form("doppler_theta_%s",outgoing->GetName()); obj.FillHistogram(dirname, histname, 100, 0, TMath::Pi(), hit.GetTheta(), @@ -386,6 +620,8 @@ void MakeHistograms(TRuntimeObjects& obj) { HandleGretina(obj, incoming_s44, outgoing_s44, gt_time); + HandleAddback(obj, incoming_s44, outgoing_s44, gt_time); + dirname = "gretina"; for(unsigned int i=0;iSize();i++) { TGretinaHit hit = gretina->GetGretinaHit(i); @@ -397,7 +633,7 @@ void MakeHistograms(TRuntimeObjects& obj) { hit.GetCoreEnergy()); histname = "dtimet0_all"; obj.FillHistogram(dirname,histname, - 500, -250, 250, + 500, 0, 500, s800->GetTimestamp()-hit.GetTime(), 1000, 0, 4000, hit.GetCoreEnergy()); @@ -461,9 +697,9 @@ void MakeHistograms(TRuntimeObjects& obj) { s800->GetCrdc(1).GetDispersiveX()); } - //std::cout << " After Gret Calorimeter" << std::endl; + if(numobj!=list->GetSize()) list->Sort(); - //std::cout << " end" << std::endl; + } From 8392a512f30be4baac9a53cca141f39fd1dfb1f2 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 6 Jun 2017 09:04:39 -0400 Subject: [PATCH 04/29] Update to histos/MakeHistosInBeamLH.cxx for e10010 --- .grutrc | 5 +- histos/MakeHistosInBeamLH.cxx | 59 +++++++----- histos/MakeHistosSourcesSim.cxx | 133 +++++++++++++--------------- libraries/TGRUTint/TGRUTOptions.cxx | 1 + 4 files changed, 104 insertions(+), 94 deletions(-) diff --git a/.grutrc b/.grutrc index 6747e781..14205085 100644 --- a/.grutrc +++ b/.grutrc @@ -4,8 +4,9 @@ Unix.*.Root.MacroPath: .:$(GRUTSYS)/util:$(ROOTSYS)/macros #default MakeHistos library #GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosSourcesSim.so -#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosInBeam.so -GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010.so +GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosInBeamLH.so +#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010_p43.so +#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010_p41.so GRUT.GuiSetup: $(GRUTSYS)/gui_params.hist diff --git a/histos/MakeHistosInBeamLH.cxx b/histos/MakeHistosInBeamLH.cxx index bc7064c1..72368b57 100644 --- a/histos/MakeHistosInBeamLH.cxx +++ b/histos/MakeHistosInBeamLH.cxx @@ -27,7 +27,7 @@ #define Q1 15 #define Q2 7 #define Q3 11 -#define Q4 -1 +#define Q4 1 #define Q5 22 #define Q6 14 #define Q7 12 @@ -73,23 +73,7 @@ void MakeHistograms(TRuntimeObjects& obj) { TList *list = &(obj.GetObjects()); int numobj = list->GetSize(); - - if(gretSim){ - if(gretSim->Size() > 0){ - obj.FillHistogram("sim","beta", - 500, 0, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - obj.FillHistogram("sim","z", - 1000,-5,5., - gretSim->GetGretinaSimHit(0).GetZ()); - obj.FillHistogram("sim","beta_z", - 1000,-5,5., - gretSim->GetGretinaSimHit(0).GetZ(), - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - } - } - + if(!s800Sim) return; @@ -105,7 +89,7 @@ void MakeHistograms(TRuntimeObjects& obj) { // std::cout << std::flush; - Double_t dta = s800Sim->GetS800SimHit(0).GetDTA()*100.; + Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); // std::cout << " ATA = " // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; @@ -116,14 +100,27 @@ void MakeHistograms(TRuntimeObjects& obj) { // std::cout << " DTA = " // << dta << std::endl; + + obj.FillHistogram("s800","dta", + 200, -0.10, 0.10, + dta); + // Rough dta acceptance cut - // if(dta < -6. || dta > 6.) - // return; + if(dta < -0.06 || dta > 0.06) + return; - obj.FillHistogram("s800","dta", - 4096, -10, 10, + obj.FillHistogram("s800","dta_cut", + 200, -0.10, 0.10, dta); + obj.FillHistogram("s800","ata", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetATA()); + + obj.FillHistogram("s800","bta", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetBTA()); + Double_t xsin, ysin, scatter; xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); @@ -133,6 +130,22 @@ void MakeHistograms(TRuntimeObjects& obj) { obj.FillHistogram("s800","scatter", 4096, 0, 300, scatter); + if(gretSim){ + if(gretSim->Size() > 0){ + obj.FillHistogram("sim","beta", + 300, 0.2, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + obj.FillHistogram("sim","z", + 1000,-50,50., + gretSim->GetGretinaSimHit(0).GetZ()); + obj.FillHistogram("sim","beta_z", + 1000,-50.,50., + gretSim->GetGretinaSimHit(0).GetZ(), + 300, 0.2, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + } + } + } if(!gretina) diff --git a/histos/MakeHistosSourcesSim.cxx b/histos/MakeHistosSourcesSim.cxx index 4caefdb6..def89af3 100644 --- a/histos/MakeHistosSourcesSim.cxx +++ b/histos/MakeHistosSourcesSim.cxx @@ -59,6 +59,17 @@ void InitMap() { #define INTEGRATION 128.0 +Double_t measuredE(Double_t energy){ + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 0.; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.; + + return energy*gRandom->Gaus(1.0, exp(resPar1*log(energy)+resPar2)); +} + // extern "C" is needed to prevent name mangling. // The function signature must be exactly as shown here, // or else bad things will happen. @@ -86,15 +97,18 @@ void MakeHistograms(TRuntimeObjects& obj) { obj.FillHistogram("sim","emitted_phi", 360, 0., 360., hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); } } if(!gretina) return; - Double_t res = 1./1000.; // Relative energy resolution + // Double_t res = 1./1000.; // Relative energy resolution - Double_t calorimeterEnergy_gaus = 0.; + Double_t calorimeterEnergy = 0.; std::vector hits; // Gamma-gated crystal spectrum @@ -111,16 +125,15 @@ void MakeHistograms(TRuntimeObjects& obj) { for(int i=0; iSize(); i++){ TGretinaHit hit = gretina->GetGretinaHit(i); if(i != iGate){ + Double_t mE = measuredE(hit.GetCoreEnergy()); obj.FillHistogram("energy", - Form("energy_gaus_%.0f", + Form("energy_%.0f", (eGateLlim+eGateUlim)/2.0), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); + energyNChannels, energyLlim, energyUlim, mE); obj.FillHistogram("energy", - Form("fold_vs_energy_gaus_%.0f", + Form("fold_vs_energy_%.0f", (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res), + energyNChannels/8, energyLlim, energyUlim, mE, 20, 0, 20, hit.NumberOfInteractions()); // Count segment fold @@ -133,10 +146,9 @@ void MakeHistograms(TRuntimeObjects& obj) { } obj.FillHistogram("energy", - Form("segfold_vs_energy_gaus_%.0f", + Form("segfold_vs_energy_%.0f", (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res), + energyNChannels/8, energyLlim, energyUlim, mE, 20, 0, 20, segment_fold); } @@ -151,8 +163,7 @@ void MakeHistograms(TRuntimeObjects& obj) { if(hit.GetCoreEnergy() > energyLlim && hit.GetCoreEnergy() < energyUlim){ - calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,res); - + calorimeterEnergy += measuredE(hit.GetCoreEnergy()); hits.push_back(hit); } @@ -163,25 +174,18 @@ void MakeHistograms(TRuntimeObjects& obj) { for(int x=0; xSize(); x++){ TGretinaHit hit = gretina->GetGretinaHit(x); + Double_t mE = measuredE(hit.GetCoreEnergy()); // directory, histogram - obj.FillHistogram("energy", "overview_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res), + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, mE, 100, 0, 100, hit.GetCrystalId()); - obj.FillHistogram("energy", "energy_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, hit.NumberOfInteractions()); - - obj.FillHistogram("energy", "fold_vs_energy_gaus", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res), + energyNChannels/8, energyLlim, energyUlim, mE, 20, 0, 20, hit.NumberOfInteractions()); // Count segment fold @@ -194,19 +198,16 @@ void MakeHistograms(TRuntimeObjects& obj) { } obj.FillHistogram("energy", - "segfold_vs_energy_gaus", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res), + "segfold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, 20, 0, 20, segment_fold); if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", "energy_gaus_A", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); + obj.FillHistogram("energy", "energy_A", + energyNChannels, energyLlim, energyUlim, mE); else - obj.FillHistogram("energy", "energy_gaus_B", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); + obj.FillHistogram("energy", "energy_B", + energyNChannels, energyLlim, energyUlim, mE); // Peter wrote these to give Dirk his Phi range (0-360). obj.FillHistogram("position", "theta_vs_phi", @@ -263,31 +264,26 @@ void MakeHistograms(TRuntimeObjects& obj) { max_layer); if(max_layer == 5){ - obj.FillHistogram("energy", "energy_gaus_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); - obj.FillHistogram("energy", "overview_gaus_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res), + obj.FillHistogram("energy", "energy_involves_phi", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_involves_phi", + energyNChannels, energyLlim, energyUlim, mE, 100, 0, 100, hit.GetCrystalId()); } for(int k = 5; k > 0; k--){ if(max_layer < k){ obj.FillHistogram("energy", - Form("energy_gaus_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); + Form("energy_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); if( hit.GetCrystalId()%2 ) obj.FillHistogram("energy", - Form("energy_gaus_A_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); + Form("energy_A_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); else obj.FillHistogram("energy", - Form("energy_gaus_B_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,res)); + Form("energy_B_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); } } @@ -295,16 +291,16 @@ void MakeHistograms(TRuntimeObjects& obj) { } // Addback - obj.FillHistogram("addback", "calorimeter_gaus", + obj.FillHistogram("addback", "calorimeter", energyNChannels, energyLlim, energyUlim, - calorimeterEnergy_gaus); + calorimeterEnergy); for(int k = 5; k > 0; k--){ if(max_layer < k){ obj.FillHistogram("addback", - Form("calorimeter_gaus_below_%s", + Form("calorimeter_below_%s", LayerMap[k].c_str()), energyNChannels, energyLlim, energyUlim, - calorimeterEnergy_gaus); + calorimeterEnergy); } } @@ -347,10 +343,9 @@ void MakeHistograms(TRuntimeObjects& obj) { // Calculate the total energy deposited in the cluster, // and count the pairs of neighbors. Int_t neighbors = 0; - Double_t addbackEnergy_gaus = 0.; + Double_t addbackEnergy = 0.; for(int i = 0; i < cluster.size(); i++){ - addbackEnergy_gaus += - cluster[i].GetCoreEnergy()*gRandom->Gaus(1,res); + addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); for(int j = i+1; j < cluster.size(); j++){ TVector3 distance = cluster[i].GetCrystalPosition() - cluster[j].GetCrystalPosition(); @@ -370,23 +365,23 @@ void MakeHistograms(TRuntimeObjects& obj) { // Fill addback histograms. - obj.FillHistogram("addback", addbackType+"_gaus", + obj.FillHistogram("addback", addbackType, energyNChannels, energyLlim, energyUlim, - addbackEnergy_gaus); + addbackEnergy); if(addbackType == "addback_n0" || addbackType == "addback_n1"){ - obj.FillHistogram("addback", "addback_n0n1_gaus", + obj.FillHistogram("addback", "addback_n0n1", energyNChannels, energyLlim, energyUlim, - addbackEnergy_gaus); + addbackEnergy); } if(addbackType == "addback_n0" || addbackType == "addback_n1" || addbackType == "addback_n2"){ - obj.FillHistogram("addback", "addback_n0n1n2_gaus", + obj.FillHistogram("addback", "addback_n0n1n2", energyNChannels, energyLlim, energyUlim, - addbackEnergy_gaus); + addbackEnergy); } obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", @@ -394,11 +389,11 @@ void MakeHistograms(TRuntimeObjects& obj) { 10, 0, 10, cluster.size()); // For energy-gated addback spectra - if(addbackEnergy_gaus > eGateLlim && - addbackEnergy_gaus < eGateUlim) + if(addbackEnergy > eGateLlim && + addbackEnergy < eGateUlim) iGate = Naddback; - ABenergy.push_back(addbackEnergy_gaus); + ABenergy.push_back(addbackEnergy); ABtype.push_back(addbackType); Naddback++; @@ -409,7 +404,7 @@ void MakeHistograms(TRuntimeObjects& obj) { for(int i = 0; i Date: Mon, 3 Jun 2019 21:05:02 -0400 Subject: [PATCH 05/29] Fixed printing of fit results in GPeak::Fit() method --- libraries/GROOT/GPeak.cxx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/GROOT/GPeak.cxx b/libraries/GROOT/GPeak.cxx index 957b05e6..89f741ec 100644 --- a/libraries/GROOT/GPeak.cxx +++ b/libraries/GROOT/GPeak.cxx @@ -278,8 +278,7 @@ Bool_t GPeak::Fit(TH1 *fithist,Option_t *opt) { TFitResultPtr fitres = fithist->Fit(this,Form("%sLRSME",options.Data())); //fitres.Get()->Print(); - printf("chi^2/NDF = %.02f\n",this->GetChisquare()/(double)this->GetNDF()); - + // printf("chi^2/NDF = %.02f\n",this->GetChisquare()/(double)this->GetNDF()); if(!fitres.Get()->IsValid()) { @@ -350,21 +349,27 @@ Bool_t GPeak::Fit(TH1 *fithist,Option_t *opt) { fArea = this->Integral(xlow,xhigh) / fithist->GetBinWidth(1); double bgArea = fBGFit.Integral(xlow,xhigh) / fithist->GetBinWidth(1); + double DBgArea = fBGFit.IntegralError(xlow,xhigh) / fithist->GetBinWidth(1); fArea -= bgArea; + fDArea = this->IntegralError(xlow,xhigh) / fithist->GetBinWidth(1); + fDArea = TMath::Sqrt(fDArea*fDArea + DBgArea*DBgArea); + + fChi2 = this->GetChisquare(); + fNdf = (double)this->GetNDF(); if(xlow>xhigh) std::swap(xlow,xhigh); fSum = fithist->Integral(fithist->GetXaxis()->FindBin(xlow), fithist->GetXaxis()->FindBin(xhigh));// * fithist->GetBinWidth(1); - printf("sum between markers: %02f\n",fSum); + // printf("sum between markers: %02f\n",fSum); fDSum = TMath::Sqrt(fSum); fSum -= bgArea; - printf("sum after subtraction: %02f\n",fSum); + // printf("sum after subtraction: %02f\n",fSum); if(!verbose) { - printf("hist: %s\n",fithist->GetName()); + // printf("hist: %s\n",fithist->GetName()); Print();/* printf("BG Area: %.02f\n",bgArea); printf("GetChisquared(): %.4f\n", TF1::GetChisquare()); From 4806289bd6960d1dd96e8c1af3f3e5e781086d3c Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 4 Jun 2019 09:07:11 -0400 Subject: [PATCH 06/29] Fixed printing of fit results in GFaus::Fit() method --- libraries/GROOT/GGaus.cxx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/GROOT/GGaus.cxx b/libraries/GROOT/GGaus.cxx index 0844aa21..29d8297a 100644 --- a/libraries/GROOT/GGaus.cxx +++ b/libraries/GROOT/GGaus.cxx @@ -270,10 +270,20 @@ Bool_t GGaus::Fit(TH1 *fithist,Option_t *opt) { //fithist->GetListOfFunctions()->Print(); + // fArea = this->Integral(xlow,xhigh) / fithist->GetBinWidth(1); + // double bgArea = fBGFit.Integral(xlow,xhigh) / fithist->GetBinWidth(1);; + // fArea -= bgArea; + + fArea = this->Integral(xlow,xhigh) / fithist->GetBinWidth(1); - double bgArea = fBGFit.Integral(xlow,xhigh) / fithist->GetBinWidth(1);; + double bgArea = fBGFit.Integral(xlow,xhigh) / fithist->GetBinWidth(1); + double DBgArea = fBGFit.IntegralError(xlow,xhigh) / fithist->GetBinWidth(1); fArea -= bgArea; + fDArea = this->IntegralError(xlow,xhigh) / fithist->GetBinWidth(1); + fDArea = TMath::Sqrt(fDArea*fDArea + DBgArea*DBgArea); + fChi2 = this->GetChisquare(); + fNdf = (double)this->GetNDF(); if(xlow>xhigh) std::swap(xlow,xhigh); From b74ac1b8694495dd0164ad35fbc9ed6af6ce9079 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Wed, 19 May 2021 11:55:35 -0400 Subject: [PATCH 07/29] Final Expt. 10010 version --- .grutrc | 1 + histos/MakeHistos60CoLaBr.cxx | 285 +++++ histos/MakeHistos60CoSim.cxx | 489 +++++++++ histos/MakeHistosFDS.cxx | 250 +++++ histos/MakeHistosInBeam.cxx | 61 +- histos/MakeHistosInBeamAngCorr.cxx | 610 +++++++++++ histos/MakeHistosInBeamLH.cxx | 59 +- histos/MakeHistosNeutrons.cxx | 364 +++++++ histos/MakeHistosOslo.cxx | 156 +++ histos/MakeHistosPencil.cxx | 402 +++++++ histos/MakeHistosSourcesSim.cxx | 117 +- histos/MakeHistosTarEx.cxx | 430 ++++++++ histos/MakeHistosWhiteSim.cxx | 179 +++ histos/MakeHistos_e10010_Sim.cxx | 907 ++++++++++++++++ histos/MakeHistos_e10010_Trigger.cxx | 303 ++++++ histos/MakeHistos_e10010_Trigger_cl46.cxx | 345 ++++++ histos/MakeHistos_e10010_Trigger_p41.cxx | 352 ++++++ histos/MakeHistos_e10010_Trigger_p43.cxx | 352 ++++++ histos/MakeHistos_e10010_Trigger_s42.cxx | 345 ++++++ histos/MakeHistos_e10010_Trigger_s44.cxx | 307 ++++++ histos/MakeHistos_e10010_Trigger_si39.cxx | 345 ++++++ histos/MakeHistos_e10010_cl46.cxx | 1182 ++++++++++++++++++++ histos/MakeHistos_e10010_cl46_empty.cxx | 1182 ++++++++++++++++++++ histos/MakeHistos_e10010_p41.cxx | 1197 ++++++++++++++++++++ histos/MakeHistos_e10010_p43.cxx | 1182 ++++++++++++++++++++ histos/MakeHistos_e10010_p43_empty.cxx | 1182 ++++++++++++++++++++ histos/MakeHistos_e10010_s42.cxx | 1197 ++++++++++++++++++++ histos/MakeHistos_e10010_s42_empty.cxx | 1197 ++++++++++++++++++++ histos/MakeHistos_e10010_s44.cxx | 1206 +++++++++++++++++++++ histos/MakeHistos_e10010_si39.cxx | 1197 ++++++++++++++++++++ histos/MakeHistos_e10010_si39_empty.cxx | 1197 ++++++++++++++++++++ 31 files changed, 18479 insertions(+), 99 deletions(-) create mode 100644 histos/MakeHistos60CoLaBr.cxx create mode 100644 histos/MakeHistos60CoSim.cxx create mode 100644 histos/MakeHistosFDS.cxx create mode 100644 histos/MakeHistosInBeamAngCorr.cxx create mode 100644 histos/MakeHistosNeutrons.cxx create mode 100644 histos/MakeHistosOslo.cxx create mode 100644 histos/MakeHistosPencil.cxx create mode 100644 histos/MakeHistosTarEx.cxx create mode 100644 histos/MakeHistosWhiteSim.cxx create mode 100644 histos/MakeHistos_e10010_Sim.cxx create mode 100644 histos/MakeHistos_e10010_Trigger.cxx create mode 100644 histos/MakeHistos_e10010_Trigger_cl46.cxx create mode 100644 histos/MakeHistos_e10010_Trigger_p41.cxx create mode 100644 histos/MakeHistos_e10010_Trigger_p43.cxx create mode 100644 histos/MakeHistos_e10010_Trigger_s42.cxx create mode 100644 histos/MakeHistos_e10010_Trigger_s44.cxx create mode 100644 histos/MakeHistos_e10010_Trigger_si39.cxx create mode 100644 histos/MakeHistos_e10010_cl46.cxx create mode 100644 histos/MakeHistos_e10010_cl46_empty.cxx create mode 100644 histos/MakeHistos_e10010_p41.cxx create mode 100644 histos/MakeHistos_e10010_p43.cxx create mode 100644 histos/MakeHistos_e10010_p43_empty.cxx create mode 100644 histos/MakeHistos_e10010_s42.cxx create mode 100644 histos/MakeHistos_e10010_s42_empty.cxx create mode 100644 histos/MakeHistos_e10010_s44.cxx create mode 100644 histos/MakeHistos_e10010_si39.cxx create mode 100644 histos/MakeHistos_e10010_si39_empty.cxx diff --git a/.grutrc b/.grutrc index 14205085..5a6ef304 100644 --- a/.grutrc +++ b/.grutrc @@ -5,6 +5,7 @@ Unix.*.Root.MacroPath: .:$(GRUTSYS)/util:$(ROOTSYS)/macros #GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosSourcesSim.so GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosInBeamLH.so +#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosTarEx.so #GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010_p43.so #GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010_p41.so diff --git a/histos/MakeHistos60CoLaBr.cxx b/histos/MakeHistos60CoLaBr.cxx new file mode 100644 index 00000000..feb20a07 --- /dev/null +++ b/histos/MakeHistos60CoLaBr.cxx @@ -0,0 +1,285 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +Double_t measuredE(Double_t energy){ + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 1.2; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.0005; + + return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 4000; + Double_t energyLlim = 0.; + Double_t energyUlim = 4000.; + Double_t cosTheta = -1; + Double_t mCosTheta = -1; + Double_t x1 = -1; + Double_t y1 = -1; + Double_t z1 = -1; + Double_t x2 = -1; + Double_t y2 = -1; + Double_t z2 = -1; + + if(gretSim){ + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + if(hit.GetEn() > 1331 && hit.GetEn() < 1334){ + x1 = sin(hit.GetTheta())*cos(hit.GetPhi()); + y1 = sin(hit.GetTheta())*sin(hit.GetPhi()); + z1 = cos(hit.GetTheta()); + } + if(hit.GetEn() > 1171 && hit.GetEn() < 1175){ + x2 = sin(hit.GetTheta())*cos(hit.GetPhi()); + y2 = sin(hit.GetTheta())*sin(hit.GetPhi()); + z2 = cos(hit.GetTheta()); + } + } + cosTheta + = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); + obj.FillHistogram("sim","emitted_delta", + 100, -1, 1., + cosTheta); + } + + if(!gretina) + return; + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + int max_layer = -1; + + // LaBr-gate + Bool_t LaBr = false; + Double_t eGateLlim = 1327.5; + Double_t eGateUlim = 1337.5; + for(int x=0; xSize(); x++){ + TGretinaHit hit = gretina->GetGretinaHit(x); + if(hit.GetCrystalId() == 136){ + obj.FillHistogram("energy", "LaBr", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + if(hit.GetCoreEnergy() > eGateLlim && + hit.GetCoreEnergy() < eGateUlim ) + LaBr = true; + } + } + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + if(hit.GetCrystalId() == 136) // Ignore LaBr + continue; + + Double_t mE = measuredE(hit.GetCoreEnergy()); + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + if(LaBr){ + obj.FillHistogram("energy", "LaBr_gate", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_LaBr_gate", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + obj.FillHistogram("position", "theta_LaBr", + 1024, 0., TMath::Pi(), + hit.GetTheta()); + if(mE > 1168 && mE < 1178){ + obj.FillHistogram("position", "theta_LaBr_1173", + 1024, 0., TMath::Pi(), + hit.GetTheta()); + } + + } + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); + + obj.FillHistogram("energy", "fold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, hit.NumberOfInteractions()); + + // Symmetrized gamma-gamma matrix and angular correlation + for(int y=x+1; ySize(); y++){ + TGretinaHit hit2 = gretina->GetGretinaHit(y); + if(hit2.GetCrystalId() == 136) // Ignore LaBr + continue; + + Double_t mE2 = measuredE(hit2.GetCoreEnergy()); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE, + energyNChannels/4, energyLlim, energyUlim, mE2); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE2, + energyNChannels/4, energyLlim, energyUlim, mE); + } + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + "segfold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, segment_fold); + + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", "energy_A", + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", "energy_B", + energyNChannels, energyLlim, energyUlim, mE); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + obj.FillHistogram("position", "theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + for(int y=0; y < hit.NumberOfInteractions(); y++){ + + int layer = hit.GetSegmentId(y)/6; + + if(layer > max_layer) max_layer = layer; + + obj.FillHistogram("layers", + Form("theta_vs_phi_%s", LayerMap[layer].c_str()), + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + obj.FillHistogram("layers", "max_layer", 12, -2, 10, + max_layer); + + if(max_layer == 5){ + obj.FillHistogram("energy", "energy_involves_phi", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_involves_phi", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + } + + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("energy", + Form("energy_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", + Form("energy_A_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", + Form("energy_B_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + } + + } + + } + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistos60CoSim.cxx b/histos/MakeHistos60CoSim.cxx new file mode 100644 index 00000000..da8bdcf1 --- /dev/null +++ b/histos/MakeHistos60CoSim.cxx @@ -0,0 +1,489 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +Double_t measuredE(Double_t energy){ + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 1.2; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.0005; + + return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 4000; + Double_t energyLlim = 0.; + Double_t energyUlim = 4000.; + Double_t cosTheta = -1; + Double_t mCosTheta = -1; + Double_t x1 = -1; + Double_t y1 = -1; + Double_t z1 = -1; + Double_t x2 = -1; + Double_t y2 = -1; + Double_t z2 = -1; + + if(gretSim){ + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + if(hit.GetEn() > 1331 && hit.GetEn() < 1334){ + x1 = sin(hit.GetTheta())*cos(hit.GetPhi()); + y1 = sin(hit.GetTheta())*sin(hit.GetPhi()); + z1 = cos(hit.GetTheta()); + } + if(hit.GetEn() > 1171 && hit.GetEn() < 1175){ + x2 = sin(hit.GetTheta())*cos(hit.GetPhi()); + y2 = sin(hit.GetTheta())*sin(hit.GetPhi()); + z2 = cos(hit.GetTheta()); + } + } + cosTheta + = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); + obj.FillHistogram("sim","emitted_delta", + 100, -1, 1., + cosTheta); + } + + if(!gretina) + return; + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + // Gamma-gated crystal spectrum + Double_t eGateLlim = 1327.5; + Double_t eGateUlim = 1337.5; + int iGate = -1; + for(int i=0; iSize(); i++){ + TGretinaHit hit = gretina->GetGretinaHit(i); + if( hit.GetCoreEnergy() > eGateLlim && + hit.GetCoreEnergy() < eGateUlim ) + iGate = i; + } + if(iGate>=0){ + for(int i=0; iSize(); i++){ + TGretinaHit hit = gretina->GetGretinaHit(i); + if(i != iGate){ + Double_t mE = measuredE(hit.GetCoreEnergy()); + obj.FillHistogram("energy", + Form("energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", + Form("fold_vs_energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, hit.NumberOfInteractions()); + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + Form("segfold_vs_energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, segment_fold); + + } + } + } + + // Addback preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += measuredE(hit.GetCoreEnergy()); + hits.push_back(hit); + + } + } + + int max_layer = -1; + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + Double_t mE = measuredE(hit.GetCoreEnergy()); + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); + + obj.FillHistogram("energy", "fold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, hit.NumberOfInteractions()); + + // Symmetrized gamma-gamma matrix and angular correlation + for(int y=x+1; ySize(); y++){ + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t mE2 = measuredE(hit2.GetCoreEnergy()); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE, + energyNChannels/4, energyLlim, energyUlim, mE2); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE2, + energyNChannels/4, energyLlim, energyUlim, mE); + + if( (mE > 1168. && mE < 1178. && mE2 > 1328. && mE2 < 1337.) + || (mE2 > 1168. && mE2 < 1178. && mE > 1328. && mE < 1337.) ){ + TVector3 r1 = hit.GetFirstIntPosition_2(); + TVector3 r2 = hit2.GetFirstIntPosition_2(); + mCosTheta = r1.Dot(r2)/r1.Mag()/r2.Mag(); + obj.FillHistogram("position","delta", + 100, -1, 1., + mCosTheta); + obj.FillHistogram("position","cosTheta_mCosTheta", + 100, -1, 1., + cosTheta, + 100, -1, 1., + mCosTheta); + } + + } + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + "segfold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, segment_fold); + + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", "energy_A", + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", "energy_B", + energyNChannels, energyLlim, energyUlim, mE); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + // Position spectra in crystal coordinates + if(hit.NumberOfInteractions()){ + obj.FillHistogram("position", + Form("crys_%d_x", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).X()); + + obj.FillHistogram("position", + Form("crys_%d_y", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_z", hit.GetCrystalId()), + 1200, -10, 100, hit.GetLocalPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_xy", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).X(), + 1200, -60, 60, hit.GetLocalPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_xz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).X(), + 1200, -10, 100, hit.GetLocalPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_yz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).Y(), + 1200, -10, 100, hit.GetLocalPosition(0).Z()); + } + + for(int y=0; y < hit.NumberOfInteractions(); y++){ + + int layer = hit.GetSegmentId(y)/6; + + if(layer > max_layer) max_layer = layer; + + obj.FillHistogram("layers", + Form("theta_vs_phi_%s", LayerMap[layer].c_str()), + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + obj.FillHistogram("layers", "max_layer", 12, -2, 10, + max_layer); + + if(max_layer == 5){ + obj.FillHistogram("energy", "energy_involves_phi", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_involves_phi", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + } + + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("energy", + Form("energy_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", + Form("energy_A_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", + Form("energy_B_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + } + + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("addback", + Form("calorimeter_below_%s", + LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + } + } + + // For energy-gated addback spectra + std::vector ABenergy; + std::vector ABtype; + Int_t Naddback = 0; + iGate = -1; + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1) + addbackType = "addback_n0"; + else if(neighbors == 1 && cluster.size() == 2) + addbackType = "addback_n1"; + else if(neighbors == 3 && cluster.size() == 3) + addbackType = "addback_n2"; + else + addbackType = "addback_ng"; + + // Fill addback histograms. + + obj.FillHistogram("addback", addbackType, + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + + if(addbackType == "addback_n0" + || addbackType == "addback_n1"){ + obj.FillHistogram("addback", "addback_n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + if(addbackType == "addback_n0" + || addbackType == "addback_n1" + || addbackType == "addback_n2"){ + obj.FillHistogram("addback", "addback_n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + + // For energy-gated addback spectra + if(addbackEnergy > eGateLlim && + addbackEnergy < eGateUlim) + iGate = Naddback; + + ABenergy.push_back(addbackEnergy); + ABtype.push_back(addbackType); + Naddback++; + + } + + // Fill energy-gated addback spectra + if(iGate >= 0){ + for(int i = 0; iGetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistosFDS.cxx b/histos/MakeHistosFDS.cxx new file mode 100644 index 00000000..86e85a43 --- /dev/null +++ b/histos/MakeHistosFDS.cxx @@ -0,0 +1,250 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" + +Double_t measuredE(Double_t energy){ + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 1.2; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.0005; + + return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + + TGretina *gretina = obj.GetDetector(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 4000; + Double_t energyLlim = 0.; + Double_t energyUlim = 4000.; + + if(gretSim){ + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + } + } + + if(!gretina) + return; + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + Double_t mE = measuredE(hit.GetCoreEnergy()); + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, mE, + 250, 0, 250, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); + + if(gretSim && gretSim->Size()>0) + if(gretSim->GetGretinaSimHit(0).IsFEP()) + obj.FillHistogram("energy", "photopeak", + energyNChannels, energyLlim, energyUlim, mE); + + obj.FillHistogram("energy", "fold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, hit.NumberOfInteractions()); + + // Symmetrized gamma-gamma matrix + for(int y=x+1; ySize(); y++){ + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t mE2 = measuredE(hit2.GetCoreEnergy()); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE, + energyNChannels/4, energyLlim, energyUlim, mE2); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE2, + energyNChannels/4, energyLlim, energyUlim, mE); + } + + // crmat/crystal Transformations turned off for FDS, so local positions + // are in world coordinates. + TVector3 hitpos = hit.GetLocalPosition(0); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + // 360, 0., 360., + 360, -180., 180., + hitpos.Phi()*TMath::RadToDeg(), + 180, 0., 180., + hitpos.Theta()*TMath::RadToDeg()); + // hit.GetPhi()*TMath::RadToDeg(), + // 180, 0., 180., + // hit.GetTheta()*TMath::RadToDeg()); + + if(hit.GetSegmentId(0)==1) + obj.FillHistogram("position", "theta_vs_phi_R", + 360, -180., 180., + hitpos.Phi()*TMath::RadToDeg(), + 180, 0., 180., + hitpos.Theta()*TMath::RadToDeg()); + if(hit.GetSegmentId(0)==2){ + obj.FillHistogram("position", "theta_vs_phi_M", + 360, -180., 180., + hitpos.Phi()*TMath::RadToDeg(), + 180, 0., 180., + hitpos.Theta()*TMath::RadToDeg()); + if(hit.GetCrystalId()%4 == 0 || hit.GetCrystalId()%4 == 3) + obj.FillHistogram("position", "theta_vs_phi_MR", + 360, -180., 180., + hitpos.Phi()*TMath::RadToDeg(), + 180, 0., 180., + hitpos.Theta()*TMath::RadToDeg()); + if(hit.GetCrystalId()%4 == 1 || hit.GetCrystalId()%4 == 2) + obj.FillHistogram("position", "theta_vs_phi_ML", + 360, -180., 180., + hitpos.Phi()*TMath::RadToDeg(), + 180, 0., 180., + hitpos.Theta()*TMath::RadToDeg()); + } + if(hit.GetSegmentId(0)==3){ + obj.FillHistogram("position", "theta_vs_phi_L", + 360, -180., 180., + hitpos.Phi()*TMath::RadToDeg(), + 180, 0., 180., + hitpos.Theta()*TMath::RadToDeg()); + } + + // Position spectra in crystal coordinates + if(hit.NumberOfInteractions()){ + + obj.FillHistogram("position", "r", 500, 0, 500, hitpos.Mag()); + obj.FillHistogram("position", "x", 1000, -500, 500, hitpos.X()); + obj.FillHistogram("position", "y", 1000, -500, 500, hitpos.Y()); + obj.FillHistogram("position", "z", 1000, -500, 500, hitpos.Z()); + + obj.FillHistogram("position", + Form("crys_%d_x", hit.GetCrystalId()), + 1000, -500, 500, hit.GetLocalPosition(0).X()); + + obj.FillHistogram("position", + Form("crys_%d_y", hit.GetCrystalId()), + 1000, -500, 500, hit.GetLocalPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_z", hit.GetCrystalId()), + 1000, -500, 500, hit.GetLocalPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_r", hit.GetCrystalId()), + 500, 0, 500, hit.GetLocalPosition(0).Mag()); + + obj.FillHistogram("position", + Form("crys_%d_xy", hit.GetCrystalId()), + 100, -500, 500, hit.GetLocalPosition(0).X(), + 100, -500, 500, hit.GetLocalPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_xz", hit.GetCrystalId()), + 100, -500, 500, hit.GetLocalPosition(0).X(), + 100, -500, 500, hit.GetLocalPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_yz", hit.GetCrystalId()), + 100, -500, 500, hit.GetLocalPosition(0).Y(), + 100, -500, 500, hit.GetLocalPosition(0).Z()); + } + + } + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + // Addback preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += measuredE(hit.GetCoreEnergy()); + hits.push_back(hit); + + } + } + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + // Same clover + if(cluster[i].GetHoleNumber() == hits[j].GetHoleNumber()){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + for(int i = 0; i < cluster.size(); i++) + addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); + + // Fill addback histograms. + + obj.FillHistogram("energy", "addback", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistosInBeam.cxx b/histos/MakeHistosInBeam.cxx index 66b81f16..476dd25d 100644 --- a/histos/MakeHistosInBeam.cxx +++ b/histos/MakeHistosInBeam.cxx @@ -72,20 +72,34 @@ void MakeHistograms(TRuntimeObjects& obj) { TList *list = &(obj.GetObjects()); int numobj = list->GetSize(); + + Int_t energyNChannels = 8192; + Double_t energyLlim = 0.; + Double_t energyUlim = 8192.; if(gretSim){ - if(gretSim->Size() > 0){ + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); obj.FillHistogram("sim","beta", - 500, 0, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - obj.FillHistogram("sim","z", - 1000,-5,5., - gretSim->GetGretinaSimHit(0).GetZ()); + 500, 0, 0.5, + hit.GetBeta()); obj.FillHistogram("sim","beta_z", - 1000,-5,5., - gretSim->GetGretinaSimHit(0).GetZ(), - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); + 1000,-5,5., + hit.GetZ(), + 300, 0.2, 0.5, + hit.GetBeta()); } } @@ -104,7 +118,7 @@ void MakeHistograms(TRuntimeObjects& obj) { // std::cout << std::flush; - Double_t dta = s800Sim->GetS800SimHit(0).GetDTA()*100.; + Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); // std::cout << " ATA = " // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; @@ -115,14 +129,27 @@ void MakeHistograms(TRuntimeObjects& obj) { // std::cout << " DTA = " // << dta << std::endl; + + obj.FillHistogram("s800","dta", + 200, -0.10, 0.10, + dta); + // Rough dta acceptance cut - if(dta < -6. || dta > 6.) + if(dta < -0.06 || dta > 0.06) return; - obj.FillHistogram("s800","dta", - 4096, -6, 6, + obj.FillHistogram("s800","dta_cut", + 200, -0.10, 0.10, dta); + obj.FillHistogram("s800","ata", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetATA()); + + obj.FillHistogram("s800","bta", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetBTA()); + Double_t xsin, ysin, scatter; xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); @@ -154,11 +181,7 @@ void MakeHistograms(TRuntimeObjects& obj) { // (optionally define extra beta values in gvalues file) const Int_t nBetas = 1; Double_t betas[nBetas] = {beta}; - - Int_t energyNChannels = 8192; - Double_t energyLlim = 0.; - Double_t energyUlim = 8192.; - + Double_t calorimeterEnergy = 0.; Double_t calorimeterEnergy_gaus = 0.; std::vector hits; diff --git a/histos/MakeHistosInBeamAngCorr.cxx b/histos/MakeHistosInBeamAngCorr.cxx new file mode 100644 index 00000000..032e46b9 --- /dev/null +++ b/histos/MakeHistosInBeamAngCorr.cxx @@ -0,0 +1,610 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank29.h" +#include "TS800.h" +#include "TS800Sim.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +Double_t ProjectileTheta(Double_t theta, Double_t beta){ + // std::cout << theta << ", " << beta + // << ", " + // << (TMath::Cos(theta) - beta)/(1 - beta*TMath::Cos(theta)) + // << ", " + // << TMath::ACos( (TMath::Cos(theta) - beta)/(1 - beta*TMath::Cos(theta)) ) + // << std::endl; + return TMath::ACos( (TMath::Cos(theta) - beta)/(1 - beta*TMath::Cos(theta)) ); +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TS800Sim *s800Sim = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset,yoffset,zoffset); + + Int_t energyNChannels = 8192; + Double_t energyLlim = 0.; + Double_t energyUlim = 8192.; + Double_t cosTheta = -1; + Double_t mCosTheta = -1; + Double_t x1 = -1; + Double_t y1 = -1; + Double_t z1 = -1; + Double_t x2 = -1; + Double_t y2 = -1; + Double_t z2 = -1; + + if(gretSim){ + + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_proj_theta", + 180, 0., 180., + ProjectileTheta(hit.GetTheta(), + beta)*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + obj.FillHistogram("sim","beta", + 500, 0, 0.5, + hit.GetBeta()); + obj.FillHistogram("sim","beta_z", + 1000,-5,5., + hit.GetZ(), + 300, 0.2, 0.5, + hit.GetBeta()); + if(x==0){ + Double_t th = ProjectileTheta(hit.GetTheta(), beta); + x1 = TMath::Sin(th)*TMath::Cos(hit.GetPhi()); + y1 = TMath::Sin(th)*TMath::Sin(hit.GetPhi()); + z1 = TMath::Cos(th); + } + if(x==1){ + Double_t th = ProjectileTheta(hit.GetTheta(), beta); + x2 = TMath::Sin(th)*TMath::Cos(hit.GetPhi()); + y2 = TMath::Sin(th)*TMath::Sin(hit.GetPhi()); + z2 = TMath::Cos(th); + } + } + cosTheta + = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); + obj.FillHistogram("sim","emitted_delta", + 100, -1, 1., + cosTheta); + } + + if(!s800Sim) + return; + + if(s800Sim->Size() > 0){ + // std::cout << "In MakeHistos:" << std::endl; + + // std::cout << " time stamp = " + // << s800Sim->Timestamp() << std::endl; + + // std::cout << " size = " + // << s800Sim->Size() + // << std::endl; + + // std::cout << std::flush; + + Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); + + // std::cout << " ATA = " + // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; + + // std::cout << " BTA = " + // << s800Sim->GetS800SimHit(0).GetBTA() << std::endl; + + // std::cout << " DTA = " + // << dta << std::endl; + + + obj.FillHistogram("s800","dta", + 200, -0.10, 0.10, + dta); + + // Rough dta acceptance cut + if(dta < -0.06 || dta > 0.06) + return; + + obj.FillHistogram("s800","dta_cut", + 200, -0.10, 0.10, + dta); + + obj.FillHistogram("s800","ata", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetATA()); + + obj.FillHistogram("s800","bta", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetBTA()); + + Double_t xsin, ysin, scatter; + + xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); + ysin = -sin(s800Sim->GetS800SimHit(0).GetBTA()/1000.); + scatter = asin(sqrt(xsin*xsin + ysin*ysin))*1000.; + + obj.FillHistogram("s800","scatter", + 4096, 0, 300, + scatter); + } + + if(!gretina) + return; + + // (optionally define extra beta values in gvalues file) + const Int_t nBetas = 1; + Double_t betas[nBetas] = {beta}; + + Double_t calorimeterEnergy = 0.; + Double_t calorimeterEnergy_gaus = 0.; + std::vector hits; + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + // Addback preprocessing + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += hit.GetCoreEnergy(); + calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + hits.push_back(hit); + + } + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + obj.FillHistogram("energy", "overview_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + + for(int i=0; iGaus(1,1./1000.); + for(int y=x+1; ySize(); y++){ + + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t e2 = hit2.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.); + + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/16, energyLlim, energyUlim/2, e1, + energyNChannels/16, energyLlim, energyUlim/2, e2); + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/8, energyLlim, energyUlim, e2, + energyNChannels/8, energyLlim, energyUlim, e1); + + if( (e1 > 1110. && e1 < 1145. && e2 > 1305. && e2 < 1350.) + || (e2 > 1110. && e2 < 1145. && e1 > 1305. && e1 < 1350.) ){ + //TVector3 r1 = hit.GetFirstIntPosition_2(); + //TVector3 r2 = hit2.GetFirstIntPosition_2(); + // mCosTheta = r1.Dot(r2)/r1.Mag()/r2.Mag(); + Double_t th = ProjectileTheta(hit.GetTheta(), beta); + x1 = sin(th)*cos(hit.GetPhi()); + y1 = sin(th)*sin(hit.GetPhi()); + z1 = cos(th); + th = ProjectileTheta(hit2.GetTheta(), beta); + x2 = sin(th)*cos(hit2.GetPhi()); + y2 = sin(th)*sin(hit2.GetPhi()); + z2 = cos(th); + mCosTheta + = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); + obj.FillHistogram("position","delta", + 100, -1, 1., mCosTheta); + obj.FillHistogram("position","cosTheta_mCosTheta", + 100, -1, 1., + cosTheta, + 100, -1, 1., + mCosTheta); + } + } + + obj.FillHistogram("energy", + Form("dop_%.0f", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])); + + obj.FillHistogram("energy", + Form("dop_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("energy", + Form("dop_fw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); + } else { + obj.FillHistogram("energy", + Form("dop_bw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); + } + } + + obj.FillHistogram("position", "theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + obj.FillHistogram("position", "theta_proj", + 180, 0., 180., + ProjectileTheta(hit.GetTheta(), beta)*TMath::RadToDeg()); + + obj.FillHistogram("position", "phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + obj.FillHistogram("position", "theta_vs_phi_proj", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + ProjectileTheta(hit.GetTheta(), beta)*TMath::RadToDeg()); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("position", "theta_vs_phi_fw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } else { + obj.FillHistogram("position", "theta_vs_phi_bw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + obj.FillHistogram("addback", "calorimeter_gaus", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy_gaus); + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + Double_t addbackEnergy_gaus = 0.; + TVector3 firstHitPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + addbackEnergy_gaus += + cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + // Find the largest IP in the cluster and save its position + // for Doppler correction. + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) + > firstHitEnergy){ + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; + firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy[nBetas] = {0.}; + Double_t dopplerABEnergy_gaus[nBetas] = {0.}; + for(int b=0; bGetSize()) + list->Sort(); + +} diff --git a/histos/MakeHistosInBeamLH.cxx b/histos/MakeHistosInBeamLH.cxx index 72368b57..a51c0a2b 100644 --- a/histos/MakeHistosInBeamLH.cxx +++ b/histos/MakeHistosInBeamLH.cxx @@ -73,7 +73,29 @@ void MakeHistograms(TRuntimeObjects& obj) { TList *list = &(obj.GetObjects()); int numobj = list->GetSize(); - + + // These are written for every event, not just those in which + // gamma rays are detected, so catch them first. + if(gretSim){ + if(gretSim->Size() > 0){ + obj.FillHistogram("sim","beta", + 300, 0.2, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + obj.FillHistogram("sim","z", + 1000,-50,50., + gretSim->GetGretinaSimHit(0).GetZ()); + obj.FillHistogram("sim","beta_z", + 1000,-50.,50., + gretSim->GetGretinaSimHit(0).GetZ(), + 300, 0.2, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + obj.FillHistogram("sim","theta", + 180,0,180., + gretSim->GetGretinaSimHit(0).GetTheta()*TMath::RadToDeg()); + } + } + + if(!s800Sim) return; @@ -130,22 +152,6 @@ void MakeHistograms(TRuntimeObjects& obj) { obj.FillHistogram("s800","scatter", 4096, 0, 300, scatter); - if(gretSim){ - if(gretSim->Size() > 0){ - obj.FillHistogram("sim","beta", - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - obj.FillHistogram("sim","z", - 1000,-50,50., - gretSim->GetGretinaSimHit(0).GetZ()); - obj.FillHistogram("sim","beta_z", - 1000,-50.,50., - gretSim->GetGretinaSimHit(0).GetZ(), - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - } - } - } if(!gretina) @@ -235,6 +241,13 @@ void MakeHistograms(TRuntimeObjects& obj) { energyNChannels, energyLlim, energyUlim, hit.GetDoppler_2(betas[i])); + obj.FillHistogram("position", + Form("dop_theta_%.0f",betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i]), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("energy", Form("dop_%.0f_gaus", betas[i]*10000), energyNChannels, energyLlim, energyUlim, @@ -253,19 +266,23 @@ void MakeHistograms(TRuntimeObjects& obj) { } } - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), + obj.FillHistogram("position", "theta", 180, 0., 180., hit.GetTheta()*TMath::RadToDeg()); - + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("position", "theta_fw", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); obj.FillHistogram("position", "theta_vs_phi_fw", 360, 0., 360., hit.GetPhi()*TMath::RadToDeg(), 180, 0., 180., hit.GetTheta()*TMath::RadToDeg()); } else { + obj.FillHistogram("position", "theta_bw", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); obj.FillHistogram("position", "theta_vs_phi_bw", 360, 0., 360., hit.GetPhi()*TMath::RadToDeg(), diff --git a/histos/MakeHistosNeutrons.cxx b/histos/MakeHistosNeutrons.cxx new file mode 100644 index 00000000..26023166 --- /dev/null +++ b/histos/MakeHistosNeutrons.cxx @@ -0,0 +1,364 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + // TBank29 *bank29 = obj.GetDetector(); + // TS800 *s800 = obj.GetDetector() + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 10000; + Double_t energyLlim = 0.; + Double_t energyUlim = 10000.; + + if(gretSim){ + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_x", + 2000,-100., 100., + hit.GetX()); + obj.FillHistogram("sim","emitted_y", + 2000,-100., 100., + hit.GetY()); + obj.FillHistogram("sim","emitted_z", + 2000,-100., 100., + hit.GetZ()); + } + } + + if(!gretina) + return; + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + for(int x=0; xSize(); x++){ + TGretinaHit hit = gretina->GetGretinaHit(x); + + // Addback preprocessing + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += hit.GetCoreEnergy(); + + hits.push_back(hit); + + } + + // directory, histogram + // obj.FillHistogram("energy", "overview", + // energyNChannels, energyLlim, energyUlim, + // hit.GetCoreEnergy(), + // 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + obj.FillHistogram("energy", "energy_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + + if(gretSim && gretSim->Size()>0){ + TGretSimHit simhit = gretSim->GetGretinaSimHit(0); + obj.FillHistogram("energy", "GT_energy_gaus_vs_neutron_energy", + energyNChannels/5, energyLlim, energyUlim, + simhit.GetEn(), + energyNChannels/5, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + obj.FillHistogram("energy", "neutron_energy_minus_GT_energy_gaus", + 2*energyNChannels, -energyUlim, energyUlim, + simhit.GetEn() + - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + if( simhit.GetEn() < hit.GetCoreEnergy() ) + obj.FillHistogram("energy", "GT_energy_gaus_EGT_gt_En", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + } + + obj.FillHistogram("energy", "fold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 20, 0, 20, hit.NumberOfInteractions()); + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + "segfold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 20, 0, 20, segment_fold); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + TGretSimHit simhit = gretSim->GetGretinaSimHit(0); + if(gretSim){ + if(gretSim->Size()){ + Double_t p = simhit.GetPhi(); + p += TMath::Pi()/2.; + if(p>TMath::TwoPi()) + p -= TMath::TwoPi(); + Double_t azimuthal = hit.GetPhi()-p+TMath::Pi(); + if(azimuthal>TMath::TwoPi()) + azimuthal -= TMath::TwoPi(); + obj.FillHistogram("position", "phi_GT_phi_n", + 360, 0., TMath::TwoPi(), + hit.GetPhi(), + 360, 0., TMath::TwoPi(), + p); + obj.FillHistogram("position", "azimuthal", + 540, 0., 3.*TMath::Pi(), + azimuthal); + + if(azimuthal > 2.5 && azimuthal < 4.){ + obj.FillHistogram("position", "phi_GT_phi_n_azimuthal", + 360, 0., TMath::TwoPi(), + hit.GetPhi(), + 360, 0., TMath::TwoPi(), + p); + obj.FillHistogram("energy", "energy_gaus_azimuthal", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + } + + } + } + + int max_layer = -1; + for(int y=0; y < hit.NumberOfInteractions(); y++){ + + int layer = hit.GetSegmentId(y)/6; + + if(layer > max_layer) max_layer = layer; + + obj.FillHistogram("layers", + Form("theta_vs_phi_%s", LayerMap[layer].c_str()), + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + obj.FillHistogram("layers", "max_layer", 12, -2, 10, + max_layer); + + if(max_layer == 5){ + obj.FillHistogram("energy", "energy_involves_phi", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + obj.FillHistogram("energy", "overview_involves_phi", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 100, 0, 100, hit.GetCrystalId()); + } + + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("energy", + Form("energy_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", + Form("energy_A_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + else + obj.FillHistogram("energy", + Form("energy_B_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + } + + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + + // For energy-gated addback spectra + Double_t ABenergy[100]; + TString ABtype[100]; + Int_t Naddback = 0; + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1) + addbackType = "addback_n0"; + else if(neighbors == 1 && cluster.size() == 2) + addbackType = "addback_n1"; + else if(neighbors == 3 && cluster.size() == 3) + addbackType = "addback_n2"; + else + addbackType = "addback_ng"; + + // Fill addback histograms. + + obj.FillHistogram("addback", addbackType, + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + + if(addbackType == "addback_n0" + || addbackType == "addback_n1"){ + obj.FillHistogram("addback", "addback_n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + if(addbackType == "addback_n0" + || addbackType == "addback_n1" + || addbackType == "addback_n2"){ + obj.FillHistogram("addback", "addback_n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + + ABenergy[Naddback] = addbackEnergy; + ABtype[Naddback] = addbackType; + Naddback++; + + } + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistosOslo.cxx b/histos/MakeHistosOslo.cxx new file mode 100644 index 00000000..13f07c43 --- /dev/null +++ b/histos/MakeHistosOslo.cxx @@ -0,0 +1,156 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +Double_t measuredE(Double_t energy){ + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 2.650474517; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.000838828; + + if( !(resPar1 + resPar2 > 0) ) + return energy; + + return gRandom->Gaus(energy, (resPar1+energy*resPar2)/2.355); + +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 10000; + Double_t energyLlim = 0.; + Double_t energyUlim = 10000.; + + if(gretSim){ + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + } + } + + if(!gretina) + return; + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + Double_t mE = measuredE(hit.GetCoreEnergy()); + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); + + if(gretSim && gretSim->Size()>0){ + TGretSimHit simHit = gretSim->GetGretinaSimHit(0); + obj.FillHistogram("energy","emitted_energy_vs_energy", + energyNChannels/10, energyLlim, energyUlim, + mE, + energyNChannels/10, energyLlim, energyUlim, + simHit.GetEn()); + } + if(gretSim && gretSim->Size()>0 && + gretSim->GetGretinaSimHit(0).IsFEP()){ + obj.FillHistogram("energy", "photopeak", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_photopeak", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + } + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistosPencil.cxx b/histos/MakeHistosPencil.cxx new file mode 100644 index 00000000..dee3c737 --- /dev/null +++ b/histos/MakeHistosPencil.cxx @@ -0,0 +1,402 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GValue.h" + + +#include "TChannel.h" +#include "GValue.h" + +std::map LayerMap; + +void InitMap() { + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + // TBank29 *bank29 = obj.GetDetector(); + // TS800 *s800 = obj.GetDetector(); + + if(!gretina) + return; + + Int_t energyNChannels = 4000; + Double_t energyLlim = 0.; + Double_t energyUlim = 4000.; + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + // Gamma-gated crystal spectrum + Double_t eGateLlim = 1327.5; + Double_t eGateUlim = 1337.5; + int iGate = -1; + for(int i=0; iSize(); i++){ + TGretinaHit hit = gretina->GetGretinaHit(i); + if( hit.GetCoreEnergy() > eGateLlim && + hit.GetCoreEnergy() < eGateUlim ) + iGate = i; + } + if(iGate>=0){ + for(int i=0; iSize(); i++){ + TGretinaHit hit = gretina->GetGretinaHit(i); + if(i != iGate){ + obj.FillHistogram("energy", + Form("energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + obj.FillHistogram("energy", + Form("fold_vs_energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels/8, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 20, 0, 20, hit.NumberOfInteractions()); + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + Form("segfold_vs_energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels/8, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 20, 0, 20, segment_fold); + + } + } + } + + for(int x=0; xSize(); x++){ + TGretinaHit hit = gretina->GetGretinaHit(x); + + // Addback preprocessing + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += hit.GetCoreEnergy(); + + hits.push_back(hit); + + } + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + obj.FillHistogram("energy", "fold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 20, 0, 20, hit.NumberOfInteractions()); + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + "segfold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 20, 0, 20, segment_fold); + + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", "energy_A", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + else + obj.FillHistogram("energy", "energy_B", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + // Position spectra in crystal coordinates + if(hit.NumberOfInteractions()){ + obj.FillHistogram("position", "world_x", + 1400, 20, 160, hit.GetInteractionPosition(0).X()); + obj.FillHistogram("position", "world_y", + 1400, -280, -140, hit.GetInteractionPosition(0).Y()); + obj.FillHistogram("position", "world_z", + 1400, 20, 160, hit.GetInteractionPosition(0).Z()); + obj.FillHistogram("position", + Form("world_xy", hit.GetCrystalId()), + 1400, 20, 160, hit.GetInteractionPosition(0).X(), + 1400, -280, -140, hit.GetInteractionPosition(0).Y()); + obj.FillHistogram("position", + Form("world_xz", hit.GetCrystalId()), + 1400, 20, 160, hit.GetInteractionPosition(0).X(), + 1400, 20, 160, hit.GetInteractionPosition(0).Z()); + obj.FillHistogram("position", + Form("world_zy", hit.GetCrystalId()), + 1400, 20, 160, hit.GetInteractionPosition(0).Z(), + 1400, -280, -140, hit.GetInteractionPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_x", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).X()); + + obj.FillHistogram("position", + Form("crys_%d_y", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_z", hit.GetCrystalId()), + 1200, -10, 100, hit.GetLocalPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_xy", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).X(), + 1200, -60, 60, hit.GetLocalPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_xz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).X(), + 1200, -10, 100, hit.GetLocalPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_yz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalPosition(0).Y(), + 1200, -10, 100, hit.GetLocalPosition(0).Z()); + } + + int max_layer = -1; + for(int y=0; y < hit.NumberOfInteractions(); y++){ + + int layer = hit.GetSegmentId(y)/6; + + if(layer > max_layer) max_layer = layer; + + obj.FillHistogram("layers", + Form("theta_vs_phi_%s", LayerMap[layer].c_str()), + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + obj.FillHistogram("layers", "max_layer", 12, -2, 10, + max_layer); + + if(max_layer == 5){ + obj.FillHistogram("energy", "energy_involves_phi", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + obj.FillHistogram("energy", "overview_involves_phi", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 100, 0, 100, hit.GetCrystalId()); + } + + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("energy", + Form("energy_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", + Form("energy_A_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + else + obj.FillHistogram("energy", + Form("energy_B_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + } + + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + + // For energy-gated addback spectra + Double_t ABenergy[100]; + TString ABtype[100]; + Int_t Naddback = 0; + iGate = -1; + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1) + addbackType = "addback_n0"; + else if(neighbors == 1 && cluster.size() == 2) + addbackType = "addback_n1"; + else if(neighbors == 3 && cluster.size() == 3) + addbackType = "addback_n2"; + else + addbackType = "addback_ng"; + + // Fill addback histograms. + + obj.FillHistogram("addback", addbackType, + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + + if(addbackType == "addback_n0" + || addbackType == "addback_n1"){ + obj.FillHistogram("addback", "addback_n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + if(addbackType == "addback_n0" + || addbackType == "addback_n1" + || addbackType == "addback_n2"){ + obj.FillHistogram("addback", "addback_n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + + // For energy-gated addback spectra + if(addbackEnergy > eGateLlim && + addbackEnergy < eGateUlim) + iGate = Naddback; + + ABenergy[Naddback] = addbackEnergy; + ABtype[Naddback] = addbackType; + Naddback++; + + } + + // Fill energy-gated addback spectra + if(iGate >= 0){ + for(int i = 0; iGetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistosSourcesSim.cxx b/histos/MakeHistosSourcesSim.cxx index def89af3..3ecef7c0 100644 --- a/histos/MakeHistosSourcesSim.cxx +++ b/histos/MakeHistosSourcesSim.cxx @@ -62,12 +62,12 @@ void InitMap() { Double_t measuredE(Double_t energy){ Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); if(std::isnan(resPar1)) - resPar1 = 0.; + resPar1 = 1.2; Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); if(std::isnan(resPar2)) - resPar2 = 0.; - - return energy*gRandom->Gaus(1.0, exp(resPar1*log(energy)+resPar2)); + resPar2 = 0.0005; + + return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); } // extern "C" is needed to prevent name mangling. @@ -81,9 +81,17 @@ void MakeHistograms(TRuntimeObjects& obj) { TS800 *s800 = obj.GetDetector(); TGretSim *gretSim = obj.GetDetector(); - Int_t energyNChannels = 4000; - Double_t energyLlim = 0.; - Double_t energyUlim = 4000.; + Int_t energyNChannels = GValue::Value("CHANNELS"); + if(std::isnan(energyNChannels)) + energyNChannels = 10000; + + Double_t energyLlim = GValue::Value("LOWER_LIMIT"); + if(std::isnan(energyLlim)) + energyLlim = 0; + + Double_t energyUlim = GValue::Value("UPPER_LIMIT"); + if(std::isnan(energyUlim)) + energyUlim = 10000; if(gretSim){ for(int x=0; xSize(); x++){ @@ -106,8 +114,6 @@ void MakeHistograms(TRuntimeObjects& obj) { if(!gretina) return; - // Double_t res = 1./1000.; // Relative energy resolution - Double_t calorimeterEnergy = 0.; std::vector hits; @@ -179,15 +185,36 @@ void MakeHistograms(TRuntimeObjects& obj) { // directory, histogram obj.FillHistogram("energy", "overview", energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); + 200, 0, 200, hit.GetCrystalId()); obj.FillHistogram("energy", "energy", energyNChannels, energyLlim, energyUlim, mE); + if(gretSim && gretSim->Size()>0 && + gretSim->GetGretinaSimHit(0).IsFEP()){ + obj.FillHistogram("energy", "photopeak", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_photopeak", + energyNChannels, energyLlim, energyUlim, mE, + 200, 0, 200, hit.GetCrystalId()); + } + obj.FillHistogram("energy", "fold_vs_energy", energyNChannels/8, energyLlim, energyUlim, mE, 20, 0, 20, hit.NumberOfInteractions()); + // Symmetrized gamma-gamma matrix + for(int y=x+1; ySize(); y++){ + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t mE2 = measuredE(hit2.GetCoreEnergy()); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE, + energyNChannels/4, energyLlim, energyUlim, mE2); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE2, + energyNChannels/4, energyLlim, energyUlim, mE); + } + // Count segment fold int segment_fold = hit.NumberOfInteractions(); for(int y=0; y < hit.NumberOfInteractions(); y++) @@ -210,6 +237,12 @@ void MakeHistograms(TRuntimeObjects& obj) { energyNChannels, energyLlim, energyUlim, mE); // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("position", "phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); obj.FillHistogram("position", "theta_vs_phi", 360, 0., 360., hit.GetPhi()*TMath::RadToDeg(), @@ -250,7 +283,13 @@ void MakeHistograms(TRuntimeObjects& obj) { int layer = hit.GetSegmentId(y)/6; - if(layer > max_layer) max_layer = layer; + // Look for a segment in the layer with > 50 keV deposited + // to avoid segment threshold issues when compared with + // measurements. (Make sure the measured spectra are sorted + // with the same constraint.) + if(layer > max_layer && hit.GetSegmentEng(y) > 50.) { + max_layer = layer; + } obj.FillHistogram("layers", Form("theta_vs_phi_%s", LayerMap[layer].c_str()), @@ -269,6 +308,14 @@ void MakeHistograms(TRuntimeObjects& obj) { obj.FillHistogram("energy", "overview_involves_phi", energyNChannels, energyLlim, energyUlim, mE, 100, 0, 100, hit.GetCrystalId()); + if(gretSim && gretSim->Size()>0 && + gretSim->GetGretinaSimHit(0).IsFEP()){ + obj.FillHistogram("energy", "photopeak_involves_phi", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_photopeak_involves_phi", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + } } for(int k = 5; k > 0; k--){ @@ -304,12 +351,6 @@ void MakeHistograms(TRuntimeObjects& obj) { } } - // For energy-gated addback spectra - std::vector ABenergy; - std::vector ABtype; - Int_t Naddback = 0; - iGate = -1; - while(hits.size() > 0){ TGretinaHit currentHit = hits.back(); hits.pop_back(); @@ -388,48 +429,6 @@ void MakeHistograms(TRuntimeObjects& obj) { 20, 0, 20, neighbors, 10, 0, 10, cluster.size()); - // For energy-gated addback spectra - if(addbackEnergy > eGateLlim && - addbackEnergy < eGateUlim) - iGate = Naddback; - - ABenergy.push_back(addbackEnergy); - ABtype.push_back(addbackType); - Naddback++; - - } - - // Fill energy-gated addback spectra - if(iGate >= 0){ - for(int i = 0; i +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank29.h" +#include "TS800.h" +#include "TS800Sim.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" +#include "GValue.h" + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + + TGretina *gretina = obj.GetDetector(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TS800Sim *s800Sim = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + Int_t energyNChannels = 8192; + Double_t energyLlim = 0.; + Double_t energyUlim = 8192.; + + if(gretSim){ + if(gretSim->Size() > 0){ + obj.FillHistogram("sim","beta", + 1000, 0, 1.0, + gretSim->GetGretinaSimHit(0).GetBeta()); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + gretSim->GetGretinaSimHit(0).GetEn()); + obj.FillHistogram("sim","z", + 1000,-5,5., + gretSim->GetGretinaSimHit(0).GetZ()); + obj.FillHistogram("sim","beta_z", + 1000,-5,5., + gretSim->GetGretinaSimHit(0).GetZ(), + 300, 0.3, 0.6, + gretSim->GetGretinaSimHit(0).GetBeta()); + } + } + + if(!gretina) + return; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset,yoffset,zoffset); + + // (optionally define extra beta values in gvalues file) + const Int_t nBetas = 1; + Double_t betas[nBetas] = {beta}; + + Double_t calorimeterEnergy = 0.; + Double_t calorimeterEnergy_gaus = 0.; + std::vector hits; + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + // Addback preprocessing + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += hit.GetCoreEnergy(); + calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + hits.push_back(hit); + + } + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + obj.FillHistogram("energy", "overview_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + + for(int i=0; iGaus(1,1./1000.); + for(int y=x+1; ySize(); y++){ + + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t e2 = hit2.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.); + + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/16, energyLlim, energyUlim/2, e1, + energyNChannels/16, energyLlim, energyUlim/2, e2); + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/8, energyLlim, energyUlim, e2, + energyNChannels/8, energyLlim, energyUlim, e1); + } + + obj.FillHistogram("energy", + Form("dop_%.0f", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])); + + obj.FillHistogram("energy", + Form("dop_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("energy", + Form("dop_fw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); + } else { + obj.FillHistogram("energy", + Form("dop_bw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); + } + } + + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("position", "theta_vs_phi_fw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } else { + obj.FillHistogram("position", "theta_vs_phi_bw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + obj.FillHistogram("addback", "calorimeter_gaus", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy_gaus); + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + Double_t addbackEnergy_gaus = 0.; + TVector3 firstHitPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + addbackEnergy_gaus += + cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + // Find the largest IP in the cluster and save its position + // for Doppler correction. + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) + > firstHitEnergy){ + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; + firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy[nBetas] = {0.}; + Double_t dopplerABEnergy_gaus[nBetas] = {0.}; + for(int b=0; bGetSize()) + list->Sort(); + +} diff --git a/histos/MakeHistosWhiteSim.cxx b/histos/MakeHistosWhiteSim.cxx new file mode 100644 index 00000000..2a26b90e --- /dev/null +++ b/histos/MakeHistosWhiteSim.cxx @@ -0,0 +1,179 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" + +// Not actual mapping +#define Q1 6 +#define Q2 7 +#define Q3 8 +#define Q4 9 +#define Q5 14 +#define Q6 15 +#define Q7 21 +#define Q8 22 +#define Q9 24 +#define Q10 25 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +Double_t measuredE(Double_t energy){ + + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 0.; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.; + + if(!(resPar1 + resPar2) > 0) + return energy; + + return energy*gRandom->Gaus(1.0, exp(resPar1*log(energy)+resPar2)); +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + // TBank29 *bank29 = obj.GetDetector(); + // TS800 *s800 = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 8000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + if(!gretSim) + return; + + Double_t eE = 0.; + Bool_t fE = false; + if(gretSim){ + for(int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + eE = hit.GetEn(); + fE = hit.IsFEP(); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + obj.FillHistogram("sim","full_energy", + 3, -1, 2, + hit.IsFEP()); + obj.FillHistogram("sim","beta", + 1000, 0., 1.0, + hit.GetBeta()); + } + } + + if(!gretina) + return; + + // Double_t res = 1./1000.; // Relative energy resolution + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + // Addback preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += measuredE(hit.GetCoreEnergy()); + hits.push_back(hit); + + } + } + + int max_layer = -1; + + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + Double_t mE = measuredE(hit.GetCoreEnergy()); + + // directory, histogram + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); + + if(fE) + obj.FillHistogram("energy", "full_energy", + energyNChannels, energyLlim, energyUlim, mE); + + obj.FillHistogram("energy", "emitted_vs_detected", + energyNChannels/10, energyLlim, energyUlim, mE, + energyNChannels/10, energyLlim, energyUlim, eE); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + } + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistos_e10010_Sim.cxx b/histos/MakeHistos_e10010_Sim.cxx new file mode 100644 index 00000000..a268a7da --- /dev/null +++ b/histos/MakeHistos_e10010_Sim.cxx @@ -0,0 +1,907 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800Sim.h" +#include "TGretSim.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +bool DTA(TRuntimeObjects &obj){ + + TS800Sim *s800Sim = obj.GetDetector(); + + if(!s800Sim || s800Sim->Size() < 1) + return false; + + Double_t dta_min = GValue::Value("DTA_MIN"); + if(std::isnan(dta_min)) + dta_min = -0.06; + Double_t dta_max = GValue::Value("DTA_MAX"); + if(std::isnan(dta_max)) + dta_max = 0.06; + + TS800SimHit hit = s800Sim->GetS800SimHit(0); + + std::string dirname = "S800"; + std::string histname = "dta"; + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + hit.GetDTA()); + histname = "ata"; + obj.FillHistogram(dirname, histname, + 200, -50., 50., + hit.GetATA()); + histname = "bta"; + obj.FillHistogram(dirname, histname, + 200, -50., 50., + hit.GetBTA()); + histname = "ata_bta"; + obj.FillHistogram(dirname, histname, + 200, -50., 50., + hit.GetBTA(), + 200, -50., 50., + hit.GetATA()); + histname = "yta"; + obj.FillHistogram(dirname, histname, + 200, -20, 20, + hit.GetYTA()); + + // Rough DTA cut + if(hit.GetDTA() < dta_max && + hit.GetDTA() > dta_min){ + histname = "dta_acc"; + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + hit.GetDTA()); + histname = "ata_acc"; + obj.FillHistogram(dirname, histname, + 200, -50., 50., + hit.GetATA()); + histname = "bta_acc"; + obj.FillHistogram(dirname, histname, + 200, -50., 50., + hit.GetBTA()); + histname = "ata_bta_acc"; + obj.FillHistogram(dirname, histname, + 200, -50., 50., + hit.GetBTA(), + 200, -50., 50., + hit.GetATA()); + histname = "yta_acc"; + obj.FillHistogram(dirname, histname, + 200, -20, 20, + hit.GetYTA()); + } + + return true; + +} + +Double_t measuredE(Double_t energy, Int_t xtalID){ + + Double_t threshPar1 = GValue::Value(Form("THRESH_PAR_%i_1",xtalID)); + if(std::isnan(threshPar1)) + threshPar1 = 0.; + Double_t threshPar2 = GValue::Value(Form("THRESH_PAR_%i_2",xtalID)); + if(std::isnan(threshPar2)) + threshPar2 = 0.001; + + // std::cout << Form("THRESH_PAR_%i_1",xtalID) << " = " + // << threshPar1 << std::endl; + // std::cout << Form("THRESH_PAR_%i_2",xtalID) << " = " + // << threshPar2 << std::endl; + + Double_t threshold = (1.0 + tanh((energy-threshPar1)/threshPar2))/2.0; + + if(gRandom->Rndm() > threshold) + return -1.; + + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar1) || std::isnan(resPar2)) + return energy; + else + return energy*gRandom->Gaus(1.0, exp(resPar1*log(energy)+resPar2)); +} + +bool HandleAddback(TRuntimeObjects &obj) { + + TGretina *gretina = obj.GetDetector(); + TS800Sim *s800Sim = obj.GetDetector(); + + if(!gretina || !s800Sim) + return false; + + //Rough dta acceptance cut + Double_t dta_min = GValue::Value("DTA_MIN"); + if(std::isnan(dta_min)) + dta_min = -0.06; + Double_t dta_max = GValue::Value("DTA_MAX"); + if(std::isnan(dta_max)) + dta_max = 0.06; + if(s800Sim->GetS800SimHit(0).GetDTA() < dta_min || + s800Sim->GetS800SimHit(0).GetDTA() > dta_max) + return false; + + std::string dirname = "addback"; + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + // Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += measuredE(cluster[i].GetCoreEnergy(), + cluster[i].GetCrystalId()); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + // firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = measuredE(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()), + cluster[i].GetCrystalId()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + Double_t gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/8, energyLlim, energyUlim/2, e1, + energyNChannels/8, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/8, energyLlim, energyUlim/2, e2, + energyNChannels/8, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/8, energyLlim, energyUlim/2, e1, + energyNChannels/8, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/8, energyLlim, energyUlim/2, e2, + energyNChannels/8, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/8, energyLlim, energyUlim/2, e1, + energyNChannels/8, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/8, energyLlim, energyUlim/2, e2, + energyNChannels/8, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj) { + + TGretina *gretina = obj.GetDetector(); + TS800Sim *s800Sim = obj.GetDetector(); + + if(!gretina || !s800Sim || s800Sim->Size() < 1) + return false; + + //Rough dta acceptance cut + Double_t dta_min = GValue::Value("DTA_MIN"); + if(std::isnan(dta_min)) + dta_min = -0.06; + Double_t dta_max = GValue::Value("DTA_MAX"); + if(std::isnan(dta_max)) + dta_max = 0.06; + if(s800Sim->GetS800SimHit(0).GetDTA() < dta_min || + s800Sim->GetS800SimHit(0).GetDTA() > dta_max) + return false; + + std::string dirname = "segAddback"; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim ) + hits.push_back(hit); + } + + // Addback + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of hits including the current + // hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + // Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += measuredE(cluster[i].GetCoreEnergy(), + cluster[i].GetCrystalId()); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + // firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = measuredE(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()), + cluster[i].GetCrystalId()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1) + addbackType = "n0"; + else if(neighbors == 1 && cluster.size() == 2) + addbackType = "n1"; + else if(neighbors == 3 && cluster.size() == 3) + addbackType = "n2"; + else + addbackType = "ng"; + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj) { + + TGretina *gretina = obj.GetDetector(); + TS800Sim *s800Sim = obj.GetDetector(); + + if(!gretina || !s800Sim) + return false; + + //Rough dta acceptance cut + Double_t dta_min = GValue::Value("DTA_MIN"); + if(std::isnan(dta_min)) + dta_min = -0.06; + Double_t dta_max = GValue::Value("DTA_MAX"); + if(std::isnan(dta_max)) + dta_max = 0.06; + if(s800Sim->GetS800SimHit(0).GetDTA() < dta_min || + s800Sim->GetS800SimHit(0).GetDTA() > dta_max) + return false; + + std::string dirname = "gretina"; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( !hit.HasInteractions() || + hit.GetCoreEnergy() < energyLlim || + hit.GetCoreEnergy() > energyUlim ) + continue; + + std::string histname = "energy"; + Double_t e = measuredE(hit.GetCoreEnergy(), + hit.GetCrystalId()); + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + e); + histname = "overview"; + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + e, + 120, 0, 120, + hit.GetCrystalId()); + + histname = "doppler"; + // obj.FillHistogram(dirname, histname, + // energyNChannels, energyLlim, energyUlim, + // hit.GetDoppler_2(beta, 0)); + + // Do this "by hand" to use "measured" energy. + TVector3 firstHitPos = hit.GetInteractionPosition(hit.GetFirstIntPoint()) + - targetOffset; + Double_t gamma = 1/(sqrt(1-pow(beta,2))); + Double_t edop = e*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + edop); + + // histname = "doppler_s800"; + // TVector3 track = s800->Track(); + // obj.FillHistogram(dirname, histname, + // energyNChannels, energyLlim, energyUlim, + // hit.GetDoppler(beta, &track)); + + histname = "doppler_theta"; + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // energyNChannels, energyLlim, energyUlim, + // hit.GetDoppler_2(beta, 0)); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + edop); + + histname = "theta_phi"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + + histname = "theta"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + + histname = "phi"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = "theta_phi_fw"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = "theta_fw"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + + histname = "phi_fw"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = "theta_phi_bw"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = "theta_bw"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + + histname = "phi_bw"; + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + } + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TS800Sim *s800Sim = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + std::string histname = ""; + std::string dirname = ""; + + if(gretSim && gretSim->Size() > 0 && + s800Sim && s800Sim->Size() > 0){ + + dirname = "sim"; + + histname = "beta"; + obj.FillHistogram(dirname, histname, + 500, 0, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + histname = "z"; + obj.FillHistogram(dirname, histname, + 1000,-50,50., + gretSim->GetGretinaSimHit(0).GetZ()); + histname = "beta_z"; + obj.FillHistogram(dirname, histname, + 1000,-50,50., + gretSim->GetGretinaSimHit(0).GetZ(), + 300, 0.2, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + + //Rough dta acceptance cut + Double_t dta_min = GValue::Value("DTA_MIN"); + if(std::isnan(dta_min)) + dta_min = -0.06; + Double_t dta_max = GValue::Value("DTA_MAX"); + if(std::isnan(dta_max)) + dta_max = 0.06; + if(s800Sim->GetS800SimHit(0).GetDTA() > dta_min && + s800Sim->GetS800SimHit(0).GetDTA() < dta_max) { + histname = "beta_acc"; + obj.FillHistogram(dirname, histname, + 500, 0, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + histname = "z_acc"; + obj.FillHistogram(dirname, histname, + 1000,-50,50., + gretSim->GetGretinaSimHit(0).GetZ()); + histname = "beta_z_acc"; + obj.FillHistogram(dirname, histname, + 1000,-50,50., + gretSim->GetGretinaSimHit(0).GetZ(), + 300, 0.2, 0.5, + gretSim->GetGretinaSimHit(0).GetBeta()); + } + } + + if(s800Sim) { + dirname = "S800"; + + DTA(obj); + + if(gretina) { + + HandleGretina(obj); + + HandleAddback(obj); + + HandleSegmentAddback(obj); + + } + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_Trigger.cxx b/histos/MakeHistos_e10010_Trigger.cxx new file mode 100644 index 00000000..cfedde6b --- /dev/null +++ b/histos/MakeHistos_e10010_Trigger.cxx @@ -0,0 +1,303 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_s44=0; + +GCutG *outgoing_s44=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 2000, 3000, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -2500, -1500, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 30000, 70000, + s800->GetIonChamber().Charge()); + // s800->GetIonChamber().GetSum()); + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_s44) { + incoming_s44 = (GCutG*)gates->FindObject("in44S"); + } + + if(!outgoing_s44) { + outgoing_s44 = (GCutG*)gates->FindObject("out44S"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + + TriggerRegister(obj, incoming_s44, outgoing_s44); + + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s44); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s44); + + DTA(obj, incoming_s44, outgoing_s44); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_Trigger_cl46.cxx b/histos/MakeHistos_e10010_Trigger_cl46.cxx new file mode 100644 index 00000000..65e43fbe --- /dev/null +++ b/histos/MakeHistos_e10010_Trigger_cl46.cxx @@ -0,0 +1,345 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p43=0; +GCutG *incoming_s44=0; +GCutG *incoming_cl46=0; + +GCutG *outgoing_p43=0; +GCutG *outgoing_s44=0; +GCutG *outgoing_cl46=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 2000, 3000, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -2500, -1500, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 30000, 70000, + s800->GetIonChamber().Charge()); + // s800->GetIonChamber().GetSum()); + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("trigger_bit_%s_%s", + incoming->GetName(), + outgoing->GetName()); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = Form("trigger_raw_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p43) { + incoming_p43 = (GCutG*)gates->FindObject("in43P"); + } + if(!incoming_s44) { + incoming_s44 = (GCutG*)gates->FindObject("in44S"); + } + if(!incoming_cl46) { + incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); + } + + if(!outgoing_p43) { + outgoing_p43 = (GCutG*)gates->FindObject("out43P"); + } + if(!outgoing_s44) { + outgoing_s44 = (GCutG*)gates->FindObject("out44S"); + } + if(!outgoing_cl46) { + outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + + TriggerRegister(obj, incoming_p43, outgoing_p43); + + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p43); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p43); + + DTA(obj, incoming_p43, outgoing_p43); + + + TriggerRegister(obj, incoming_s44, outgoing_s44); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s44); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s44); + + DTA(obj, incoming_s44, outgoing_s44); + + + TriggerRegister(obj, incoming_cl46, outgoing_cl46); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_cl46); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_cl46); + + DTA(obj, incoming_cl46, outgoing_cl46); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_Trigger_p41.cxx b/histos/MakeHistos_e10010_Trigger_p41.cxx new file mode 100644 index 00000000..04f4e7f6 --- /dev/null +++ b/histos/MakeHistos_e10010_Trigger_p41.cxx @@ -0,0 +1,352 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p41=0; +GCutG *incoming_s42=0; +GCutG *incoming_si39=0; + +GCutG *outgoing_p41=0; +GCutG *outgoing_s42=0; +GCutG *outgoing_si39=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 1500, 2700, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -2100, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 32000, 60000, + s800->GetIonChamber().Charge()); + // s800->GetIonChamber().GetSum()); + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname = "dta_ata"; + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta(), + 200, -0.1, 0.1, + s800->GetAta()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("trigger_bit_%s_%s", + incoming->GetName(), + outgoing->GetName()); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = Form("trigger_raw_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p41) { + incoming_p41 = (GCutG*)gates->FindObject("in41P"); + } + if(!incoming_s42) { + incoming_s42 = (GCutG*)gates->FindObject("in42S"); + } + if(!incoming_si39) { + incoming_si39 = (GCutG*)gates->FindObject("in39Si"); + } + + if(!outgoing_p41) { + outgoing_p41 = (GCutG*)gates->FindObject("out41P"); + } + if(!outgoing_s42) { + outgoing_s42 = (GCutG*)gates->FindObject("out42S"); + } + if(!outgoing_si39) { + outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + + TriggerRegister(obj, incoming_p41, outgoing_p41); + + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p41); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p41); + + DTA(obj, incoming_p41, outgoing_p41); + + + TriggerRegister(obj, incoming_s42, outgoing_s42); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s42); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s42); + + DTA(obj, incoming_s42, outgoing_s42); + + + TriggerRegister(obj, incoming_si39, outgoing_si39); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_si39); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_si39); + + DTA(obj, incoming_si39, outgoing_si39); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_Trigger_p43.cxx b/histos/MakeHistos_e10010_Trigger_p43.cxx new file mode 100644 index 00000000..0bc3b9a0 --- /dev/null +++ b/histos/MakeHistos_e10010_Trigger_p43.cxx @@ -0,0 +1,352 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p43=0; +GCutG *incoming_s44=0; +GCutG *incoming_cl46=0; + +GCutG *outgoing_p43=0; +GCutG *outgoing_s44=0; +GCutG *outgoing_cl46=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 2000, 3000, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -2500, -1500, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 30000, 70000, + s800->GetIonChamber().Charge()); + // s800->GetIonChamber().GetSum()); + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname = "dta_ata"; + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta(), + 200, -0.1, 0.1, + s800->GetAta()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("trigger_bit_%s_%s", + incoming->GetName(), + outgoing->GetName()); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = Form("trigger_raw_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p43) { + incoming_p43 = (GCutG*)gates->FindObject("in43P"); + } + if(!incoming_s44) { + incoming_s44 = (GCutG*)gates->FindObject("in44S"); + } + if(!incoming_cl46) { + incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); + } + + if(!outgoing_p43) { + outgoing_p43 = (GCutG*)gates->FindObject("out43P"); + } + if(!outgoing_s44) { + outgoing_s44 = (GCutG*)gates->FindObject("out44S"); + } + if(!outgoing_cl46) { + outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + + TriggerRegister(obj, incoming_p43, outgoing_p43); + + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p43); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p43); + + DTA(obj, incoming_p43, outgoing_p43); + + + TriggerRegister(obj, incoming_s44, outgoing_s44); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s44); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s44); + + DTA(obj, incoming_s44, outgoing_s44); + + + TriggerRegister(obj, incoming_cl46, outgoing_cl46); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_cl46); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_cl46); + + DTA(obj, incoming_cl46, outgoing_cl46); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_Trigger_s42.cxx b/histos/MakeHistos_e10010_Trigger_s42.cxx new file mode 100644 index 00000000..0bf1c1c6 --- /dev/null +++ b/histos/MakeHistos_e10010_Trigger_s42.cxx @@ -0,0 +1,345 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p41=0; +GCutG *incoming_s42=0; +GCutG *incoming_si39=0; + +GCutG *outgoing_p41=0; +GCutG *outgoing_s42=0; +GCutG *outgoing_si39=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 1500, 2700, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -2100, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 32000, 60000, + s800->GetIonChamber().Charge()); + // s800->GetIonChamber().GetSum()); + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("trigger_bit_%s_%s", + incoming->GetName(), + outgoing->GetName()); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = Form("trigger_raw_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p41) { + incoming_p41 = (GCutG*)gates->FindObject("in41P"); + } + if(!incoming_s42) { + incoming_s42 = (GCutG*)gates->FindObject("in42S"); + } + if(!incoming_si39) { + incoming_si39 = (GCutG*)gates->FindObject("in39Si"); + } + + if(!outgoing_p41) { + outgoing_p41 = (GCutG*)gates->FindObject("out41P"); + } + if(!outgoing_s42) { + outgoing_s42 = (GCutG*)gates->FindObject("out42S"); + } + if(!outgoing_si39) { + outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + + TriggerRegister(obj, incoming_p41, outgoing_p41); + + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p41); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p41); + + DTA(obj, incoming_p41, outgoing_p41); + + + TriggerRegister(obj, incoming_s42, outgoing_s42); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s42); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s42); + + DTA(obj, incoming_s42, outgoing_s42); + + + TriggerRegister(obj, incoming_si39, outgoing_si39); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_si39); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_si39); + + DTA(obj, incoming_si39, outgoing_si39); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_Trigger_s44.cxx b/histos/MakeHistos_e10010_Trigger_s44.cxx new file mode 100644 index 00000000..6aafa734 --- /dev/null +++ b/histos/MakeHistos_e10010_Trigger_s44.cxx @@ -0,0 +1,307 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_s44=0; + +GCutG *outgoing_s44=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 1500, 2700, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -2100, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 32000, 60000, + s800->GetIonChamber().Charge()); + // s800->GetIonChamber().GetSum()); + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("trigger_bit_%s_%s", + incoming->GetName(), + outgoing->GetName()); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = Form("trigger_raw_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_s44) { + incoming_s44 = (GCutG*)gates->FindObject("in44S"); + } + + if(!outgoing_s44) { + outgoing_s44 = (GCutG*)gates->FindObject("out44S"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + + dirname = "S800"; + + TriggerRegister(obj, incoming_s44, outgoing_s44); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s44); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s44); + + DTA(obj, incoming_s44, outgoing_s44); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_Trigger_si39.cxx b/histos/MakeHistos_e10010_Trigger_si39.cxx new file mode 100644 index 00000000..0bf1c1c6 --- /dev/null +++ b/histos/MakeHistos_e10010_Trigger_si39.cxx @@ -0,0 +1,345 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p41=0; +GCutG *incoming_s42=0; +GCutG *incoming_si39=0; + +GCutG *outgoing_p41=0; +GCutG *outgoing_s42=0; +GCutG *outgoing_si39=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -1600, + s800->GetOBJ_E1Raw_MESY(), + 1000, 1500, 2700, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + obj.FillHistogram(dirname, histname, + 1000, -3000, -2100, + s800->GetCorrTOF_OBJ_MESY(), + 1000, 32000, 60000, + s800->GetIonChamber().Charge()); + // s800->GetIonChamber().GetSum()); + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = Form("trigger_bit_%s_%s", + incoming->GetName(), + outgoing->GetName()); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = Form("trigger_raw_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p41) { + incoming_p41 = (GCutG*)gates->FindObject("in41P"); + } + if(!incoming_s42) { + incoming_s42 = (GCutG*)gates->FindObject("in42S"); + } + if(!incoming_si39) { + incoming_si39 = (GCutG*)gates->FindObject("in39Si"); + } + + if(!outgoing_p41) { + outgoing_p41 = (GCutG*)gates->FindObject("out41P"); + } + if(!outgoing_s42) { + outgoing_s42 = (GCutG*)gates->FindObject("out42S"); + } + if(!outgoing_si39) { + outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + + TriggerRegister(obj, incoming_p41, outgoing_p41); + + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p41); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p41); + + DTA(obj, incoming_p41, outgoing_p41); + + + TriggerRegister(obj, incoming_s42, outgoing_s42); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s42); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s42); + + DTA(obj, incoming_s42, outgoing_s42); + + + TriggerRegister(obj, incoming_si39, outgoing_si39); + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_si39); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_si39); + + DTA(obj, incoming_si39, outgoing_si39); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_cl46.cxx b/histos/MakeHistos_e10010_cl46.cxx new file mode 100644 index 00000000..51ca511d --- /dev/null +++ b/histos/MakeHistos_e10010_cl46.cxx @@ -0,0 +1,1182 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_cl46=0; + +GCutG *outgoing_cl46=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600., -1600., + s800->GetOBJ_E1Raw_MESY(), + 1000, 2000., 3000., + s800->GetXF_E1Raw_MESY()); + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600., -1600., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 20000., 60000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + obj.FillHistogram(dirname, ehistname, + 1000, 20000., 45000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_cl46) { + incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); + } + + if(!outgoing_cl46) { + outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_cl46); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_cl46); + + DTA(obj, incoming_cl46, outgoing_cl46); + + if(gretina) { + + HandleGretina(obj, incoming_cl46, outgoing_cl46, gt_time); + + HandleAddback(obj, incoming_cl46, outgoing_cl46, gt_time); + + HandleSegmentAddback(obj, incoming_cl46, outgoing_cl46, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_cl46 && !outgoing_cl46 && + incoming_cl46->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_cl46->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_cl46->GetName(), + outgoing_cl46->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_cl46->GetName(), + outgoing_cl46->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_cl46_empty.cxx b/histos/MakeHistos_e10010_cl46_empty.cxx new file mode 100644 index 00000000..b5a3155b --- /dev/null +++ b/histos/MakeHistos_e10010_cl46_empty.cxx @@ -0,0 +1,1182 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_cl46=0; + +GCutG *outgoing_cl46=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -4000., 0., + s800->GetOBJ_E1Raw_MESY(), + 1000, 0., 4000., + s800->GetXF_E1Raw_MESY()); + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + obj.FillHistogram(dirname, histname, + 1000, -4000., 0., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 0., 100000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + obj.FillHistogram(dirname, ehistname, + 1000, 20000., 45000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_cl46) { + incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); + } + + if(!outgoing_cl46) { + outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_cl46); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_cl46); + + DTA(obj, incoming_cl46, outgoing_cl46); + + if(gretina) { + + HandleGretina(obj, incoming_cl46, outgoing_cl46, gt_time); + + HandleAddback(obj, incoming_cl46, outgoing_cl46, gt_time); + + HandleSegmentAddback(obj, incoming_cl46, outgoing_cl46, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_cl46 && !outgoing_cl46 && + incoming_cl46->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_cl46->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_cl46->GetName(), + outgoing_cl46->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_cl46->GetName(), + outgoing_cl46->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_p41.cxx b/histos/MakeHistos_e10010_p41.cxx new file mode 100644 index 00000000..20f9faff --- /dev/null +++ b/histos/MakeHistos_e10010_p41.cxx @@ -0,0 +1,1197 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p41=0; + +GCutG *outgoing_p41=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + // LH runs + obj.FillHistogram(dirname, histname, + 1000, -3000., -1600., + s800->GetOBJ_E1Raw_MESY(), + 1000, 1500., 2700., + s800->GetXF_E1Raw_MESY()); + + // Empty run + // obj.FillHistogram(dirname, histname, + // 1000, -2600., -1200., + // s800->GetOBJ_E1Raw_MESY(), + // 1000, 1600., 3600., + // s800->GetXF_E1Raw_MESY()); + + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + // LH runs + obj.FillHistogram(dirname, histname, + 1000, -3000., -2100., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 32000., 60000., + s800->GetIonChamber().GetSum()); + + // Empty run + // obj.FillHistogram(dirname, histname, + // 1000, -2200., -1500., + // s800->GetCorrTOF_OBJ_MESY(), + // 1000, 10000., 50000., + // s800->GetIonChamber().GetSum()); + + obj.FillHistogram(dirname, ehistname, + 1000, 32000., 60000., + s800->GetIonChamber().GetSum()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p41) { + incoming_p41 = (GCutG*)gates->FindObject("in41P"); + } + + if(!outgoing_p41) { + outgoing_p41 = (GCutG*)gates->FindObject("out41P"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p41); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p41); + + DTA(obj, incoming_p41, outgoing_p41); + + if(gretina) { + + HandleGretina(obj, incoming_p41, outgoing_p41, gt_time); + + HandleAddback(obj, incoming_p41, outgoing_p41, gt_time); + + HandleSegmentAddback(obj, incoming_p41, outgoing_p41, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_p41 && !outgoing_p41 && + incoming_p41->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_p41->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_p41->GetName(), + outgoing_p41->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_p41->GetName(), + outgoing_p41->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_p43.cxx b/histos/MakeHistos_e10010_p43.cxx new file mode 100644 index 00000000..6d53b016 --- /dev/null +++ b/histos/MakeHistos_e10010_p43.cxx @@ -0,0 +1,1182 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p43=0; + +GCutG *outgoing_p43=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600., -1600., + s800->GetOBJ_E1Raw_MESY(), + 1000, 2000., 3000., + s800->GetXF_E1Raw_MESY()); + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600., -1600., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 20000., 60000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + obj.FillHistogram(dirname, ehistname, + 1000, 20000., 45000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p43) { + incoming_p43 = (GCutG*)gates->FindObject("in43P"); + } + + if(!outgoing_p43) { + outgoing_p43 = (GCutG*)gates->FindObject("out43P"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p43); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p43); + + DTA(obj, incoming_p43, outgoing_p43); + + if(gretina) { + + HandleGretina(obj, incoming_p43, outgoing_p43, gt_time); + + HandleAddback(obj, incoming_p43, outgoing_p43, gt_time); + + HandleSegmentAddback(obj, incoming_p43, outgoing_p43, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_p43 && !outgoing_p43 && + incoming_p43->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_p43->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_p43->GetName(), + outgoing_p43->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_p43->GetName(), + outgoing_p43->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_p43_empty.cxx b/histos/MakeHistos_e10010_p43_empty.cxx new file mode 100644 index 00000000..2c270a7e --- /dev/null +++ b/histos/MakeHistos_e10010_p43_empty.cxx @@ -0,0 +1,1182 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_p43=0; + +GCutG *outgoing_p43=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -4000., 0., + s800->GetOBJ_E1Raw_MESY(), + 1000, 0., 4000., + s800->GetXF_E1Raw_MESY()); + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + obj.FillHistogram(dirname, histname, + 1000, -4000., 0., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 0., 100000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + obj.FillHistogram(dirname, ehistname, + 1000, 20000., 45000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_p43) { + incoming_p43 = (GCutG*)gates->FindObject("in43P"); + } + + if(!outgoing_p43) { + outgoing_p43 = (GCutG*)gates->FindObject("out43P"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_p43); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_p43); + + DTA(obj, incoming_p43, outgoing_p43); + + if(gretina) { + + HandleGretina(obj, incoming_p43, outgoing_p43, gt_time); + + HandleAddback(obj, incoming_p43, outgoing_p43, gt_time); + + HandleSegmentAddback(obj, incoming_p43, outgoing_p43, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_p43 && !outgoing_p43 && + incoming_p43->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_p43->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_p43->GetName(), + outgoing_p43->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_p43->GetName(), + outgoing_p43->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_s42.cxx b/histos/MakeHistos_e10010_s42.cxx new file mode 100644 index 00000000..129e32c0 --- /dev/null +++ b/histos/MakeHistos_e10010_s42.cxx @@ -0,0 +1,1197 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_s42=0; + +GCutG *outgoing_s42=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + // LH runs + obj.FillHistogram(dirname, histname, + 1000, -3000., -1600., + s800->GetOBJ_E1Raw_MESY(), + 1000, 1500., 2700., + s800->GetXF_E1Raw_MESY()); + + // Empty run + // obj.FillHistogram(dirname, histname, + // 1000, -2600., -1200., + // s800->GetOBJ_E1Raw_MESY(), + // 1000, 1600., 3600., + // s800->GetXF_E1Raw_MESY()); + + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + // LH runs + obj.FillHistogram(dirname, histname, + 1000, -3000., -2100., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 32000., 60000., + s800->GetIonChamber().GetSum()); + + // Empty run + // obj.FillHistogram(dirname, histname, + // 1000, -2200., -1500., + // s800->GetCorrTOF_OBJ_MESY(), + // 1000, 10000., 50000., + // s800->GetIonChamber().GetSum()); + + obj.FillHistogram(dirname, ehistname, + 1000, 32000., 60000., + s800->GetIonChamber().GetSum()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_s42) { + incoming_s42 = (GCutG*)gates->FindObject("in42S"); + } + + if(!outgoing_s42) { + outgoing_s42 = (GCutG*)gates->FindObject("out42S"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s42); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s42); + + DTA(obj, incoming_s42, outgoing_s42); + + if(gretina) { + + HandleGretina(obj, incoming_s42, outgoing_s42, gt_time); + + HandleAddback(obj, incoming_s42, outgoing_s42, gt_time); + + HandleSegmentAddback(obj, incoming_s42, outgoing_s42, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_s42 && !outgoing_s42 && + incoming_s42->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_s42->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_s42->GetName(), + outgoing_s42->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_s42->GetName(), + outgoing_s42->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_s42_empty.cxx b/histos/MakeHistos_e10010_s42_empty.cxx new file mode 100644 index 00000000..1bbbc50d --- /dev/null +++ b/histos/MakeHistos_e10010_s42_empty.cxx @@ -0,0 +1,1197 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_s42=0; + +GCutG *outgoing_s42=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + // LH runs + // obj.FillHistogram(dirname, histname, + // 1000, -3000., -1600., + // s800->GetOBJ_E1Raw_MESY(), + // 1000, 1500., 2700., + // s800->GetXF_E1Raw_MESY()); + + // Empty run + obj.FillHistogram(dirname, histname, + 1000, -2600., -1200., + s800->GetOBJ_E1Raw_MESY(), + 1000, 1600., 3600., + s800->GetXF_E1Raw_MESY()); + + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + // LH runs + // obj.FillHistogram(dirname, histname, + // 1000, -3000., -2100., + // s800->GetCorrTOF_OBJ_MESY(), + // 1000, 32000., 60000., + // s800->GetIonChamber().GetSum()); + + // Empty run + obj.FillHistogram(dirname, histname, + 1000, -2200., -1500., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 10000., 50000., + s800->GetIonChamber().GetSum()); + + obj.FillHistogram(dirname, ehistname, + 1000, 10000., 50000., + s800->GetIonChamber().GetSum()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_s42) { + incoming_s42 = (GCutG*)gates->FindObject("in42S"); + } + + if(!outgoing_s42) { + outgoing_s42 = (GCutG*)gates->FindObject("out42S"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s42); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s42); + + DTA(obj, incoming_s42, outgoing_s42); + + if(gretina) { + + HandleGretina(obj, incoming_s42, outgoing_s42, gt_time); + + HandleAddback(obj, incoming_s42, outgoing_s42, gt_time); + + HandleSegmentAddback(obj, incoming_s42, outgoing_s42, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_s42 && !outgoing_s42 && + incoming_s42->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_s42->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_s42->GetName(), + outgoing_s42->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_s42->GetName(), + outgoing_s42->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_s44.cxx b/histos/MakeHistos_e10010_s44.cxx new file mode 100644 index 00000000..ad6b901a --- /dev/null +++ b/histos/MakeHistos_e10010_s44.cxx @@ -0,0 +1,1206 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_s44=0; + +GCutG *outgoing_s44=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600., -1000., + s800->GetOBJ_E1Raw_MESY(), + 1000, 2000., 3600., + s800->GetXF_E1Raw_MESY()); + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + obj.FillHistogram(dirname, histname, + 1000, -2600., -1000., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 0., 55000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + obj.FillHistogram(dirname, ehistname, + 1000, 32000., 55000., + s800->GetIonChamber().GetSum()); + // s800->GetIonChamber().Charge()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + std::string histname = "energy"; + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + histname = "overview"; + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 120, 0, 120, + hit.GetCrystalId()); + + histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ){ + histname = Form("background_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy()); + histname = Form("background_dop_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetDoppler_2(beta, 0)); + return false; + } + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_s44) { + incoming_s44 = (GCutG*)gates->FindObject("in44S"); + } + + if(!outgoing_s44) { + outgoing_s44 = (GCutG*)gates->FindObject("out44S"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_s44); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_s44); + + DTA(obj, incoming_s44, outgoing_s44); + + if(gretina) { + + HandleGretina(obj, incoming_s44, outgoing_s44, gt_time); + + HandleAddback(obj, incoming_s44, outgoing_s44, gt_time); + + HandleSegmentAddback(obj, incoming_s44, outgoing_s44, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_s44 && !outgoing_s44 && + incoming_s44->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_s44->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_s44->GetName(), + outgoing_s44->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_s44->GetName(), + outgoing_s44->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_si39.cxx b/histos/MakeHistos_e10010_si39.cxx new file mode 100644 index 00000000..b69a235b --- /dev/null +++ b/histos/MakeHistos_e10010_si39.cxx @@ -0,0 +1,1197 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_si39=0; + +GCutG *outgoing_si39=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + // LH runs + obj.FillHistogram(dirname, histname, + 1000, -3000., -1600., + s800->GetOBJ_E1Raw_MESY(), + 1000, 1500., 2700., + s800->GetXF_E1Raw_MESY()); + + // Empty run + // obj.FillHistogram(dirname, histname, + // 1000, -2600., -1200., + // s800->GetOBJ_E1Raw_MESY(), + // 1000, 1600., 3600., + // s800->GetXF_E1Raw_MESY()); + + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + // LH runs + obj.FillHistogram(dirname, histname, + 1000, -3000., -2100., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 32000., 60000., + s800->GetIonChamber().GetSum()); + + // Empty run + // obj.FillHistogram(dirname, histname, + // 1000, -2200., -1500., + // s800->GetCorrTOF_OBJ_MESY(), + // 1000, 10000., 50000., + // s800->GetIonChamber().GetSum()); + + obj.FillHistogram(dirname, ehistname, + 1000, 32000., 60000., + s800->GetIonChamber().GetSum()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_si39) { + incoming_si39 = (GCutG*)gates->FindObject("in39Si"); + } + + if(!outgoing_si39) { + outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_si39); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_si39); + + DTA(obj, incoming_si39, outgoing_si39); + + if(gretina) { + + HandleGretina(obj, incoming_si39, outgoing_si39, gt_time); + + HandleAddback(obj, incoming_si39, outgoing_si39, gt_time); + + HandleSegmentAddback(obj, incoming_si39, outgoing_si39, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_si39 && !outgoing_si39 && + incoming_si39->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_si39->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_si39->GetName(), + outgoing_si39->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_si39->GetName(), + outgoing_si39->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistos_e10010_si39_empty.cxx b/histos/MakeHistos_e10010_si39_empty.cxx new file mode 100644 index 00000000..e5f2087d --- /dev/null +++ b/histos/MakeHistos_e10010_si39_empty.cxx @@ -0,0 +1,1197 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank29.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_si39=0; + +GCutG *outgoing_si39=0; + +GCutG *gt_time=0; + +//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + // LH runs + // obj.FillHistogram(dirname, histname, + // 1000, -3000., -1600., + // s800->GetOBJ_E1Raw_MESY(), + // 1000, 1500., 2700., + // s800->GetXF_E1Raw_MESY()); + + // Empty run + obj.FillHistogram(dirname, histname, + 1000, -2600., -1200., + s800->GetOBJ_E1Raw_MESY(), + 1000, 1600., 3600., + s800->GetXF_E1Raw_MESY()); + + + return true; + +} + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname, ehistname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + ehistname = Form("ICcharge_%s", incoming->GetName()); + } else { + histname = "outgoing"; + ehistname = "ICcharge"; + } + // LH runs + // obj.FillHistogram(dirname, histname, + // 1000, -3000., -2100., + // s800->GetCorrTOF_OBJ_MESY(), + // 1000, 32000., 60000., + // s800->GetIonChamber().GetSum()); + + // Empty run + obj.FillHistogram(dirname, histname, + 1000, -2200., -1500., + s800->GetCorrTOF_OBJ_MESY(), + 1000, 10000., 50000., + s800->GetIonChamber().GetSum()); + + obj.FillHistogram(dirname, ehistname, + 1000, 10000., 50000., + s800->GetIonChamber().GetSum()); + + // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " + // << s800->GetCorrTOF_OBJ_MESY() + // << "s800->GetIonChamber().Charge() = " + // << s800->GetIonChamber().Charge() + // << std::endl; + + // TMTof &mtof = s800->GetMTof(); + //histname = "RefSize"; + //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), + // 20,0,0,mtof.E1UpSize()); + + //for(int i=0;iGetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); +// +// histname = "time_afp"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetAFP()); +// +// histname = "time_charge"; +// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), +// 2000,0,0,s800->GetIonChamber().Charge()); + + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta()); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetBta(), + 200, -0.1, 0.1, + s800->GetAta()); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = 100.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("addback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + // std::cout << " * distance.Mag() = " << distance.Mag() + // << std::endl; + + obj.FillHistogram(dirname, + "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitCrystalPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitCrystalPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + // firstHitEnergy = cluster[i].GetCoreEnergy(); + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); + if(std::isnan(neighborLimit)) + neighborLimit = 0.; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!incoming || !outgoing || !gt_time) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = Form("segAddback_%s_%s", + incoming->GetName(), + outgoing->GetName()); + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + std::vector hits; + + // Preprocessing + for(int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if( hit.HasInteractions() && + hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim && + gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + hits.push_back(hit); + } + + // Addback + std::vector dop_n0n1_energies; // for gamma-gamma + std::vector dop_n0n1n2_energies; // for gamma-gamma + std::vector dop_n0n1n2ng_energies; // for gamma-gamma + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(int i = 0; i < cluster.size(); i++){ + for(int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - hits[j].GetSegmentPosition(); + + obj.FillHistogram(dirname, + "segment_separation", + 1000, 0., 1000., + distance.Mag()); + if(distance.Mag() < neighborLimit){ + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + TVector3 firstHitPos; + TVector3 firstHitSegmentPos; + Int_t firstHitHoleNum; + Double_t firstHitEnergy = 0; + for(int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + + // Find the hit with the largest energy deposit and save its position + // for Doppler correction. + + if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > + firstHitEnergy){ + firstHitSegmentPos = cluster[i].GetCrystalPosition(); + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos + = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) + - targetOffset; + firstHitEnergy + = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); + } + + for(int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetSegmentPosition() + - cluster[j].GetSegmentPosition(); + if(distance.Mag() < neighborLimit) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy = 0.; + double gamma = 1/(sqrt(1-pow(beta,2))); + dopplerABEnergy = + addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1){ + addbackType = "n0"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 1 && cluster.size() == 2){ + addbackType = "n1"; + dop_n0n1_energies.push_back(dopplerABEnergy); + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else if(neighbors == 3 && cluster.size() == 3){ + addbackType = "n2"; + dop_n0n1n2_energies.push_back(dopplerABEnergy); + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } else { + addbackType = "ng"; + dop_n0n1n2ng_energies.push_back(dopplerABEnergy); + } + + // Fill addback histograms. + obj.FillHistogram(dirname, addbackType.Data(), + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_%s_%.0f", + addbackType.Data(), + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + + if(addbackType == "n0" + || addbackType == "n1"){ + obj.FillHistogram(dirname, "n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + if(addbackType == "n0" + || addbackType == "n1" + || addbackType == "n2"){ + obj.FillHistogram(dirname, "n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + obj.FillHistogram(dirname, + Form("dop_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + // if(firstHitHoleNum < 10){ + // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ + if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ + obj.FillHistogram(dirname, + Form("dop_fw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } else { + obj.FillHistogram(dirname, + Form("dop_bw_n0n1n2_%.0f", + beta*10000), + energyNChannels, energyLlim, energyUlim, + dopplerABEnergy); + } + } + + obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + } + + // Symmetrized gamma-gamma + std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1_energies.size(); i++){ + Double_t e1 = dop_n0n1_energies[i]; + for(int j = i+1; j < dop_n0n1_energies.size(); j++){ + Double_t e2 = dop_n0n1_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ + Double_t e1 = dop_n0n1n2_energies[i]; + for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ + Double_t e2 = dop_n0n1n2_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); + for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ + Double_t e1 = dop_n0n1n2ng_energies[i]; + for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ + Double_t e2 = dop_n0n1n2ng_energies[j]; + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e1, + energyNChannels/10, energyLlim, energyUlim/2, e2); + obj.FillHistogram(dirname, histname, + energyNChannels/10, energyLlim, energyUlim/2, e2, + energyNChannels/10, energyLlim, energyUlim/2, e1); + } + } + + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + + std::string histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), + // hit.GetCoreEnergy()) ){ + // histname = Form("doppler_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 2000, 0, 8000, + // hit.GetDoppler_2(beta, 0)); + // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); + // obj.FillHistogram(dirname, histname, + // 100, 0, TMath::Pi(), + // hit.GetTheta(), + // 2000, 0, 8000, + // hit.GetDoppler(beta, 0)); + // } + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ) + return false; + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 2000, 0, 8000, + hit.GetDoppler_2(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + 2000, 0, 8000, + hit.GetDoppler_2(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TBank29 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + if(!incoming_si39) { + incoming_si39 = (GCutG*)gates->FindObject("in39Si"); + } + + if(!outgoing_si39) { + outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + // if(!strange) { + // strange = (GCutG*)gates->FindObject("strange"); + // } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank29"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank29_time"; + dirname = "Bank29"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + } + } + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_si39); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_si39); + + DTA(obj, incoming_si39, outgoing_si39); + + if(gretina) { + + HandleGretina(obj, incoming_si39, outgoing_si39, gt_time); + + HandleAddback(obj, incoming_si39, outgoing_si39, gt_time); + + HandleSegmentAddback(obj, incoming_si39, outgoing_si39, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + histname = Form("dtime_all_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_si39 && !outgoing_si39 && + incoming_si39->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_si39->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + histname = Form("dtime_all_reg%i_%s_%s",j, + incoming_si39->GetName(), + outgoing_si39->GetName()); + obj.FillHistogram(dirname,histname, + 500, -250, 250, + s800->GetTimestamp()-hit.GetTimestamp(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_si39->GetName(), + outgoing_si39->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + // histname = "TDC_vs_DispX"; + // obj.FillHistogram(dirname,histname, + // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), + // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + // histname ="PID_TDC"; + // obj.FillHistogram(dirname,histname, + // 2000,0,0,s800->GetCorrTOF_OBJ(), + // 2000,0,0,s800->GetIonChamber().Charge()); + + //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); + //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), + // 2000,10000,60000,s800->GetIonChamber().Charge()); + //} + + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //std::cout << " In gret loop + s800 before haspids" << std::endl; + //histname = "E1_m_TDC"; + //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); + + //histname = "E1Raw"; + //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); + + //histname = "M_E1Raw"; + //for(int z=0;zGetMTof().E1UpSize();z++) + // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + From 50ff9b714b8b009ba4ee8da7d5e3b9eb2eec7c17 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Wed, 19 May 2021 16:37:28 -0400 Subject: [PATCH 08/29] Catching up with pcbend/GRUTinizer. --- .gitignore | 79 +- .grutrc | 14 +- config/DetectorEnvironment.env | 7 +- Gretina.hist => config/Gretina.hist | 20 - config/myvalues.val | 55 + config/sega_cal.cal | 246 ++ filters/Filter_e10010.cxx | 26 +- gui_params.hist | 9 - histos/BenchmarkGrutinizerSpecTcl.cxx | 163 - histos/BetterCaesarHistos.cxx | 585 --- histos/BetterCaesarHistos2.cxx | 171 - histos/CaesarMakeAddbackHistos.cxx | 437 --- histos/CaesarMakeFitHistos.cxx | 227 -- histos/CaesarMakeHistos.cxx | 268 -- histos/FastScintHists.cxx | 145 - histos/GretinaMakeHistos.cxx | 288 -- histos/HasPIDs_Example.cxx | 772 ---- histos/MakeHistos.cxx | 622 ---- histos/MakeHistosGretinaBlank.cxx | 114 + histos/MakeHistosInBeam.cxx | 528 --- histos/MakeHistosInBeamLH.cxx | 536 --- histos/MakeHistosSources.cxx | 405 --- histos/MakeHistosSourcesSim.cxx | 439 --- histos/MakeHistos_Crdcs.cxx | 492 +++ histos/MakeHistos_DDAS.cxx | 433 +++ histos/MakeHistos_Gretina.cxx | 1245 +++++++ histos/MakeHistos_Gretina_tests_Mode2.cxx | 420 +++ histos/MakeHistos_Gretina_tests_Mode2_v2.cxx | 401 +++ histos/MakeHistos_Mode3.cxx | 206 ++ histos/MakeHistos_e17001.cxx | 413 +++ histos/MakeHistos_mode3.cxx | 140 - histos/MakeHistos_test_lee.cxx | 780 ++++ histos/MakeHistos_test_lee_mode3.cxx | 444 +++ histos/MakeSegaJanusHistos.cxx | 903 ----- histos/Make_CRDC_Mask_Histos.cxx | 181 - histos/MyMakeHistos.cxx.bak | 761 ++++ histos/PolarHists.cxx | 287 -- include/DDASBanks.h | 46 +- include/DDASDataFormat.h | 92 +- include/GCanvas.h | 18 +- include/GCutG.h | 11 +- include/GDoubleGaus.h | 99 + include/GGraph.h | 31 + include/GGraph2D.h | 30 + include/GH1.h | 64 + include/GH1D.h | 130 +- include/GH2.h | 150 + include/GH2Base.h | 140 - include/GH2D.h | 78 +- include/GH2I.h | 64 +- include/GHistPopup.h | 33 + include/GPeak.h | 2 + include/GPopup.h | 5 + include/GRootCommands.h | 44 +- include/GRootFunctions.h | 31 +- include/{TBank29.h => TBank88.h} | 16 +- include/TCaesar.h | 2 +- include/TCalibrator.h | 18 +- include/TChannel.h | 14 +- include/TCluster.h | 220 ++ include/TDetector.h | 8 +- include/TDetectorEnv.h | 10 +- include/TDetectorHit.h | 12 +- include/TF1Sum.h | 51 + include/TFSU.h | 44 + include/TFSUHit.h | 31 + include/TFastScint.h | 12 +- include/TFastScintHit.h | 70 +- include/TGRUTOptions.h | 6 + include/TGRUTTypes.h | 8 +- include/TGRUTUtilities.h | 1 + include/TGretSim.h | 2 +- include/TGretina.h | 66 +- include/TGretinaHit.h | 230 +- include/THistogramLoop.h | 4 +- include/TJanus.h | 2 + include/TKinematics.h | 1 + include/TLenda.h | 34 + include/TLendaHit.h | 36 + include/TMode3.h | 7 +- include/TMode3Hit.h | 9 +- include/TNSCLScalers.h | 2 +- include/TOBJ.h | 49 + include/TOBJHit.h | 63 + include/TOldSega.h.bak | 56 + include/TOldSegaHit.h.bak | 58 + include/TPhosWall.h | 8 +- include/TRawBanks.h | 25 +- include/TRawSource.h | 1 + include/TRuntimeObjects.h | 164 +- include/TS800.h | 74 +- include/TS800Hit.h | 56 +- include/TS800Scaler.h | 2 +- include/TS800Sim.h | 2 +- include/TSega.h | 4 + include/TSegaHit.h | 5 +- include/TSmartBuffer.h | 2 - include/TTransition.h | 1 + include/TUML.h | 136 + include/TUMLHit.h | 42 + include/TUnpackedEvent.h | 4 + include/TVariable.h | 98 + include/ThreadsafeQueue.h | 2 +- libraries/GROOT/GCanvas.cxx | 981 +++--- libraries/GROOT/GCutG.cxx | 10 +- libraries/GROOT/GDoubleGaus.cxx | 336 ++ libraries/GROOT/GGaus.cxx | 33 +- libraries/GROOT/GGraph2D.cxx | 106 + libraries/GROOT/GH1.cxx | 152 + libraries/GROOT/GH1D.cxx | 373 +- libraries/GROOT/GH2.cxx | 3122 +++++++++++++++++ libraries/GROOT/GH2Base.cxx | 459 --- libraries/GROOT/GH2D.cxx | 228 +- libraries/GROOT/GH2I.cxx | 143 +- libraries/GROOT/GHistPopup.cxx | 76 + libraries/GROOT/GPeak.cxx | 20 +- libraries/GROOT/GPopup.cxx | 51 +- libraries/GROOT/GRootCanvas.cxx | 37 +- libraries/GROOT/GRootCommands.cxx | 187 +- libraries/GROOT/GRootFunctions.cxx | 457 ++- libraries/GROOT/GValue.cxx | 19 +- libraries/GROOT/LinkDef.h | 22 +- libraries/GROOT/TF1Sum.cxx | 89 + libraries/SourceData/eu152.sou | 22 +- libraries/SourceData/ra226.sou | 27 + libraries/TDetSystems/TDetector/LinkDef.h | 4 +- libraries/TDetSystems/TDetector/TDetector.cxx | 9 + .../TDetSystems/TDetector/TDetectorEnv.cxx | 3 +- .../TDetSystems/TDetector/TDetectorHit.cxx | 29 +- libraries/TDetSystems/TFSU/LinkDef.h | 14 + libraries/TDetSystems/TFSU/TFSU.cxx | 79 + libraries/TDetSystems/TFSU/TFSUHit.cxx | 59 + .../TDetSystems/TFastScint/TFastScint.cxx | 210 +- .../TDetSystems/TFastScint/TFastScintHit.cxx | 150 +- libraries/TDetSystems/TGretina/LinkDef.h | 12 +- libraries/TDetSystems/TGretina/TBank29.cxx | 46 - libraries/TDetSystems/TGretina/TBank88.cxx | 69 + libraries/TDetSystems/TGretina/TCluster.cxx | 226 ++ libraries/TDetSystems/TGretina/TGretina.cxx | 436 ++- .../TDetSystems/TGretina/TGretinaHit.cxx | 509 ++- libraries/TDetSystems/TGretina/TMode3.cxx | 64 +- libraries/TDetSystems/TGretina/TMode3Hit.cxx | 59 +- libraries/TDetSystems/TJanus/TJanus.cxx | 12 +- libraries/TDetSystems/TLenda/LinkDef.h | 14 + libraries/TDetSystems/TLenda/TLenda.cxx | 46 + libraries/TDetSystems/TLenda/TLendaHit.cxx | 21 + .../TDetSystems/TNSCLScalers/TNSCLScalers.cxx | 2 + libraries/TDetSystems/TOBJ/LinkDef.h | 14 + libraries/TDetSystems/TOBJ/TOBJ.cxx | 113 + libraries/TDetSystems/TOBJ/TOBJHit.cxx | 192 + libraries/TDetSystems/TPhosWall/TPhosWall.cxx | 7 +- libraries/TDetSystems/TS800/TS800.cxx | 401 ++- libraries/TDetSystems/TS800/TS800Hit.cxx | 242 +- .../TDetSystems/TSega/DDASDataFormat.cxx | 42 - libraries/TDetSystems/TSega/LinkDef.h | 3 +- libraries/TDetSystems/TSega/TSega.cxx | 17 +- libraries/TDetSystems/TSega/TSegaHit.cxx | 18 +- libraries/TDetSystems/TUML/LinkDef.h | 14 + libraries/TDetSystems/TUML/TUML.cxx | 293 ++ libraries/TDetSystems/TUML/TUMLHit.cxx | 22 + libraries/TGRUTUtil/LinkDef.h | 18 +- libraries/TGRUTUtil/TCalibrator.cxx | 229 +- libraries/TGRUTUtil/TChannel.cxx | 44 +- libraries/TGRUTUtil/TGRUTUtilities.cxx | 14 + libraries/TGRUTUtil/TPresetCanvas.cxx | 1 + libraries/TGRUTUtil/TVariable.cxx | 83 + libraries/TGRUTint/TGRUTOptions.cxx | 10 +- libraries/TGRUTint/TGRUTTypes.cxx | 7 +- libraries/TGRUTint/TGRUTint.cxx | 29 +- .../THistogramming/TCompiledHistograms.cxx | 7 +- libraries/THistogramming/TRuntimeObjects.cxx | 142 +- libraries/TKinematics/TKinematics.cxx | 78 +- libraries/TLoops/TBuildingLoop.cxx | 10 + libraries/TLoops/TDataLoop.cxx | 5 + libraries/TLoops/TUnpackedEvent.cxx | 41 +- libraries/TLoops/TUnpackingLoop.cxx | 18 +- libraries/TLoops/TWriteLoop.cxx | 6 +- libraries/TNSCLFormat/TNSCLEvent.cxx | 6 + libraries/TNucleus/TNucleus.cxx | 15 +- libraries/TRawFormat/TOrderedRawFile.cxx | 3 +- libraries/TRawFormat/TRawBanks.cxx | 2 + libraries/TRawFormat/TRawFileOut.cxx | 37 +- makefile | 31 +- pygui/AnsiColorText.py | 2 +- pygui/grut-view.py | 4 +- pygui/hist_tab.py | 24 +- pygui/mainwindow.py | 111 +- pygui/status_widget.py | 4 +- pygui/tcut_tab.py | 391 +-- pygui/util.py | 5 +- pygui/variable_tab.py | 6 +- sandbox/runme.sh | 12 + sandbox/sort.sh | 42 + thisgrut.sh | 9 - util/CalibrateCaesar.cxx | 643 ---- util/CheckUnCalCRDCY.C | 323 +- util/Check_TOF.C | 122 + util/FitRawY.cxx | 22 +- util/MakeCaesarCalibrationHists.cxx | 139 - util/MakeCaesarCalibrationHists_Brandon.cxx | 154 - util/Root2Rad.cxx | 375 ++ util/correctCaesarTime.cxx | 148 - util/detmap_Q9.txt | 160 + util/filtertree.C | 47 + util/fitCoulexGRUT_Kr90all.cxx | 730 ---- util/gadd.cxx | 250 -- util/getScalerCounts.cxx | 86 + util/grutinizer-config | 7 +- util/r2root.cxx | 6 + util/read.cxx | 127 + util/scripts.C | 5 +- 211 files changed, 18760 insertions(+), 12529 deletions(-) rename Gretina.hist => config/Gretina.hist (98%) create mode 100644 config/myvalues.val create mode 100644 config/sega_cal.cal delete mode 100644 gui_params.hist delete mode 100644 histos/BenchmarkGrutinizerSpecTcl.cxx delete mode 100644 histos/BetterCaesarHistos.cxx delete mode 100644 histos/BetterCaesarHistos2.cxx delete mode 100644 histos/CaesarMakeAddbackHistos.cxx delete mode 100644 histos/CaesarMakeFitHistos.cxx delete mode 100644 histos/CaesarMakeHistos.cxx delete mode 100644 histos/FastScintHists.cxx delete mode 100644 histos/GretinaMakeHistos.cxx delete mode 100644 histos/HasPIDs_Example.cxx delete mode 100644 histos/MakeHistos.cxx create mode 100644 histos/MakeHistosGretinaBlank.cxx delete mode 100644 histos/MakeHistosInBeam.cxx delete mode 100644 histos/MakeHistosInBeamLH.cxx delete mode 100644 histos/MakeHistosSources.cxx delete mode 100644 histos/MakeHistosSourcesSim.cxx create mode 100644 histos/MakeHistos_Crdcs.cxx create mode 100644 histos/MakeHistos_DDAS.cxx create mode 100644 histos/MakeHistos_Gretina.cxx create mode 100644 histos/MakeHistos_Gretina_tests_Mode2.cxx create mode 100644 histos/MakeHistos_Gretina_tests_Mode2_v2.cxx create mode 100644 histos/MakeHistos_Mode3.cxx create mode 100644 histos/MakeHistos_e17001.cxx delete mode 100644 histos/MakeHistos_mode3.cxx create mode 100644 histos/MakeHistos_test_lee.cxx create mode 100644 histos/MakeHistos_test_lee_mode3.cxx delete mode 100644 histos/MakeSegaJanusHistos.cxx delete mode 100644 histos/Make_CRDC_Mask_Histos.cxx create mode 100644 histos/MyMakeHistos.cxx.bak delete mode 100644 histos/PolarHists.cxx create mode 100644 include/GDoubleGaus.h create mode 100644 include/GGraph.h create mode 100644 include/GGraph2D.h create mode 100644 include/GH1.h create mode 100644 include/GH2.h delete mode 100644 include/GH2Base.h create mode 100644 include/GHistPopup.h rename include/{TBank29.h => TBank88.h} (70%) create mode 100644 include/TCluster.h create mode 100644 include/TF1Sum.h create mode 100644 include/TFSU.h create mode 100644 include/TFSUHit.h create mode 100644 include/TLenda.h create mode 100644 include/TLendaHit.h create mode 100644 include/TOBJ.h create mode 100644 include/TOBJHit.h create mode 100644 include/TOldSega.h.bak create mode 100644 include/TOldSegaHit.h.bak create mode 100644 include/TUML.h create mode 100644 include/TUMLHit.h create mode 100644 include/TVariable.h create mode 100644 libraries/GROOT/GDoubleGaus.cxx create mode 100644 libraries/GROOT/GGraph2D.cxx create mode 100644 libraries/GROOT/GH1.cxx create mode 100644 libraries/GROOT/GH2.cxx delete mode 100644 libraries/GROOT/GH2Base.cxx create mode 100644 libraries/GROOT/GHistPopup.cxx create mode 100644 libraries/GROOT/TF1Sum.cxx create mode 100644 libraries/SourceData/ra226.sou create mode 100644 libraries/TDetSystems/TFSU/LinkDef.h create mode 100644 libraries/TDetSystems/TFSU/TFSU.cxx create mode 100644 libraries/TDetSystems/TFSU/TFSUHit.cxx delete mode 100644 libraries/TDetSystems/TGretina/TBank29.cxx create mode 100644 libraries/TDetSystems/TGretina/TBank88.cxx create mode 100644 libraries/TDetSystems/TGretina/TCluster.cxx create mode 100644 libraries/TDetSystems/TLenda/LinkDef.h create mode 100644 libraries/TDetSystems/TLenda/TLenda.cxx create mode 100644 libraries/TDetSystems/TLenda/TLendaHit.cxx create mode 100644 libraries/TDetSystems/TOBJ/LinkDef.h create mode 100644 libraries/TDetSystems/TOBJ/TOBJ.cxx create mode 100644 libraries/TDetSystems/TOBJ/TOBJHit.cxx delete mode 100644 libraries/TDetSystems/TSega/DDASDataFormat.cxx create mode 100644 libraries/TDetSystems/TUML/LinkDef.h create mode 100644 libraries/TDetSystems/TUML/TUML.cxx create mode 100644 libraries/TDetSystems/TUML/TUMLHit.cxx create mode 100644 libraries/TGRUTUtil/TVariable.cxx create mode 100755 sandbox/runme.sh create mode 100755 sandbox/sort.sh delete mode 100644 util/CalibrateCaesar.cxx create mode 100644 util/Check_TOF.C delete mode 100644 util/MakeCaesarCalibrationHists.cxx delete mode 100644 util/MakeCaesarCalibrationHists_Brandon.cxx create mode 100644 util/Root2Rad.cxx delete mode 100644 util/correctCaesarTime.cxx create mode 100644 util/detmap_Q9.txt create mode 100644 util/filtertree.C delete mode 100644 util/fitCoulexGRUT_Kr90all.cxx delete mode 100644 util/gadd.cxx create mode 100644 util/getScalerCounts.cxx create mode 100644 util/r2root.cxx create mode 100644 util/read.cxx diff --git a/.gitignore b/.gitignore index f00f6be9..8e144345 100644 --- a/.gitignore +++ b/.gitignore @@ -16,9 +16,86 @@ htmldoc .grut_history bin +lib .build .nfs* *.pyc .grut_thread histos/MakeHistos.cxx -include/GVersion.h \ No newline at end of file +include/GVersion.h +Calibration.cc +histos/#Joe_MakeHistos_1-11-16.cxx# +histos/Joe_MakeHistos_1-11-16.cxx +histos/MakeGRETJABHistos.cxx +histos/MakeHistos.cxx_Stock +histos/MakeHistos_CheckAddback.cxx +histos/MakeHistos_Eff.cxx +histos/MakeHistos_EnCalibration.cxx +histos/MakeHistos_EnVsXtal.cxx +histos/MakeHistos_ForCrossSections.cxx +histos/MakeHistos_ForCrossSections_Unreacted.cxx +histos/MakeHistos_ForXSec_Run113.cxx +histos/MakeHistos_ForXSec_Run114.cxx +histos/MakeHistos_ForXSec_Run115.cxx +histos/MakeHistos_ForXSec_Run117.cxx +histos/MakeHistos_ForXSec_Run118.cxx +histos/MakeHistos_ForXSec_Run119.cxx +histos/MakeHistos_ForXSec_Run120.cxx +histos/MakeHistos_ForXSec_Run121.cxx +histos/MakeHistos_ForXSec_Run122.cxx +histos/MakeHistos_ForXSec_Run123.cxx +histos/MakeHistos_Gamma1DOnly.cxx +histos/MakeHistos_GammaEnergyResolution.cxx +histos/MakeHistos_Source_TripleCoin.cxx +histos/MakeHistos_UCGret_Source.cxx +histos/MakeHistos_e15020.cxx +histos/MakeHistos_e15020_AfterInAndResCuts.cxx +histos/MakeHistos_e15020_HodoCheck.cxx +histos/MakeHistos_e15020_Mask.cxx +histos/MakeHistos_e15020_PID.cxx +histos/MakeHistos_e15020_TOFvsTIME.cxx +histos/MakeHistos_e15020_Unreacted.cxx +histos/MakeHistos_e15040.cxx +histos/MakeHistos_e15040_GenTesting.cxx +histos/MakeHistos_e15040_Mask.cxx +histos/MakeHistos_e15040_PID.cxx +.grut_logon +CheckFS.C +PeakFind.C +Test/ +a.out +co56_2.sou +config/invmap_37Ar.inv +hist/ +include/#TCompiledHistograms.h# +include/#TFastScint.h# +include/#TJanus.h# +include/#new.cpp# +include/RS800.h +include/TS800.h_OLD +include/TS800Hit.h_OLD +invmap.inv +invmap_37Ar.inv +libraries/SourceData/gs_ho166.sou +libraries/SourceData/ho166.sou +libraries/TDetSystems/TFastScint/TFastScint.cxx_OLD +libraries/TDetSystems/TJanus/#TJanus.cxx# +libraries/TDetSystems/TS800/RS800.cxx.bak +libraries/TDetSystems/TS800/TS800.cxx_OLD +libraries/TDetSystems/TS800/TS800Hit.cxx_OLD +libraries/TGRUTint/#TGRUTOptions.cxx# +libraries/THistogramming/#DynamicLibrary.cxx# +libraries/TLoops/#TChainLoop.cxx# +libraries/TNucleus/#TNucleus.cxx# +libraries/TNucleus/TPeakFinder.cpp +libraries/TNucleus/TTransition.cpp +libraries/TRawFormat/#TRawEventSource.cxx# +pygui/#hist_tab.py# +util/#grut-config# +util/CalculateCrossSection.C +util/CheckUnCalCRDCY_jab.C +util/Check_TOF_71Cu.C +util/Check_TOF_73Cu.C +util/Check_TOF_77Cu.C +util/CoincidenceHelpers.C +util/GetXtalEnVsPhi.C diff --git a/.grutrc b/.grutrc index 5a6ef304..85c8fcae 100644 --- a/.grutrc +++ b/.grutrc @@ -4,19 +4,17 @@ Unix.*.Root.MacroPath: .:$(GRUTSYS)/util:$(ROOTSYS)/macros #default MakeHistos library #GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosSourcesSim.so -GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosInBeamLH.so -#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosTarEx.so -#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010_p43.so -#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistos_e10010_p41.so +#GRUT.HistLib: $(GRUTSYS)/lib/libMakeHistosInBeam.so +GRUT.HistLib: $(GRUTSYS)/lib/libStupid.so GRUT.GuiSetup: $(GRUTSYS)/gui_params.hist #GRUT.SnapshotExt: png #GRUT.SnapshotDir: /user/benderp/public_html/figures -GRUT.SnapshotExt: -GRUT.SnapshotDir: +GRUT.SnapshotExt: png +GRUT.SnapshotDir: ~/doc/log -GRUT.DefaultCutFile: mycuts.cuts +GRUT.DefaultCutFile: mycuts.root #files to load at log in: Rint.Logon: $(GRUTSYS)/.grut_logon @@ -40,6 +38,8 @@ Root.Fitter: Fumili2 #Root.Fitter: Minuit +#Gui.Backend: qt +#Gui.Factory: qt Gui.IconPath: $(GRUTSYS)/icons:$(ROOTSYS)/icons #$(ROOTSYS)/etc/root.mimes Gui.MimeTypeFile: $(GRUTSYS)/.grut.mimes diff --git a/config/DetectorEnvironment.env b/config/DetectorEnvironment.env index ca933338..f5dbc3bf 100644 --- a/config/DetectorEnvironment.env +++ b/config/DetectorEnvironment.env @@ -6,13 +6,16 @@ Gretina: Mode3: Bank29: Phoswall: +Lenda: S800: 5 S800Scaler: -Sega: 1 2 3 +Sega: #1 2 3 Janus: -Caesar: 0 +Caesar: #0 FastScint: 4 +OBJ: 0 + # Trailing newline required diff --git a/Gretina.hist b/config/Gretina.hist similarity index 98% rename from Gretina.hist rename to config/Gretina.hist index 5c877ddd..69c6efbf 100644 --- a/Gretina.hist +++ b/config/Gretina.hist @@ -26,23 +26,3 @@ ] } - - - - - - - - - - - - - - - - - - - - diff --git a/config/myvalues.val b/config/myvalues.val new file mode 100644 index 00000000..a4c5f9a9 --- /dev/null +++ b/config/myvalues.val @@ -0,0 +1,55 @@ +AEM { +value: 931.494013 +} + + +BRHO0 { +value: 3.426500 +} + + +DISPERSION { +value: 50.000000 +} + + +LENGTH { +value: 46.020000 +} + + +STRIP_SLOPE { +value: 0.307600 +} + + +TKE_OFFSET { +value: 15.000000 +} + + +TOF_OFFSET { +value: 614.300000 +} + + +VC { +value: 0.299792 +} + + +Z2_SLOPE { +value: 0.000000 +} + + +Z_OFFSET { +value: 0.000000 +} + + +Z_SLOPE { +value: 3.889000 +} + + diff --git a/config/sega_cal.cal b/config/sega_cal.cal new file mode 100644 index 00000000..08785874 --- /dev/null +++ b/config/sega_cal.cal @@ -0,0 +1,246 @@ + + + +Sega00: { + Address: 0x5e6a0200 + Number: 2 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} +----------------------------------- + +Sega01: { + Address: 0x5e6a0300 + Number: 3 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + + +Sega02: { + Address: 0x5e6a0400 + Number: 4 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + +Sega03: { + Address: 0x5e6a0500 + Number: 5 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + +Sega04: { + Address: 0x5e6a0600 + Number: 6 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} +----------------------------------- + +Sega05: { + Address: 0x5e6a0900 + Number: 9 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + + +Sega06: { + Address: 0x5e6a0a00 + Number: 10 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + +Sega07: { + Address: 0x5e6a0b00 + Number: 11 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} +Sega08: { + Address: 0x5e6a0c00 + Number: 12 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} +----------------------------------- + +Sega09: { + Address: 0x5e6a0d00 + Number: 13 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + + +Sega10: { + Address: 0x5e6a0e00 + Number: 14 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + +Sega11: { + Address: 0x5e6a1100 + Number: 17 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} +Sega12: { + Address: 0x5e6a1200 + Number: 18 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} +----------------------------------- + +Sega13: { + Address: 0x5e6a1300 + Number: 19 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + + +Sega14: { + Address: 0x5e6a1400 + Number: 20 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + +Sega15: { + Address: 0x5e6a1500 + Number: 21 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} + +Sega16: { + Address: 0x5e6a1600 + Number: 22 + Info: + System: + Position: + Subposition: + Segment: 32 + Pedestal: 0 + EnergyCoeff: 0 1 + TimeCoeff: + EfficiencyCoeff: +} diff --git a/filters/Filter_e10010.cxx b/filters/Filter_e10010.cxx index 2a2b4cc0..e964f7a9 100644 --- a/filters/Filter_e10010.cxx +++ b/filters/Filter_e10010.cxx @@ -12,28 +12,26 @@ extern "C" bool FilterCondition(TRuntimeObjects& obj) { TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); + //TS800 *s800 = obj.GetDetector(); if(!gretina) return false; - - if(!s800){ - // printf("i am returning false ***\n"); fflush(stdout); - return false; } - - // std::cout << s800->Size() << std::endl; + //if((s800->GetTrigger().GetRegistr()&0x0002)>>1) + // return true; + //if(s800->GetTrigger().GetRegistr()==3) { + //printf("i am returning true\n"); fflush(stdout); + // return true; + //} + //return false; + gretina->CleanHits(); + if(!gretina->Size()) + return false; - // if(s800->GetTrigger().GetRegistr()==3) { - if( s800->GetTrigger().GetRegistr()&0x0002 ){ - // printf("i am returning true\n"); fflush(stdout); - return true; - } - // printf("i am returning false ***\n"); fflush(stdout); - return false; + return true; } diff --git a/gui_params.hist b/gui_params.hist deleted file mode 100644 index 29f7cbf2..00000000 --- a/gui_params.hist +++ /dev/null @@ -1,9 +0,0 @@ -{'histograms': [], - 'tcuts': [], - 'variables': {'AFP_COEF': 1200, - 'BETA': 0.404, - 'CRDCX_COEF': 0.15, - 'E1_TDC_high': 8000, - 'E1_TDC_low': -8000, - 'MAFP_COEF': 1000, - 'MCRDCX_COEF': 0.1}} diff --git a/histos/BenchmarkGrutinizerSpecTcl.cxx b/histos/BenchmarkGrutinizerSpecTcl.cxx deleted file mode 100644 index d5248e61..00000000 --- a/histos/BenchmarkGrutinizerSpecTcl.cxx +++ /dev/null @@ -1,163 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include - -#include - -#include -#include -#include -#include "TRandom.h" - -#include "TObject.h" -#include "TS800.h" - -#include "TChannel.h" -#include "GValue.h" -#include "TCutG.h" - -TH1 *GetHistogram(TList *list, std::string histname,int xbins,double xlow,double xhigh) { - //TList *list = &(obj.GetObjects()); - TH1 *hist = (TH1*)list->FindObject(histname.c_str()); - if(!hist) { - hist= new TH1I(histname.c_str(),histname.c_str(),xbins,xlow,xhigh); - list->Add(hist); - } - return hist; -} - -TH2 *GetMatrix(TList *list, std::string histname,int xbins, double xlow,double xhigh, - int ybins, double ylow,double yhigh) { - //TList *list = &(obj.GetObjects()); - TH2 *mat = (TH2*)list->FindObject(histname.c_str()); - if(!mat) { - mat = new TH2I(histname.c_str(),histname.c_str(),xbins,xlow,xhigh, - ybins,ylow,yhigh); - list->Add(mat); - } - return mat; -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - TS800 *s800 = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(s800) { - - double ic_sum = s800->GetIonChamber().GetSum(); - double objtac_corr = s800->GetCorrTOF_OBJTAC(); - double objtac = s800->GetTof().GetTacOBJ(); - double crdc_1_x = s800->GetCrdc(0).GetDispersiveX(); - double crdc_2_x = s800->GetCrdc(1).GetDispersiveX(); - double crdc_1_y = s800->GetCrdc(0).GetNonDispersiveY(); - double crdc_2_y = s800->GetCrdc(1).GetNonDispersiveY(); - double xfptac = s800->GetTof().GetTacXFP(); - double xfp = s800->GetTof().GetXFP(); - double obj = s800->GetTof().GetOBJ(); - double ata = s800->GetAta(); - double bta = s800->GetBta(); - double dta = s800->GetDta(); - double yta = s800->GetYta(); - double crdc_1_anode = s800->GetCrdc(0).GetAnode(); - double crdc_2_anode = s800->GetCrdc(1).GetAnode(); - double crdc_1_tac = s800->GetCrdc(0).GetTime(); - double crdc_2_tac = s800->GetCrdc(1).GetTime(); - double crdc_1_tac_rand = s800->GetCrdc(0).GetTimeRand(); - double crdc_2_tac_rand = s800->GetCrdc(1).GetTimeRand(); - int crdc1_size = s800->GetCrdc(0).Size(); - int crdc2_size = s800->GetCrdc(1).Size(); - - for (int i =0; i < crdc1_size; i++){ - int crdc_1_data = s800->GetCrdc(0).GetData(i); - TH1 *crdc1data = GetHistogram(list,"crdc1_data",4096,0,4096); - crdc1data->Fill(crdc_1_data); - } - for (int i =0; i < crdc2_size; i++){ - int crdc_2_data = s800->GetCrdc(1).GetData(i); - TH1 *crdc2data = GetHistogram(list,"crdc2_data",4096,0,4096); - crdc2data->Fill(crdc_2_data); - } - - TH1 *crdc1anode = GetHistogram(list,"crdc1_anode",4096,0,4096); - crdc1anode->Fill(crdc_1_anode); - TH1 *crdc2anode = GetHistogram(list,"crdc2_anode",4096,0,4096); - crdc2anode->Fill(crdc_2_anode); - TH1 *crdc1tac = GetHistogram(list,"crdc1_tac",4096,0,4096); - crdc1tac->Fill(crdc_1_tac); - TH1 *crdc2tac = GetHistogram(list,"crdc2_tac",4096,0,4096); - crdc2tac->Fill(crdc_2_tac); - TH1 *crdc1tac_rand = GetHistogram(list,"crdc1_tac_rand",4096,0,4096); - crdc1tac_rand->Fill(crdc_1_tac_rand); - TH1 *crdc2tac_rand = GetHistogram(list,"crdc2_tac_rand",4096,0,4096); - crdc2tac_rand->Fill(crdc_2_tac_rand); - - TH2 *tac_vs_ic= GetMatrix(list,"PID_TAC",4096,0,4096,4096,0,4096); - tac_vs_ic->Fill(objtac_corr, ic_sum); - - TH1 *ion_sum = GetHistogram(list,"ic_sum",4096,0,4096); - ion_sum->Fill(ic_sum); - - - TH1 *tacobj = GetHistogram(list,"grut_tacobj",4096,0,4096); - tacobj->Fill(objtac); - TH1 *tacxfp = GetHistogram(list,"grut_tacxfp",4096,0,4096); - tacxfp->Fill(xfptac); - - TH1 *obj_hist = GetHistogram(list,"grut_obj",6000,-3000,3000); - obj_hist->Fill(obj); - TH1 *xfp_hist = GetHistogram(list,"grut_xfp",6000,-3000,3000); - xfp_hist->Fill(xfp); - TH1 *crdc1x = GetHistogram(list,"grut_crdc1_x",600,-300,300); - crdc1x->Fill(crdc_1_x); - TH1 *crdc2x = GetHistogram(list,"grut_crdc2_x",600,-300,300); - crdc2x->Fill(crdc_2_x); - TH1 *crdc1y = GetHistogram(list,"grut_crdc1_y",600,-300,300); - crdc1y->Fill(crdc_1_y); - TH1 *crdc2y = GetHistogram(list,"grut_crdc2_y",600,-300,300); - crdc2y->Fill(crdc_2_y); - - TH1 *tacobj_corr = GetHistogram(list,"grut_tacobj_corr",4096,0,4096); - tacobj_corr->Fill(objtac_corr); - - - - - if (crdc1_size && crdc2_size){ - TH1 *ata_hist = GetHistogram(list, "grut_ata", 9999,-0.1,0.1); - ata_hist->Fill(ata); - - TH1 *bta_hist = GetHistogram(list, "grut_bta", 9999,-0.1,0.1); - bta_hist->Fill(bta); - - TH1 *dta_hist = GetHistogram(list, "grut_dta", 9999,-0.06,0.06); - dta_hist->Fill(dta); - - TH1 *yta_hist = GetHistogram(list, "grut_yta", 9999,-0.1,0.1); - yta_hist->Fill(yta); - } - - TH1 *trig_bit = GetHistogram(list, "grut_TrigBit", 10,0,10); - int freg = s800->GetTrigger().GetRegistr(); - if (freg != 1 && freg != 2 && freg != 3){ - trig_bit->Fill(9); //Just a random channel to fill for nonsense input - } - else{ - if (freg&1){ - trig_bit->Fill(0); - } - if (freg&2){ - trig_bit->Fill(1); - } - } - }//s800 exists - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/BetterCaesarHistos.cxx b/histos/BetterCaesarHistos.cxx deleted file mode 100644 index 176e7cd0..00000000 --- a/histos/BetterCaesarHistos.cxx +++ /dev/null @@ -1,585 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include - -#include - -#include -#include -#include -#include -#include "TRandom.h" - -#include "TPreserveGDirectory.h" -#include "TObject.h" -#include "TCaesar.h" -#include "TS800.h" - -#include "TChannel.h" -#include "GValue.h" -#include "TFile.h" -#include "TCutG.h" - -TFile *cut_file = 0; - - -const int total_det_in_prev_rings[N_RINGS] = {0,10,24,48,72,96,120,144,168,182}; -const double START_ANGLE = 3.2; -const double FINAL_ANGLE = 3.2; -const double ANGLE_STEPS = 0.1; -const int ENERGY_THRESHOLD = 300; -const int TOTAL_ANGLES = (FINAL_ANGLE-START_ANGLE)/ANGLE_STEPS + 1; - -std::vector angles; - - -bool init_called = false; - -void Init() { - double temp_angle = START_ANGLE; - for (int i = 0; i < TOTAL_ANGLES; i++){ - angles.push_back(temp_angle); - temp_angle += ANGLE_STEPS; - } - init_called = true; -} - - - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - TCaesar *caesar = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - double beta = GValue::Value("BETA"); - double z_shift = GValue::Value("TARGET_SHIFT_Z"); - - static TCutG *timingcut = 0; - if(!timingcut) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/timingcut.root"); - timingcut = (TCutG*)fcut.Get("tcut"); - } - static TCutG *InBeam_Mid = 0; - if(!InBeam_Mid) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newmid.root"); - InBeam_Mid = (TCutG*)fcut.Get("InBeam_Mid"); - } - static TCutG *InBeam_Top = 0; - if(!InBeam_Top) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newtop.root"); - InBeam_Top = (TCutG*)fcut.Get("Inbeam_top"); - } - static TCutG *InBeam_btwnTopMid = 0; - if(!InBeam_btwnTopMid) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newbetween.root"); - InBeam_btwnTopMid = (TCutG*)fcut.Get("between"); - } - static TCutG *al23blob = 0; - if(!al23blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/al23blob.root"); - al23blob = (TCutG*)fcut.Get("al23blob"); - } - static TCutG *si24blob = 0; - if(!si24blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/si24blob.root"); - si24blob = (TCutG*)fcut.Get("si24blob"); - } - - static TCutG *newal23blob = 0; - if(!newal23blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newal23blob.root"); - newal23blob = (TCutG*)fcut.Get("newal23blob"); - } - static TCutG *newsi24blob = 0; - if(!newsi24blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newsi24blob.root"); - newsi24blob = (TCutG*)fcut.Get("newsi24blob"); - } - static TCutG *newmg22blob = 0; - if(!newmg22blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newmg22blob.root"); - newmg22blob = (TCutG*)fcut.Get("newmg22blob"); - } - - // Stuff for interactive gates! - TList *gates = &(obj.GetGates()); - bool haspids = gates->GetSize(); - - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - if(caesar) { - if(!init_called) - Init(); - int valid_counter=0; - int ng_newal23blob=0; - int ng_newsi24blob=0; - int ng_newmg22blob=0; - - for(unsigned int k=0;kSize();k++) { - TCaesarHit hit_m = caesar->GetCaesarHit(k); - if(!hit_m.IsValid()) - continue; - - if(!s800) - continue; - - double ic_sum_m = s800->GetIonChamber().GetAve(); - double objtac_corr_m = s800->GetCorrTOF_OBJTAC(); - double objtac_m = s800->GetTof().GetTacOBJ(); - double xfptac_m = s800->GetTof().GetTacXFP(); - TVector3 track_m = s800->Track(); - double corr_time_m = caesar->GetCorrTime(hit_m,s800); - - if(newal23blob->IsInside(objtac_corr_m,ic_sum_m) && InBeam_btwnTopMid->IsInside(objtac_m,xfptac_m) && timingcut->IsInside(corr_time_m,hit_m.GetDoppler(beta,z_shift,&track_m))) - ng_newal23blob++; - - if(newsi24blob->IsInside(objtac_corr_m,ic_sum_m) && InBeam_Top->IsInside(objtac_m,xfptac_m) && timingcut->IsInside(corr_time_m,hit_m.GetDoppler(beta,z_shift,&track_m))) - ng_newsi24blob++; - - if(newmg22blob->IsInside(objtac_corr_m,ic_sum_m) && InBeam_Mid->IsInside(objtac_m,xfptac_m) && timingcut->IsInside(corr_time_m,hit_m.GetDoppler(beta,z_shift,&track_m))) - ng_newmg22blob++; - - }//end for loop to get multiplicity of caesar event - - for(unsigned int i=0;iSize();i++) { - TCaesarHit hit = caesar->GetCaesarHit(i); - if(!hit.IsValid()) - continue; - valid_counter++; - - int ring = hit.GetRingNumber(); - - obj.FillHistogram("Caesar","CAESAR_raw_time", 4096,0,4096,hit.Time()); - obj.FillHistogram("Caesar","GetTime_vs_GetDoppler",2000,0,2000,hit.GetTime(), - 2048,0,8192,hit.GetDoppler(beta,z_shift)); - if(hit.GetDoppler(beta,z_shift)>300){ - obj.FillHistogram("Caesar","GetTime_vs_GetAbsoluteDetectorNumber",200,0,200,hit.GetAbsoluteDetectorNumber(), - 2000,0,2000,hit.GetTime()); - }//end if Doppler > 300 - - obj.FillHistogram("Caesar","Detector_Charge_Summary",300,0,300,hit.GetDetectorNumber()+total_det_in_prev_rings[ring], - 4096,0,4096,hit.Charge()); - - obj.FillHistogram("Caesar","Detector_Energy_Summary",300,0,300,hit.GetDetectorNumber()+total_det_in_prev_rings[ring], - 2048,0,8192,hit.GetEnergy()); - - obj.FillHistogram("Caesar","Detector_Doppler_Summary",300,0,300,hit.GetDetectorNumber()+total_det_in_prev_rings[ring], - 2048,0,8192,hit.GetDoppler(beta,z_shift)); - - for(unsigned int j=0;jSize();j++) { - if(i==j) - continue; - TCaesarHit hit2 = caesar->GetCaesarHit(j); - if(!hit2.IsValid()) - continue; - obj.FillHistogram("Caesar","Energy_Coincidence_Matrix",2048,0,8192,hit.GetEnergy(), - 2048,0,8192,hit2.GetEnergy()); - - }//end for loop over coincidence hits - - if(!s800) { - continue; - } - - /**************************************\ - | Lets think about the location of this| - | if(s800) that is inside our loop over| - | CAESAR Hits!!!! | - \**************************************/ - - if(s800) { - - double ic_sum = s800->GetIonChamber().GetAve(); - double objtac_corr = s800->GetCorrTOF_OBJTAC(); - double objtac = s800->GetTof().GetTacOBJ(); - double xfptac = s800->GetTof().GetTacXFP(); - double afp = s800->GetAFP(); - double xfp_focalplane = s800->GetXFP(0); - TVector3 track = s800->Track(); - double corr_time = caesar->GetCorrTime(hit,s800); - obj.FillHistogram("Caesar","GetCorrTime_vs_GetDoppler",4000,-2000,2000,corr_time, - 2048,0,8192,hit.GetDoppler(beta,z_shift,&track)); - - - - if(timingcut->IsInside(corr_time,hit.GetDoppler(beta,z_shift,&track))){ - - std::string dirname = "PID"; - - std::string histname = "IncomingPID"; - obj.FillHistogram(dirname,histname, - 1000,-1000,5000,objtac, - 1000,-1000,5000,xfptac); - - histname = "AFP_vs_OBJTOF"; - obj.FillHistogram(dirname,histname, - 1000,-500,2500,objtac_corr, - 1000,-1,1,afp); // check units of AFP - - histname = "XFP_vs_OBJTOF"; - obj.FillHistogram(dirname,histname, - 1000,-500,2500,objtac_corr, - 1000,-300,300,xfp_focalplane); - - histname = "IC_vs_OBJTOF_PID"; - obj.FillHistogram(dirname,histname, - 1000,-500,2500,objtac_corr, - 1000,-100,4000,ic_sum); - - if(InBeam_Mid->IsInside(objtac,xfptac)){ - histname = "IC_vs_OBJTOF_PID_InBeam_Mid"; - obj.FillHistogram(dirname,histname, - 1000,-500,2500,objtac_corr, - 1000,-100,4000,ic_sum); - obj.FillHistogram("Caesar_GATED","GetCorrTime_vs_GetDoppler_Mid",4000,-2000,2000,corr_time, - 2048,0,8192,hit.GetDoppler(beta,z_shift,&track)); - }//end if in mid cut - - if(InBeam_Top->IsInside(objtac,xfptac)){ - histname = "IC_vs_OBJTOF_PID_InBeam_Top"; - obj.FillHistogram(dirname,histname, - 1000,-500,2500,objtac_corr, - 1000,-100,4000,ic_sum); - obj.FillHistogram("Caesar_GATED","GetCorrTime_vs_GetDoppler_Top",4000,-2000,2000,corr_time, - 2048,0,8192,hit.GetDoppler(beta,z_shift,&track)); - }//end if in top cut - - if(InBeam_btwnTopMid->IsInside(objtac,xfptac)){ - histname = "IC_vs_OBJTOF_PID_InBeam_btwnTopMid"; - obj.FillHistogram(dirname,histname, - 1000,-500,2500,objtac_corr, - 1000,-100,4000,ic_sum); - obj.FillHistogram("Caesar_GATED","GetCorrTime_vs_GetDoppler_Btwn",4000,-2000,2000,corr_time, - 2048,0,8192,hit.GetDoppler(beta,z_shift,&track)); - }//end if in between cut - - - if(al23blob->IsInside(objtac_corr,ic_sum) && InBeam_btwnTopMid->IsInside(objtac,xfptac)){ - - histname = "Gamma_Gated_al23blob"; - obj.FillHistogram("GATED",histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - obj.FillHistogram("s800","CRDC1Y_Gated_al23blob", - 10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC2Y_Gated_al23blob", - 10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - - obj.FillHistogram("s800","CRDC1X_Gated_al23blob", - 800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - obj.FillHistogram("s800","CRDC2X_Gated_al23blob", - 800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - dirname = "InverseMap_GATED"; - - histname = "S800_YTA_Gated_al23blob"; - obj.FillHistogram(dirname,histname, - 1000,-50,50,s800->GetYta()); - - histname = "S800_DTA_Gated_al23blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA_vs_BTA_Gated_al23blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - histname = "FindBeta_al23blob"; - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram("GATED",histname, - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//for loop over beta_i - }//end if inside al23blob and inside between incomingPID - - if(si24blob->IsInside(objtac_corr,ic_sum) && InBeam_Top->IsInside(objtac,xfptac)){ - histname = "Gamma_Gated_si24blob"; - obj.FillHistogram("GATED",histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - obj.FillHistogram("s800","CRDC1Y_Gated_si24blob",10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC2Y_Gated_si24blob",10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC1X_Gated_si24blob",800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - obj.FillHistogram("s800","CRDC2X_Gated_si24blob",800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - dirname = "InverseMap_GATED"; - - histname = "S800_YTA_Gated_si24blob"; - obj.FillHistogram(dirname,histname, - 1000,-50,50,s800->GetYta()); - - histname = "S800_DTA_Gated_si24blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA_vs_BTA_Gated_si24blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - histname = "FindBeta_si24blob"; - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram("GATED",histname, - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//for loop over beta_i - - }//end if inside si24blob and inside top incomingPID - - if(newal23blob->IsInside(objtac_corr,ic_sum) && InBeam_btwnTopMid->IsInside(objtac,xfptac)){ - - histname = "Gamma_Gated_newal23blob"; - obj.FillHistogram("GATED",histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - obj.FillHistogram("s800","CRDC1Y_Gated_newal23blob", - 10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC2Y_Gated_newal23blob", - 10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - - obj.FillHistogram("s800","CRDC1X_Gated_newal23blob", - 800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - obj.FillHistogram("s800","CRDC2X_Gated_newal23blob", - 800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - dirname = "InverseMap_GATED"; - - histname = "S800_YTA_Gated_newal23blob"; - obj.FillHistogram(dirname,histname, - 1000,-50,50,s800->GetYta()); - - histname = "S800_DTA_Gated_newal23blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA_vs_BTA_Gated_newal23blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - histname = "FindBeta_newal23blob"; - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram("GATED",histname, - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - - if(ng_newal23blob==1){ - obj.FillHistogram("GATED","FindBeta_newal23blob_Mult1", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity 1 - if(ng_newal23blob==2){ - obj.FillHistogram("GATED","FindBeta_newal23blob_Mult2", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity 2 - if(ng_newal23blob>2){ - obj.FillHistogram("GATED","FindBeta_newal23blob_Mult>2", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity > 2 - }//for loop over beta_i - - if(hit.GetDoppler(beta,z_shift,&track)>300){ - obj.FillHistogram("Caesar_GATED","GetTime_vs_GetAbsoluteDetectorNumber_Gated_newal23blob", - 200,0,200,hit.GetAbsoluteDetectorNumber(), - 2000,0,2000,hit.GetTime()); - } - obj.FillHistogram("Caesar_GATED","GetCorrTime_vs_GetDoppler_Btwn_newal23blob", - 4000,-2000,2000,corr_time, - 2048,0,8192,hit.GetDoppler(beta,z_shift,&track)); - }//end if inside newal23blob and inside between incomingPID - - if(newsi24blob->IsInside(objtac_corr,ic_sum) && InBeam_Top->IsInside(objtac,xfptac)){ - histname = "Gamma_Gated_newsi24blob"; - obj.FillHistogram("GATED",histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - obj.FillHistogram("s800","CRDC1Y_Gated_newsi24blob",10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC2Y_Gated_newsi24blob",10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC1X_Gated_newsi24blob",800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - obj.FillHistogram("s800","CRDC2X_Gated_newsi24blob",800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - dirname = "InverseMap_GATED"; - - histname = "S800_YTA_Gated_newsi24blob"; - obj.FillHistogram(dirname,histname, - 1000,-50,50,s800->GetYta()); - - histname = "S800_DTA_Gated_newsi24blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA_vs_BTA_Gated_newsi24blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - histname = "FindBeta_newsi24blob"; - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram("GATED",histname, - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - - if(ng_newsi24blob==1){ - obj.FillHistogram("GATED","FindBeta_newsi24blob_Mult1", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity 1 - if(ng_newsi24blob==2){ - obj.FillHistogram("GATED","FindBeta_newsi24blob_Mult2", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity 2 - if(ng_newsi24blob>2){ - obj.FillHistogram("GATED","FindBeta_newsi24blob_Mult>2", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity > 2 - }//for loop over beta_i - - obj.FillHistogram("Caesar_GATED","GetCorrTime_vs_GetDoppler_Top_newsi24blob", - 4000,-2000,2000,corr_time, - 2048,0,8192,hit.GetDoppler(beta,z_shift,&track)); - }//end if inside newsi24blob and inside top incomingPID - - if(newmg22blob->IsInside(objtac_corr,ic_sum) && InBeam_Mid->IsInside(objtac,xfptac)){ - histname = "Gamma_Gated_newmg22blob"; - obj.FillHistogram("GATED",histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - obj.FillHistogram("s800","CRDC1Y_Gated_newmg22blob",10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC2Y_Gated_newmg22blob",10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC1X_Gated_newmg22blob",800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - obj.FillHistogram("s800","CRDC2X_Gated_newmg22blob",800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - dirname = "InverseMap_GATED"; - - histname = "S800_YTA_Gated_newmg22blob"; - obj.FillHistogram(dirname,histname, - 1000,-50,50,s800->GetYta()); - - histname = "S800_DTA_Gated_newmg22blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA_vs_BTA_Gated_newmg22blob"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - histname = "FindBeta_newmg22blob"; - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram("GATED",histname, - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - - if(ng_newmg22blob==1){ - obj.FillHistogram("GATED","FindBeta_newmg22blob_Mult1", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity 1 - if(ng_newmg22blob==2){ - obj.FillHistogram("GATED","FindBeta_newmg22blob_Mult2", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity 2 - if(ng_newmg22blob>2){ - obj.FillHistogram("GATED","FindBeta_newmg22blob_Mult>2", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - }//if multiplicity > 2 - }//for loop over beta_i - - obj.FillHistogram("Caesar_GATED","GetCorrTime_vs_GetDoppler_Mid_newmg22blob",4000,-2000,2000,corr_time, - 2048,0,8192,hit.GetDoppler(beta,z_shift,&track)); - }//end if inside newmg22blob and inside mid incomingPID - - obj.FillHistogram("s800","CRDC1Y",10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC2Y",10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC1X",800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - obj.FillHistogram("s800","CRDC2X",800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - obj.FillHistogram("s800","TrigBit",5,0,5,s800->GetTrigger().GetRegistr()); - - dirname = "InverseMap"; - - histname = "S800_YTA"; - obj.FillHistogram(dirname,histname, - 1000,-50,50,s800->GetYta()); - - histname = "S800_DTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA_vs_BTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - - if(haspids) { - dirname = "GATED"; - TIter it(gates); - while(TObject *itobj = it.Next()) { - if(!itobj->InheritsFrom(TCutG::Class())) - continue; - TCutG *mygate = (TCutG*)itobj; - - if(mygate->IsInside(objtac_corr,ic_sum)){ - - histname = Form("FindBeta_%s",mygate->GetName()); - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram(dirname,histname, - 300,0.2,0.5,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - } - - histname = Form("Gamma_%s",mygate->GetName()); - obj.FillHistogram(dirname,histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - - - histname = Form("CRDC1Y_Gated_%s",mygate->GetName()); - obj.FillHistogram("s800",histname, - 10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = Form("CRDC2Y_Gated_%s",mygate->GetName()); - obj.FillHistogram("s800",histname, - 10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - - - }// end IsInside(ResiduePID) - }// end iterating over gates - }//end haspids - - }// end of if inside timingcut - }// end of if(s800) - - - }// end of caesar for hit loop - obj.FillHistogram("Caesar","Multiplicity",300,0,300,valid_counter); - obj.FillHistogram("Caesar","Multiplicity_ng_al23blob",300,0,300,ng_newal23blob); - obj.FillHistogram("Caesar","Multiplicity_ng_si24blob",300,0,300,ng_newsi24blob); - obj.FillHistogram("Caesar","Multiplicity_ng_mg22blob",300,0,300,ng_newmg22blob); - } // I have a valid caesar event - - if(numobj!=list->GetSize()) - list->Sort(); - -}//end MakeHistograms diff --git a/histos/BetterCaesarHistos2.cxx b/histos/BetterCaesarHistos2.cxx deleted file mode 100644 index eba39138..00000000 --- a/histos/BetterCaesarHistos2.cxx +++ /dev/null @@ -1,171 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include - -#include - -#include -#include -#include -#include -#include "TRandom.h" - -#include "TPreserveGDirectory.h" -#include "TObject.h" -#include "TCaesar.h" -#include "TS800.h" - -#include "TChannel.h" -#include "GValue.h" -#include "TFile.h" -#include "TCutG.h" - -TFile *cut_file = 0; - - -const int total_det_in_prev_rings[N_RINGS] = {0,10,24,48,72,96,120,144,168,182}; -const double START_ANGLE = 3.2; -const double FINAL_ANGLE = 3.2; -const double ANGLE_STEPS = 0.1; -const int ENERGY_THRESHOLD = 300; -const int TOTAL_ANGLES = (FINAL_ANGLE-START_ANGLE)/ANGLE_STEPS + 1; - - - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - TCaesar *caesar = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - double beta = GValue::Value("BETA"); - double z_shift = GValue::Value("TARGET_SHIFT_Z"); - - static TCutG *timingcut = 0; - if(!timingcut) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/timingcut.root"); - timingcut = (TCutG*)fcut.Get("tcut"); - } - static TCutG *InBeam_Mid = 0; - if(!InBeam_Mid) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newmid.root"); - InBeam_Mid = (TCutG*)fcut.Get("InBeam_Mid"); - } - static TCutG *InBeam_Top = 0; - if(!InBeam_Top) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newtop.root"); - InBeam_Top = (TCutG*)fcut.Get("Inbeam_top"); - } - static TCutG *InBeam_btwnTopMid = 0; - if(!InBeam_btwnTopMid) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newbetween.root"); - InBeam_btwnTopMid = (TCutG*)fcut.Get("between"); - } - static TCutG *al23blob = 0; - if(!al23blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/al23blob.root"); - al23blob = (TCutG*)fcut.Get("al23blob"); - } - static TCutG *si24blob = 0; - if(!si24blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/si24blob.root"); - si24blob = (TCutG*)fcut.Get("si24blob"); - } - static TCutG *newal23blob = 0; - if(!newal23blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newal23blob.root"); - newal23blob = (TCutG*)fcut.Get("newal23blob"); - } - static TCutG *newsi24blob = 0; - if(!newsi24blob) { - TPreserveGDirectory Preserve; - TFile fcut("/mnt/analysis/pecan-2015/longfellow/e10002/newsi24blob.root"); - newsi24blob = (TCutG*)fcut.Get("newsi24blob"); - } - - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - if(!caesar) - return; - if(!s800) - return; - double ic_sum = s800->GetIonChamber().GetAve(); - double objtac_corr = s800->GetCorrTOF_OBJTAC(); - double objtac = s800->GetTof().GetTacOBJ(); - double xfptac = s800->GetTof().GetTacXFP(); - //double afp = s800->GetAFP(); - //double xfp_focalplane = s800->GetXFP(0); - TVector3 track = s800->Track(); - if(! newal23blob->IsInside(objtac_corr,ic_sum) && InBeam_btwnTopMid->IsInside(objtac,xfptac)){ - return; - } - - int counter=0; - int vcounter=0; - - std::string histname; - - for(unsigned int y=0;ySize();y++) { - TCaesarHit hit = caesar->GetCaesarHit(y); - counter++; - if(!hit.IsValid()) - continue; - vcounter++; - if(newal23blob->IsInside(objtac_corr,ic_sum) && InBeam_btwnTopMid->IsInside(objtac,xfptac)){ - - histname = "Gamma_Gated_newal23blob"; - obj.FillHistogram("Caesar",histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram("Caesar","Gamma_Gated_newal23blob_beta_scan", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - } - - }//end if inside newal23blob and inside between incomingPID - } - obj.FillHistogram("Caesar","Multiplicity_All",300,0,300,counter); - obj.FillHistogram("Caesar","Multiplicity_Valid",300,0,300,vcounter); - counter = 0; - vcounter =0; - - for(int y=0;yAddbackSize();y++) { - TCaesarHit hit = caesar->GetAddbackHit(y); - counter++; - if(!hit.IsValid()) - continue; - vcounter++; - if(newal23blob->IsInside(objtac_corr,ic_sum) && InBeam_btwnTopMid->IsInside(objtac,xfptac)){ - - histname = "a_Gamma_Gated_newal23blob"; - obj.FillHistogram("Addback",histname, - 1024,0,8192,hit.GetDoppler(beta,z_shift,&track)); - - for(int beta_i=0;beta_i<300;beta_i++){ - double beta_use = 0.2+(0.3/300.0)*double(beta_i); - obj.FillHistogram("Addback","a_Gamma_Gated_newal23blob_beta_scan", - 300,0.2,0.499,beta_use, - 1024,0,8192,hit.GetDoppler(beta_use,z_shift,&track)); - } - - }//end if inside newal23blob and inside between incomingPID - } - obj.FillHistogram("Addback","a_Multiplicity_All",300,0,300,counter); - obj.FillHistogram("Addback","a_Multiplicity_Valid",300,0,300,vcounter); - - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/CaesarMakeAddbackHistos.cxx b/histos/CaesarMakeAddbackHistos.cxx deleted file mode 100644 index 4f6cda17..00000000 --- a/histos/CaesarMakeAddbackHistos.cxx +++ /dev/null @@ -1,437 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include - -#include - -#include -#include -#include -#include -#include "TRandom.h" - -#include "TObject.h" -#include "TCaesar.h" -#include "TS800.h" - -#include "TChannel.h" -#include "GValue.h" -#include "TFile.h" -#include "TCutG.h" -#include "TPreserveGDirectory.h" - -int evt_ctr = 0; -int omitted_det = -1; -TFile *cut_file = 0; -TCutG *in = 0; -TCutG *pid = 0; -TCutG *tcut = 0; -//TH1 *GetHistogram(TList *list, std::string histname,int xbins,double xlow,double xhigh) { -// //TList *list = &(obj.GetObjects()); -// TH1 *hist = (TH1*)list->FindObject(histname.c_str()); -// if(!hist) { -// hist= new TH1I(histname.c_str(),histname.c_str(),xbins,xlow,xhigh); -// list->Add(hist); -// } -// return hist; -//} -// -//TH2 *GetMatrix(TList *list, std::string histname,int xbins, double xlow,double xhigh, -// int ybins, double ylow,double yhigh) { -// //TList *list = &(obj.GetObjects()); -// TH2 *mat = (TH2*)list->FindObject(histname.c_str()); -// if(!mat) { -// mat = new TH2I(histname.c_str(),histname.c_str(),xbins,xlow,xhigh, -// ybins,ylow,yhigh); -// list->Add(mat); -// } -// return mat; -//} - - -void initializeKr88Cuts(TFile * &cut_file, TCutG* &pid, TCutG* &tcut, - TCutG* &in) { - TPreserveGDirectory a; - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Kr88/cut_files/kr88_cuts.root","Read"); - pid = (TCutG*)cut_file->Get("large2_pid_kr88"); - tcut = (TCutG*)cut_file->Get("full_tcut"); - in = (TCutG*)cut_file->Get("in_kr88_large"); - -} - -void initializeKr90Cuts(TFile * &cut_file, TCutG* &pid, TCutG* &tcut, - TCutG* &in){ - TPreserveGDirectory a; - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Kr90/cut_files/kr90_cuts.root","Read"); - pid = (TCutG*)cut_file->Get("kr90_mid"); -// tcut = (TCutG*)cut_file->Get("tcut"); - tcut = (TCutG*)cut_file->Get("tcut_tighter"); - in = (TCutG*)cut_file->Get("in_kr90"); - omitted_det = 176; -} -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - TCaesar *caesar = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(caesar && s800) { - if (cut_file == 0){ - initializeKr88Cuts(cut_file,pid, tcut, in); - //initializeKr90Cuts(cut_file,pid, tcut, in); - } - const int SINGLES_ENERGY_THRESHOLD = 300; - const int AB_ENERGY_THRESHOLD = 0; - const int SCATTER_ANGLE_CUT = 180; - - std::vector energies_singles; - std::vector energies_addback; - std::vector energies_addback_n0; - std::vector energies_addback_n1; - std::vector energies_addback_n2; - std::vector energies_addback_ng; - std::vector time_singles; - std::vector pos_singles; - energies_singles.clear(); - energies_addback.clear(); - std::string dirname = ""; - std::string histname = ""; - //TVector3 track_vect = s800->ExitTargetVect(); - double objtac_corr = s800->GetCorrTOF_OBJTAC(); - double objtac = s800->GetTof().GetTacOBJ(); - double xfptac = s800->GetTof().GetTacXFP(); - double ic_sum = s800->GetIonChamber().GetAve(); - for(unsigned int y=0;ySize();y++) { - TCaesarHit &hit = caesar->GetCaesarHit(y); - if (omitted_det != -1 && omitted_det == hit.GetAbsoluteDetectorNumber()){ - continue; - } - if (hit.IsValid()){//only accept hits with both times and energies - std::string histname; - double energy_dc = hit.GetDoppler(); - double scatter_angle = s800->Track().Theta()*(180.0/TMath::Pi()); - double corr_time = caesar->GetCorrTime(hit,s800); - if (pid->IsInside(objtac_corr, ic_sum)){ - if (tcut->IsInside(corr_time, energy_dc)){ - if (in->IsInside(xfptac,objtac)){ - if (energy_dc > SINGLES_ENERGY_THRESHOLD){ - if (scatter_angle < SCATTER_ANGLE_CUT){ - energies_singles.push_back(energy_dc); - time_singles.push_back(hit.Time()); - pos_singles.push_back(hit.GetPosition()); - } - }//For multiplicity purposes - dirname = "Caesar"; - histname = "energy_dc_pid_in_tcut"; - obj.FillHistogram(dirname,histname, - 8192,0,8192,energy_dc); - }//inside in-beam cut - }//is inside timecut - }//is inside pid - }//hit has both energy and time - }//loop over singles hits - - - //Now loop over addback hits - int num_addback_hits = caesar->AddbackSize(); - for (int y = 0; y < num_addback_hits; y++){ - TCaesarHit &hit = caesar->GetAddbackHit(y); - - if (omitted_det != -1 && omitted_det == hit.GetAbsoluteDetectorNumber()){ - continue; - } - if (hit.IsValid()){//only accept hits with both times and energies - std::string histname; - - //double energy_dc = caesar->GetEnergyDC(hit); - double energy_dc = hit.GetDoppler(); - double corr_time = caesar->GetCorrTime(hit,s800); - double scatter_angle = s800->Track().Theta()*(180.0/TMath::Pi()); - - - if (pid->IsInside(objtac_corr, ic_sum)){ - if (tcut->IsInside(corr_time, energy_dc)){ - if (in->IsInside(xfptac,objtac)){ - if (energy_dc > AB_ENERGY_THRESHOLD){ - if (scatter_angle Clear(); } - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/CaesarMakeFitHistos.cxx b/histos/CaesarMakeFitHistos.cxx deleted file mode 100644 index 4a2c56a8..00000000 --- a/histos/CaesarMakeFitHistos.cxx +++ /dev/null @@ -1,227 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include - -#include - -#include -#include -#include -#include -#include "TRandom.h" - -#include "TObject.h" -#include "TCaesar.h" -#include "TS800.h" - -#include "TChannel.h" -#include "GValue.h" -#include "TFile.h" -#include "TCutG.h" - -#include "TPreserveGDirectory.h" -TFile *cut_file = 0; -TCutG *pid = 0; -TCutG *tcut = 0; -TCutG *in = 0; -int omitted_det = -1; -int omitted_det_2 = -1; - - -void initializeKr88Cuts(TFile * &cut_file, TCutG* &pid, TCutG* &tcut, - TCutG* &in) { - TPreserveGDirectory a;//needed to stop root from switching directories to cut_file - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Kr88/cut_files/kr88_cuts.root","Read"); - //pid = (TCutG*)cut_file->Get("pid_kr88_large"); - //pid = (TCutG*)cut_file->Get("pid_kr88_med"); - //pid = (TCutG*)cut_file->Get("pear_pid_kr88"); - pid = (TCutG*)cut_file->Get("large2_pid_kr88"); - //tcut = (TCutG*)cut_file->Get("tcut_tight"); - //pid = (TCutG*)cut_file->Get("pid_kr88_tight"); - //tcut = (TCutG*)cut_file->Get("tcut_widest_03_17_2016"); - tcut = (TCutG*)cut_file->Get("full_tcut"); - //tcut = (TCutG*)cut_file->Get("tcut_tight"); - in = (TCutG*)cut_file->Get("in_kr88_large"); -} -void initializeKr90Cuts(TFile * &cut_file, TCutG* &pid, TCutG* &tcut, - TCutG* &in) { - TPreserveGDirectory a;//needed to stop root from switching directories to cut_file - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Kr90/cut_files/kr90_cuts.root","Read"); - //pid = (TCutG*)cut_file->Get("pid_large"); - //pid = (TCutG*)cut_file->Get("pid_med"); - //tcut = (TCutG*)cut_file->Get("tcut_tight"); - pid = (TCutG*)cut_file->Get("kr90_mid"); -// pid = (TCutG*)cut_file->Get("kr90_widest"); -// pid = (TCutG*)cut_file->Get("kr90_tightest"); -// tcut = (TCutG*)cut_file->Get("tcut"); - tcut = (TCutG*)cut_file->Get("tcut_tighter"); - in = (TCutG*)cut_file->Get("in_kr90"); -// in = (TCutG*)cut_file->Get("in_kr90_tight"); -// in = (TCutG*)cut_file->Get("in_kr90_widest"); - omitted_det = 176;//referenced from 0! It's ring 8 detector 8 -} - -void initializeSe86Cuts(TFile* &cut_file, TCutG* &pid, TCutG* &in, TCutG *&tcut){ - TPreserveGDirectory a;//needed to stop root from switching directories to cut_file - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Se86/cut_files/grut_se86_cuts.root","Read"); - if (!cut_file){ - std::cout << "Failed to open cut file" << std::endl; - exit(5); - } - pid = (TCutG*)cut_file->Get("prelim_pid_se86"); - //in = (TCutG*)cut_file->Get("prelim_in_cut"); - in = (TCutG*)cut_file->Get("in_se86"); - tcut = (TCutG*)cut_file->Get("prelim_tcut"); - omitted_det = 176; - omitted_det_2 = 26; -} -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - TCaesar *caesar = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - std::string dirname = ""; - std::string histname = ""; - - if (s800){ - if (cut_file == 0){ - initializeKr90Cuts(cut_file,pid,tcut,in); - //initializeSe86Cuts(cut_file,pid,in,tcut); - //initializeKr88Cuts(cut_file,pid,tcut,in); - } - - double objtac_corr = s800->GetCorrTOF_OBJTAC(); - double ic_sum = s800->GetIonChamber().GetAve(); - - int freg = s800->GetTrigger().GetRegistr(); - int trigbit = 7; - if (freg != 1 && freg != 2 && freg != 3){ - trigbit = 9;//Just a random channel to fill for nonsense input - dirname = "Info"; - histname = "trig_bit"; - obj.FillHistogram(dirname,histname, - 10,0,10, trigbit); - } - else{ - if (freg&1){ - trigbit = 0; - dirname = "Info"; - histname = "trig_bit"; - obj.FillHistogram(dirname,histname, - 10,0,10, trigbit); - } - if (freg&2){ - trigbit = 1; - dirname = "Info"; - histname = "trig_bit"; - obj.FillHistogram(dirname,histname, - 10,0,10, trigbit); - } - } - if (pid->IsInside(objtac_corr,ic_sum)){ - int trigbit_gated = 7; - if (freg != 1 && freg != 2 && freg != 3){ - trigbit_gated = 9; - dirname = "Info"; - histname = "trig_bit_gated"; - obj.FillHistogram(dirname,histname, - 10,0,10, trigbit_gated); - } - else{ - if (freg&1){ - trigbit_gated = 0; - dirname = "Info"; - histname = "trig_bit_gated"; - obj.FillHistogram(dirname,histname, - 10,0,10, trigbit_gated); - } - if (freg&2){ - trigbit_gated = 1; - dirname = "Info"; - histname = "trig_bit_gated"; - obj.FillHistogram(dirname,histname, - 10,0,10, trigbit_gated); - } - } - - }//inside pid - if(caesar) { - const double START_ANGLE = 180.0; - const double FINAL_ANGLE = 180.0; -// const double START_ANGLE = 1.0; -// const double FINAL_ANGLE = 3.5; - const double ANGLE_STEPS = 0.1; - const int TOTAL_ANGLES = (FINAL_ANGLE-START_ANGLE)/ANGLE_STEPS + 1; - std::vector angles; - angles.reserve(TOTAL_ANGLES); - - double temp_angle = START_ANGLE; - for (int i = 0; i < TOTAL_ANGLES; i++){ - angles.push_back(temp_angle); - temp_angle += ANGLE_STEPS; - } - - for(unsigned int y=0;ySize();y++) { - - TCaesarHit &hit = caesar->GetCaesarHit(y); - if (omitted_det != -1 && hit.GetAbsoluteDetectorNumber() == omitted_det){ - continue; - } - if (omitted_det_2 != -1 && hit.GetAbsoluteDetectorNumber() == omitted_det_2){ - continue; - } - if (hit.IsValid()){//only accept hits with both times and energies - std::string histname; - //double energy_dc = caesar->GetEnergyDC(hit); - double energy_dc = hit.GetDoppler(); - - double corr_time = caesar->GetCorrTime(hit,s800); - double scatter_angle = s800->Track().Theta()*(180.0/TMath::Pi()); - - dirname = "Info"; - histname = "scatter_angle_ungated"; - obj.FillHistogram(dirname,histname, - 18000,0,180,fabs(scatter_angle)); - - double objtac = s800->GetTof().GetTacOBJ(); - double xfptac = s800->GetTof().GetTacXFP(); - - if (pid->IsInside(objtac_corr, ic_sum)){ - if (tcut->IsInside(corr_time, energy_dc)){ - if (in->IsInside(xfptac,objtac)){ - dirname = "Info"; - histname = "scatter_angle_pid_tcut_incut"; - obj.FillHistogram(dirname,histname, - 18000,0,180,fabs(scatter_angle)); - bool done = false; - int cur_angle_index = 0; - while (!done && cur_angle_index < TOTAL_ANGLES){ - if (fabs(scatter_angle) < angles.at(cur_angle_index)){ - for (int angle_index = cur_angle_index; angle_index < TOTAL_ANGLES; angle_index++){ - std::stringstream ss; - ss << "fit_angle_" << angles.at(angle_index); - dirname = "Fits"; - histname = ss.str(); - obj.FillHistogram(dirname, histname, - 8192,0,8192, energy_dc); - }//loop through angles above cur_angle_index to fill all histos - done = true; - }//scatter_angle < angles[cur_angle_index] - cur_angle_index++; - }//!done && cur_angle_index < TOTAL_ANGLES - }//inside in-beam cut - }//is inside timecut - }//is inside pid - }//hit has both energy and time - }//loop over hits - }//caesar exists - }//s800 exists - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/CaesarMakeHistos.cxx b/histos/CaesarMakeHistos.cxx deleted file mode 100644 index 377ba35f..00000000 --- a/histos/CaesarMakeHistos.cxx +++ /dev/null @@ -1,268 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include - -#include - -#include -#include -#include -#include -#include "TRandom.h" - -#include "TObject.h" -#include "TCaesar.h" -#include "TS800.h" - -#include "TChannel.h" -#include "GValue.h" -#include "TFile.h" -#include "TCutG.h" -#include "TPreserveGDirectory.h" - -TFile *cut_file = 0; -TCutG *pid = 0; -TCutG *tcut = 0; -TCutG *in = 0; -int omitted_det = -1; - -#define NUM_DETS 192 - -//void initializeKr88Cuts(TFile * &cut_file, TCutG* &pid_kr88, TCutG* &tcut_kr88, -// TCutG* &pid_rb, TCutG* &pid_br, TCutG* &in_kr88, -// TCutG* &pid_rb_left, TCutG* &pid_br_left, -// TCutG* &pid_rb_right, TCutG* &pid_br_right) { -// cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Kr88/cut_files/kr88_cuts.root","Read"); -// pid_kr88 = (TCutG*)cut_file->Get("large2_pid_kr88"); -//// pid_kr88 = (TCutG*)cut_file->Get("pid_kr88_large"); -// pid_rb = (TCutG*)cut_file->Get("pid_rb_large"); -// pid_br = (TCutG*)cut_file->Get("pid_br_large"); -//// tcut_kr88 = (TCutG*)cut_file->Get("tcut_widest_03_17_2016"); -// tcut_kr88 = (TCutG*)cut_file->Get("full_tcut"); -// in_kr88 = (TCutG*)cut_file->Get("in_kr88_large"); -// -// pid_rb_left = (TCutG*)cut_file->Get("pid_rb_left"); -// pid_br_left = (TCutG*)cut_file->Get("pid_br_left"); -// pid_rb_right = (TCutG*)cut_file->Get("pid_rb_right"); -// pid_br_right = (TCutG*)cut_file->Get("pid_br_right"); -//} - -void initializeSe86Cuts(TFile* &cut_file, TCutG* &pid, TCutG* &in, TCutG *&tcut){ - TPreserveGDirectory a;//needed to stop root from switching directories to cut_file - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Se86/cut_files/grut_se86_cuts.root","Read"); - if (!cut_file){ - std::cout << "Failed to open cut file" << std::endl; - exit(5); - } - pid = (TCutG*)cut_file->Get("prelim_pid_se86"); - //in = (TCutG*)cut_file->Get("prelim_in_cut"); - in = (TCutG*)cut_file->Get("in_se86"); - tcut = (TCutG*)cut_file->Get("prelim_tcut"); - omitted_det = 176; -} -void initializeKr90Cuts(TFile* &cut_file, TCutG* &pid, TCutG* &in, TCutG *&tcut){ - TPreserveGDirectory a;//needed to stop root from switching directories to cut_file - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Kr90/cut_files/kr90_cuts.root","Read"); - if (!cut_file){ - std::cout << "Failed to open cut file" << std::endl; - exit(5); - } - pid = (TCutG*)cut_file->Get("kr90_mid"); - //in = (TCutG*)cut_file->Get("prelim_in_cut"); - in = (TCutG*)cut_file->Get("in_kr90"); -// tcut = (TCutG*)cut_file->Get("tcut"); - tcut = (TCutG*)cut_file->Get("tcut_tighter"); - omitted_det = 176; -} -void initializeKr88Cuts(TFile* &cut_file, TCutG* &pid, TCutG* &in, TCutG *&tcut){ - TPreserveGDirectory a;//needed to stop root from switching directories to cut_file - cut_file = new TFile("/mnt/analysis/pecan-gade/elman/Kr88/cut_files/kr88_cuts.root","Read"); - if (!cut_file){ - std::cout << "Failed to open cut file" << std::endl; - exit(5); - } - pid = (TCutG*)cut_file->Get("large2_pid_kr88"); - in = (TCutG*)cut_file->Get("in_kr88_large"); - tcut = (TCutG*)cut_file->Get("full_tcut"); -} -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - TCaesar *caesar = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - const int total_det_in_prev_rings[N_RINGS] = {0,10,24,48,72,96,120,144,168,182}; - - std::string histname; - std::string dirname; - const int ENERGY_LOW_X = 0; - const int ENERGY_HIGH_X = 8192; - const int N_BINS_X = 8192; - - if(s800) { - double ic_sum = s800->GetIonChamber().GetAve(); - double objtac_corr = s800->GetCorrTOF_OBJTAC(); - double objtac = s800->GetTof().GetTacOBJ(); - double xfptac = s800->GetTof().GetTacXFP(); - double afp = s800->GetAFP(); - double xfp = s800->GetCrdc(0).GetDispersiveX();//for timing correction - double ata = s800->GetAta(); - double bta = s800->GetBta(); - dirname = "S800"; - histname ="ATA"; - obj.FillHistogram(dirname, histname,5000,-0.5,0.5, ata); - histname ="BTA"; - obj.FillHistogram(dirname, histname,5000,-0.5,0.5, bta); - histname ="PID_TAC"; - obj.FillHistogram(dirname, histname,N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac_corr, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, ic_sum); - histname ="tacxfp_tacobj_ungated"; - obj.FillHistogram(dirname, histname,N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, xfptac, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac); - histname ="raw_tacobj_vs_xfp"; - obj.FillHistogram(dirname, histname,N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac, - 600,-300,300, xfp); - histname ="raw_tacobj_vs_afp"; - obj.FillHistogram(dirname, histname,N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac, - 1000,-0.1,0.1, afp); - histname ="corr_tacobj_vs_xfp"; - obj.FillHistogram(dirname, histname,N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac_corr, - 600,-300,300, xfp); - histname ="corr_tacobj_vs_afp"; - obj.FillHistogram(dirname, histname,N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac_corr, - 1000,-0.1,0.1, afp); - - - histname = "TrigBit"; - int trig_bit = 6; - int freg = s800->GetTrigger().GetRegistr(); - if (freg != 1 && freg != 2 && freg != 3){ - trig_bit = 9; //Just a random channel to fill for nonsense input - obj.FillHistogram(dirname, histname,10,0,10 ,trig_bit); - } - else{ - if (freg&1){ - trig_bit = 0; - obj.FillHistogram(dirname, histname,10,0,10 ,trig_bit); - } - if (freg&2){ - trig_bit = 1; - obj.FillHistogram(dirname, histname,10,0,10 ,trig_bit); - } - } - if(caesar) { - for(unsigned int y=0;ySize();y++) { - if (cut_file == 0){ - // initializeSe86Cuts(cut_file,pid,in,tcut); - initializeKr88Cuts(cut_file,pid,in,tcut); - // initializeKr90Cuts(cut_file,pid,in,tcut); - } - TCaesarHit &hit = caesar->GetCaesarHit(y); - if (hit.IsValid()&&!hit.IsOverflow()){ - std::string histname; - int det = hit.GetDetectorNumber(); - int ring = hit.GetRingNumber(); - - dirname = "GeneralCaesar"; - int abs_det_num = hit.GetAbsoluteDetectorNumber(); - double raw_time = hit.GetTime(); - double corr_time = caesar->GetCorrTime(hit,s800); - double energy = hit.GetEnergy(); - double energy_dc = hit.GetDoppler(); - - //note crdc_1_x is xfp - double crdc_1_y = s800->GetCrdc(0).GetNonDispersiveY(); - double crdc_2_y = s800->GetCrdc(1).GetNonDispersiveY(); - double crdc_2_x = s800->GetCrdc(1).GetDispersiveX(); - if (energy_dc > 300){//need energy cut to not gate on noise - histname = "Raw_Time_Summary_Ungated"; - obj.FillHistogram(dirname, histname,200,0, 200, abs_det_num, - 2048,0,2048, raw_time); - } - histname = "CRDC1_Y"; - obj.FillHistogram(dirname, histname, 2000,-200,200, crdc_1_y); - histname = "CRDC2_Y"; - obj.FillHistogram(dirname, histname, 2000,-200,200, crdc_2_y); - histname = "CRDC2_X"; - obj.FillHistogram(dirname, histname, 2000,-200,200, crdc_2_x); - histname = "CRDC1_X"; - obj.FillHistogram(dirname, histname, 2000,-200,200, xfp); - - histname = "EnergyDC_CorrTime_ungated"; - obj.FillHistogram(dirname, histname, - 4000,-2000,2000, corr_time, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, energy_dc); - - if (in->IsInside(xfptac,objtac)){ - histname ="PID_TAC_INBEAM"; - obj.FillHistogram(dirname, histname,N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac_corr, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, ic_sum); - } - - if (pid->IsInside(objtac_corr, ic_sum)){ - dirname = "PID"; - histname = "EnergyDC_CorrTime_PID"; - obj.FillHistogram(dirname, histname, - 4000,-2000,2000, corr_time, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, energy_dc); - histname = "tacxfp_tacobj_PID"; - obj.FillHistogram(dirname, histname, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, xfptac, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, objtac); - if (energy_dc > 300){//need energy cut to not gate on noise - histname = "Raw_Time_Summary_PID"; - obj.FillHistogram(dirname, histname,200,0, 200, abs_det_num, - 2048,0,2048, raw_time); - } - histname = "CRDC1_Y_PID"; - obj.FillHistogram(dirname, histname, 2000,-200,200, crdc_1_y); - histname = "CRDC2_Y_PID"; - obj.FillHistogram(dirname, histname, 2000,-200,200, crdc_2_y); - histname = "CRDC2_X_PID"; - obj.FillHistogram(dirname, histname, 2000,-200,200, crdc_2_x); - histname = "CRDC1_X_PID"; - obj.FillHistogram(dirname, histname, 2000,-200,200, xfp); - - - if (tcut->IsInside(corr_time, energy_dc)){ - if (in->IsInside(xfptac,objtac)){ - if (omitted_det != -1 && det+total_det_in_prev_rings[ring] != omitted_det){ - histname = "EnergyDC_PID_incut_no176"; - obj.FillHistogram(dirname, histname, N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, energy_dc); - histname = "EnergyDC_CorrTime_PID_no176"; - obj.FillHistogram(dirname, histname, - 4000,-2000,2000, corr_time, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, energy_dc); - } - histname = "EnergyDC_PID_incut"; - obj.FillHistogram(dirname, histname, N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, energy_dc); - histname = "EnergyDC_CorrTime_PID"; - obj.FillHistogram(dirname, histname, - 4000,-2000,2000, corr_time, - N_BINS_X,ENERGY_LOW_X,ENERGY_HIGH_X, energy_dc); - - histname = "Detector_Energy_Summary_PID_IN_TCUT"; - obj.FillHistogram(dirname, histname, - NUM_DETS+1, 0, NUM_DETS+1, det+total_det_in_prev_rings[ring], - N_BINS_X, ENERGY_LOW_X, ENERGY_HIGH_X, energy); - - histname = "Detector_DCEnergy_Summary_PID_IN_TCUT"; - obj.FillHistogram(dirname, histname, - NUM_DETS+1, 0, NUM_DETS+1, det+total_det_in_prev_rings[ring], - N_BINS_X, ENERGY_LOW_X, ENERGY_HIGH_X, energy_dc); - }//inside in-beam cut - }//inside time - }//inside pid - }//hit is valid - }//loop over hits - }//caesar exists - }//if s800 - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/FastScintHists.cxx b/histos/FastScintHists.cxx deleted file mode 100644 index 703ab2c5..00000000 --- a/histos/FastScintHists.cxx +++ /dev/null @@ -1,145 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -// -// Note: from TRuntimeObjects: -// TList& GetDetectors(); -// TList& GetObjects(); -// - -#include - -#include -#include -#include -#include "TRandom.h" - -#include "TObject.h" -#include "TFastScint.h" - -float gamma1 = 1173; -float gamma2 = 1332; -float tol1 = 30; -float tol2 = 30; -int eventnum = 0; - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - TFastScint *fast = obj.GetDetector(); - - if(!fast) - return; - - eventnum++; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - std::string histname; - - histname = "Multiplicity"; - obj.FillHistogram(histname,20,0,20,fast->Size()); - - for(unsigned int i=0;iSize();i++) { - TFastScintHit hit = fast->GetLaBrHit(i); - - histname = "Multiplicity_detId"; - obj.FillHistogram(histname,20,0,20,hit.GetChannel(), - 20,0,20,fast->Size()); - - histname = "ChannelCharge"; - obj.FillHistogram(histname,4000,0,4000,hit.Charge(), - 20,0,20,hit.GetChannel()); - - histname = "ChannelTime-Uncalibrated"; - obj.FillHistogram(histname,64100,-100,64000,hit.Time(), - 20,0,20,hit.GetChannel()); - - histname = "ChannelEnergy"; - obj.FillHistogram(histname,4000,0,4000,hit.GetEnergy(), - 20,0,20,hit.GetChannel()); - - histname = Form("ChannelEnergy_multi%02i",fast->Size()); - obj.FillHistogram(histname,4000,0,4000,hit.GetEnergy(), - 20,0,20,hit.GetChannel()); - - histname = "ChannelTime-Calibrated"; - obj.FillHistogram(histname,64100,-100,64000,hit.GetTime(), - 20,0,20,hit.GetChannel()); - - histname = Form("ChannelTime-Calibrated_mult%02i",fast->Size()); - obj.FillHistogram(histname,64100,-100,64000,hit.GetTime(), - 20,0,20,hit.GetChannel()); - - - - for(unsigned int j=0;jSize();j++) { - if(i==j) - continue; - TFastScintHit hit2 = fast->GetLaBrHit(j); - histname = "gamma_gamma"; - std::string dirname = "energy_mat"; - obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetEnergy(), - 4000,0,4000,hit2.GetEnergy()); - - histname = Form("gamma_gamma_mult%i",fast->Size()); - obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetEnergy(), - 4000,0,4000,hit2.GetEnergy()); - - dirname = "time_mat"; - histname = "time_time"; - obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetTime(), - 4000,0,4000,hit2.GetTime()); - - histname = Form("time_time_multi%i",fast->Size()); - obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetTime(), - 4000,0,4000,hit2.GetTime()); - - histname = "dtime_all"; - obj.FillHistogram(dirname,histname,4000,-2000,2000,hit.GetTime() - hit2.GetTime()); - - //histname = Form("dtime_%i_%i",hit.GetChannel(),hit2.GetChannel()); - //obj.FillHistogram(dirname,histname,4000,-2000,2000,hit.GetTime() - hit2.GetTime()); - - //dirname = "energy_mat"; - //histname = Form("eng%i_eng%i",hit.GetChannel(),hit2.GetChannel()); - //obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetEnergy(), - // 4000,0,4000,hit2.GetEnergy()); - - if(abs(hit.GetEnergy() - gamma1) < tol1){ - dirname = "coincidence_energy_gated"; - histname = Form("%5.1f_in_channel_%i__dtime_vs_energy_in_channel_%i",gamma1,hit.GetChannel(),hit2.GetChannel()); - obj.FillHistogram(dirname,histname,4000,-2000,2000,hit.GetTime() - hit2.GetTime(), - 4000,0,4000,hit2.GetEnergy()); - - }//end if correct energy in first detector - - if(abs(hit2.GetEnergy() - gamma1) < tol1){ - dirname = "coincidence_energy_gated"; - histname = Form("%5.1f_in_channel_%i__dtime_vs_energy_in_channel_%i",gamma1,hit2.GetChannel(),hit.GetChannel()); - obj.FillHistogram(dirname,histname,4000,-2000,2000,hit2.GetTime() - hit.GetTime(), - 4000,0,4000,hit.GetEnergy()); - - }//end if correct energy in second detector - - if((abs(hit.GetEnergy() - gamma1) < tol1) && (abs(hit2.GetEnergy() - gamma2) < tol2)){ - - dirname = "coincidence_energy_gated"; - histname = Form("dtime_energies_%5.1f_and_%5.1f___channels_%i_%i",gamma1,gamma2,hit.GetChannel(),hit2.GetChannel()); - obj.FillHistogram(dirname,histname,4000,-2000,2000,hit.GetTime() - hit2.GetTime()); - - histname = "dtime_vs_eventnum"; - obj.FillHistogram(dirname,histname,4000,-2000,2000,hit.GetTime() - hit2.GetTime(), - 20000000/200000,0,20000000, eventnum); - - - }//end if correct energies in two coincident detectros - - }//end for loop over j - }//end for loop over i - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/GretinaMakeHistos.cxx b/histos/GretinaMakeHistos.cxx deleted file mode 100644 index 6d019672..00000000 --- a/histos/GretinaMakeHistos.cxx +++ /dev/null @@ -1,288 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - //std::cout << "obj pointer = 0x" << std::hex << &obj << std::dec << std::endl; - //std::cout << "obj::Get() = 0x" << std::hex << TRuntimeObjects::Get() << std::dec << std::endl; - //std::cout << "---------------------------------------------" << std::endl; - //std::cout << "---------------------------------------------" << std::endl; - - - //double MAFP_COEF = obj.GetVariable("MAFP_COEF"); - //double MCRDCX_COEF = obj.GetVariable("MCRDCX_COEF"); - //double AFP_COEF = GValue::Value("AFP_COEF"); - //double CRDCX_COEF = GValue::Value("CRDCX_COEF"); - double E1_TDC_low = GValue::Value("E1_TDC_low"); - double E1_TDC_high = GValue::Value("E1_TDC_high"); - double BETA = GValue::Value("BETA"); - - TList *gates = &(obj.GetGates()); - bool haspids = gates->GetSize(); - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - std::string histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(histname,16000,0,64000,hit.Charge()); - } - if(s800) { - std::string histname = "S800_Bank29_time"; - obj.FillHistogram(histname,200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - if(!gretina) - return; - - - //if(s800) { - //std::string histname = "S800_DTA"; - //obj.FillHistogram(histname,200,-10,10,s800->GetDta()); - - //histname = "S800_YTA"; - //obj.FillHistogram(histname,200,-10,10,s800->GetYta()); - - //} - - double gsum = 0.0; - for(unsigned int y=0;ySize();y++) { - TGretinaHit hit = gretina->GetGretinaHit(y); - std::string histname; - gsum += hit.GetCoreEnergy(); - - for(unsigned int z=y+1;zSize();z++) { - TGretinaHit hit2 = gretina->GetGretinaHit(z); - histname = "Gamma_Gamma"; - obj.FillHistogramSym(histname,2000,0,4000,hit.GetCoreEnergy(), - 2000,0,4000,hit2.GetCoreEnergy()); - histname = "Gamma_Gamma_Time"; - obj.FillHistogram(histname,800,-400,400,hit2.GetTime()-hit.GetTime(), - 2000,0,4000,hit2.GetCoreEnergy()); - obj.FillHistogram(histname,800,-400,400,hit.GetTime()-hit2.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - } - - - - if(bank29) { - histname = "Gretina_Bank29_time"; - obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTimestamp(), - 2000,0,4000,hit.GetCoreEnergy()); - histname = "Gretina_t0_Bank29_time"; - obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - } - - if(s800) { - histname = "Gretina_S800_time"; - obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetTimestamp(), - 2000,0,4000,hit.GetCoreEnergy()); - histname = "Gretina_t0_S800_time"; - obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - - histname = "pidtune1_TDC_vs_DispX"; - obj.FillHistogram(histname,4000,-4000,4000,s800->GetCorrTOF_OBJ(), //s800->GetTofE1_TDC(AFP_COEF,CRDCX_COEF), - 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - histname = "pidtune2_TDC_vs_AFP"; - obj.FillHistogram(histname,4000,-4000,4000,s800->GetCorrTOF_OBJ(), //s800->GetTofE1_TDC(AFP_COEF,CRDCX_COEF), - 600,-0.1,0.1,s800->GetAFP()); - - double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - histname ="pidtune3_PID_TDC"; - obj.FillHistogram(histname,4000,-4000,4000,s800->GetCorrTOF_OBJ(), //s800->GetTofE1_TDC(AFP_COEF,CRDCX_COEF), - 2000,0,50000,s800->GetIonChamber().Charge()); - - if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), //s800->GetTofE1_TDC(AFP_COEF,CRDCX_COEF), - 2000,0,50000,s800->GetIonChamber().Charge()); - } - - if(haspids) { - TIter it(gates); - while(TObject *itobj = it.Next()) { - if(!itobj->InheritsFrom(TCutG::Class())) - continue; - TCutG *mypid = (TCutG*)itobj; - if(mypid->IsInside(s800->GetCorrTOF_OBJ(),s800->GetIonChamber().Charge())) { - histname = "GretinaDoppler_%s",mypid->GetName(); - obj.FillHistogram(histname,2000,0,4000,hit.GetDoppler(BETA)); - } - } - } - - histname = "E1_m_TDC"; - obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - histname = "E1Raw"; - obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - histname = "M_E1Raw"; - for(int z=0;zGetMTof().E1UpSize();z++) - obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - obj.FillHistogram(histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - histname = "IonChamberSum"; - obj.FillHistogram(histname,4000,0,32000,s800->GetIonChamber().GetSum()); - - - - - } - histname = Form("GretinaEnergyTheta"); - obj.FillHistogram(histname,4000,0,4000,hit.GetCoreEnergy(), - 314,0,3.14,hit.GetTheta()); - - histname = Form("GretinaOverview"); - obj.FillHistogram(histname,4000,0,4000,hit.GetCoreEnergy(), - 100,0,100,hit.GetCrystalId()); - - histname = Form("GretinaSummaryX%02i",hit.GetCrystalId()); - for(int z=0;z36) - break; - int layer = hit.GetSegmentId(z)/6; - histname = Form("GretinaPosition_%s",LayerMap[layer].c_str()); - double phi = hit.GetInteractionPosition(z).Phi(); - if(phi<0) phi +=TMath::Pi()*2; - obj.FillHistogram(histname,628,0.0,6.28,phi, - 314,0,3.14,hit.GetInteractionPosition(z).Theta()); - } -/* - //for(int z=0;z0){ - if(hit.GetSegmentEng(0)>990) { - seg_summary->Fill(hit.GetSegmentId(0),hit.GetSegmentEng(0)); - int layer = hit.GetSegmentId(0)/6; - histname = Form("GretinaPositionLargestPosition_%s",LayerMap[layer].c_str()); - TH2 *position = (TH2*)list->FindObject(histname.c_str()); - if(!position) { - position = new TH2F(histname.c_str(),histname.c_str(),628,0,6.28,314,0,3.14); - list->Add(position); - } - double theta = hit.GetInteractionPosition(0).Theta(); - double phi = hit.GetInteractionPosition(0).Phi(); - if(phi<0) - phi = TMath::TwoPi()+phi; - position->Fill(phi,theta); - } - } -*/ - - histname = Form("GretinaPosition"); - obj.FillHistogram(histname,628,0,6.28,hit.GetPhi(), - 314,0,3.14,hit.GetTheta()); - - histname = "GretinaEnergyTotal"; - obj.FillHistogram(histname,8000,0,4000,hit.GetCoreEnergy()); - - histname = "GretinaDopplerTotal"; - obj.FillHistogram(histname,8000,0,4000,hit.GetDoppler(BETA)); - - histname = "GretinaDopplerBeta"; - double beta = 0.2; - for(int z=0;z<100;z++) { - beta += .3/100.0; - obj.FillHistogram(histname,8000,0,4000,hit.GetCoreEnergy(beta), - 101,0.2,0.5,beta); - } - - histname = Form("Q%iCoreCharge",HoleQMap[hit.GetCrystalId()/4]); - //if(HoleQMap[hit.GetHoleNumber()]==0) - // printf("HoleQMap[hit.GetHoleNumber() = 0 is %i\n",hit.GetHoleNumber()); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+0., - 4000,0,32000,((double)hit.GetCoreCharge(0))); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+1., - 4000,0,32000,((double)hit.GetCoreCharge(1))); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+2., - 4000,0,32000,((double)hit.GetCoreCharge(2))); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+3., - 4000,0,32000,((double)hit.GetCoreCharge(3))); - - histname = "CrystalId_hitpattern"; - obj.FillHistogram(histname,100,0,100,hit.GetCrystalId()); - } - - if(gsum>1.0) { - std::string histname = "GCalorimeter"; - obj.FillHistogram(histname,16000,0,8000,gsum); - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} diff --git a/histos/HasPIDs_Example.cxx b/histos/HasPIDs_Example.cxx deleted file mode 100644 index 90f98ce0..00000000 --- a/histos/HasPIDs_Example.cxx +++ /dev/null @@ -1,772 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - double BETA = GValue::Value("BETA"); - TVector3 trackvect_Spec(0,0,1); - - TList *gates = &(obj.GetGates()); - bool haspids = gates->GetSize(); - std::string histname = ""; - std::string dirname = ""; - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - }// end if BANK29 - - - /*=============================*\ - | If you dont have gretina, or | - | if the gretina size is less | - | than 1, get out of here. | - \*=============================*/ - if(!gretina || gretina->Size()<1) - return; - - double gsum = 0.0; - for(unsigned int y=0;ySize();y++) { - TGretinaHit hit = gretina->GetGretinaHit(y); - gsum += hit.GetCoreEnergy(); - if(bank29) { - dirname = "GretSummTime"; - histname = "Gretina_Bank29_time"; - obj.FillHistogram(dirname,histname, - 600,-600,600,bank29->Timestamp()-hit.GetTimestamp(), - 2000,0,4000,hit.GetCoreEnergy()); - histname = "Gretina_t0_Bank29_time"; - obj.FillHistogram(dirname,histname, - 600,-600,600,bank29->Timestamp()-hit.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - } - - if(s800) { - TVector3 trackvect=s800->ExitTargetVect(); - TVector3 trackvect_WithTC=s800->ExitTargetVect(); - TVector3 trackvect_WithNegTC=s800->ExitTargetVect(); - double targx = GValue::Value("GRETINA_X_OFFSET"); - double targy = GValue::Value("GRETINA_Y_OFFSET"); - double targz = GValue::Value("GRETINA_Z_OFFSET"); - TVector3 TargetShift; - TargetShift.SetXYZ(targx,targy,targz); - trackvect_WithTC = trackvect_WithTC+TargetShift; - trackvect_WithNegTC = trackvect_WithNegTC-TargetShift; - /* TVector3 zAxis(0,0,1); - TVector3 NormResPlane = trackvect.Cross(zAxis); - TVector3 NormGammaPlane = hit.GetPosition().Cross(zAxis); - TVector3 NormDiff = NormResPlane-NormGammaPlane; - TVector3 NormCrossNorm = NormResPlane.Cross(NormGammaPlane); - double SinHolder = TMath::ASin(NormCrossNorm.Mag()/(NormGammaPlane.Mag()*NormResPlane.Mag())); - double openang = NormResPlane.Angle(NormGammaPlane); - double CosHolder = NormResPlane.Angle(NormGammaPlane); - double openang2 = TMath::ATan2(SinHolder,CosHolder);*/ - //if(Stuff.Phi()<0) openang =6.28 - openang; - - double openang = (2.0*TMath::Pi() - s800->Azita()) - TMath::Abs(hit.GetPosition().Phi()); - if(openang<0) openang += 2.0*TMath::Pi(); - - - - - dirname = "GretSummTime"; - histname = "Gretina_S800_time"; - obj.FillHistogram(dirname,histname, - 1200,-600,600,s800->Timestamp()-hit.GetTimestamp(), - 2000,0,4000,hit.GetCoreEnergy()); - histname = "Gretina_t0_S800_time"; - obj.FillHistogram(dirname,histname, - 1200,-600,600,s800->Timestamp()-hit.GetTime(), - 3000,0,6000,hit.GetCoreEnergy()); - - float AllCorrOBJ_E1Val = s800->MCorrelatedOBJ_E1(false); - float AllCorrXFP_E1Val = s800->MCorrelatedXFP_E1(false); - dirname = "CorrelatedMESY"; - if(AllCorrOBJ_E1Val && AllCorrXFP_E1Val){ - //-------------------------------------------------------------------- - histname = "1D_OBJvsE1"; - obj.FillHistogram(dirname,histname, - 3000,-50000,50000,AllCorrOBJ_E1Val); - - histname = "1D_XFPvsE1"; - obj.FillHistogram(dirname,histname, - 3000,-50000,50000,AllCorrXFP_E1Val); - - histname = "2D_OBJvsE1"; - obj.FillHistogram(dirname,histname, - 3000,0,70000,s800->MCorrelatedOBJ(), - 3000,0,70000,s800->MCorrelatedE1()); - - histname = "2D_XFPvsE1"; - obj.FillHistogram(dirname,histname, - 3000,0,70000,s800->MCorrelatedXFP(), - 3000,0,70000,s800->MCorrelatedE1()); - - histname = "2D_Incoming_PID"; - obj.FillHistogram(dirname,histname, - 2000,-3000,0,AllCorrOBJ_E1Val, - 2000,2000,5000,AllCorrXFP_E1Val); - - double AllCorrectedOBJ_E1Val = s800->MCorrelatedOBJ_E1(true); - double AllCorrectedXFP_E1Val = s800->MCorrelatedXFP_E1(true); - histname = "2D_MTOF_vs_DispX"; - obj.FillHistogram(dirname,histname, - 4000,-2000,0,AllCorrectedOBJ_E1Val, - 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - histname = "2D_MTOF_vs_AFP"; - obj.FillHistogram(dirname,histname, - 4000,-2000,0,AllCorrectedOBJ_E1Val, - 600,-0.1,0.1,s800->GetAFP()); - - histname ="2D_MTOF_PID"; - obj.FillHistogram(dirname,histname, - 1000,-2000,0,AllCorrectedOBJ_E1Val, - 1000,0,40000,s800->GetIonChamber().Charge()); - - histname ="2D_MTOF_ICCorr_PID"; - obj.FillHistogram(dirname,histname, - 1000,-2000,0,AllCorrectedOBJ_E1Val, - 1000,0,40000,s800->GetIonChamber().GetdECorr(&(s800->GetCrdc()))); - - histname = "2D_Incoming_PID_BothCorrected"; - obj.FillHistogram(dirname,histname, - 2000,-3000,0,AllCorrectedOBJ_E1Val, - 2000,2000,5000,AllCorrectedXFP_E1Val); - - histname = "2D_Incoming_PID_XFPCorrected"; - obj.FillHistogram(dirname,histname, - 2000,-3000,0,AllCorrOBJ_E1Val, - 2000,2000,5000,AllCorrectedXFP_E1Val); - - histname = "2D_Incoming_PID_OBJCorrected"; - obj.FillHistogram(dirname,histname, - 2000,-3000,0,AllCorrectedOBJ_E1Val, - 2000,2000,5000,AllCorrXFP_E1Val); - - //-------------------------------------------------------------------- - - dirname = "Gamma_Doppler"; - histname = "GretinaDoppler"; - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit.GetDoppler(BETA)); - - if(gretina->Size()==1){ - histname = "Singles_GretinaDoppler"; - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit.GetDoppler(BETA)); - } - - - histname = "GretinaDopplerVsOpenAng"; - obj.FillHistogram(dirname,histname, - 1000,0,6.3,openang, - 2000,0,4000,hit.GetDoppler(BETA)); - /* histname = "GretinaDopplerVsOpenAng_Dirk"; - obj.FillHistogram(dirname,histname, - 3000,-10,10,openang_Dirk, - 2000,0,4000,hit.GetDoppler(BETA)); - histname = "GretinaDopplerVsOpenAng_Check"; - obj.FillHistogram(dirname,histname, - 2000,-7,7,openang2, - 2000,0,4000,hit.GetDoppler(BETA));*/ - - - int QuadNumb = HoleQMap[hit.GetCrystalId()/4]; - int SummarySlot = 0; - bool FWDet = false; - switch(QuadNumb){ - case 1: - FWDet = false; - SummarySlot = 1; - break; - case 2: - FWDet = true; - SummarySlot = 1; - break; - case 3: - FWDet = true; - SummarySlot = 2; - break; - case 4: - FWDet = false; - SummarySlot = 2; - break; - case 5: - FWDet = true; - SummarySlot = 3; - break; - case 6: - FWDet = false; - SummarySlot = 3; - break; - case 7: - SummarySlot = 4; - FWDet = false; - break; - case 8: - SummarySlot = 4; - FWDet = true; - break; - case 9: - SummarySlot = 5; - FWDet = false; - break; - default: - - break; - } - - histname = Form("GretinaDopplerVsDTA_Quad%02i",QuadNumb);; - obj.FillHistogram(dirname,histname, - 1000,-0.06,0.02,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA)); - - - - histname = "XtalDoppSummary"; - obj.FillHistogram(dirname,histname, - 70,20,90,hit.GetCrystalId(), - 1000,0,4000,hit.GetDoppler(BETA)); - - - - histname = "QuadDoppSummary"; - obj.FillHistogram(dirname,histname, - 10,0,10,HoleQMap[hit.GetCrystalId()/4], - 2000,0,4000,hit.GetDoppler(BETA)); - - - //std::cout << " ---- First call to GetDoppler with TRACK --------" << std::endl; - if(FWDet){ - histname = "QuadDoppSummary_FWRing"; - obj.FillHistogram(dirname,histname, - 10,0,10,SummarySlot, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - histname = "GretinaDopplerVsDTA_FWRing"; - obj.FillHistogram(dirname,histname, - 1000,-0.06,0.02,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA)); - } else{ - histname = "QuadDoppSummary_90DegRing"; - obj.FillHistogram(dirname,histname, - 10,0,10,SummarySlot, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - histname = "GretinaDopplerVsDTA_90DegRing"; - obj.FillHistogram(dirname,histname, - 1000,-0.06,0.02,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA)); - - } - - for(unsigned int z2=y+1;z2Size();z2++) { - TGretinaHit hit_2 = gretina->GetGretinaHit(z2); - - histname = "Gamma_Gamma"; - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit.GetDoppler(BETA), - 3000,0,6000,hit_2.GetDoppler(BETA)); - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit_2.GetDoppler(BETA), - 3000,0,6000,hit.GetDoppler(BETA)); - - histname = "Gamma_Gamma_Time"; - obj.FillHistogram(dirname,histname, - 800,-400,400,hit.GetTime()-hit_2.GetTime(), - 3000,0,6000,hit.GetDoppler(BETA)); - obj.FillHistogram(dirname,histname, - 800,-400,400,hit_2.GetTime()-hit.GetTime(), - 3000,0,6000,hit.GetDoppler(BETA)); - } - - //-------------------------------------------------------------------- - dirname = "Gamma_InvMapCorr"; - histname = "GretinaVecCorr"; - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit.GetDoppler(BETA,&trackvect)); - - if(gretina->Size()==1){ - histname = "Singles_GretinaInvMap"; - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit.GetDoppler(BETA,&trackvect)); - } - - - histname = "GretinaVecCorrVsOpenAng"; - obj.FillHistogram(dirname,histname, - 1000,0,6.3,openang, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - histname = "GretinaVecCorrVsDTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - - histname = Form("GretinaVectorVsDTA_Quad%02i",QuadNumb);; - obj.FillHistogram(dirname,histname, - 1000,-0.06,0.02,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - histname = "QuadVectSummary"; - obj.FillHistogram(dirname,histname, - 10,0,10,HoleQMap[hit.GetCrystalId()/4], - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - // std::cout << " Before XtalVectSummary ================== " << std::endl; - // std::cout << " Xtal = " << hit.GetCrystalId() << std::endl; - // std::cout << " X Offset = " << GValue::Value("GRETINA_X_OFFSET") << std::endl; - // std::cout << " Y Offset = " << GValue::Value("GRETINA_Y_OFFSET") << std::endl; - // std::cout << " Z Offset = " << GValue::Value("GRETINA_Z_OFFSET") << std::endl; - - histname = "XtalVectSummary"; - obj.FillHistogram(dirname,histname, - 70,20,90,hit.GetCrystalId(), - 1000,0,4000,hit.GetDoppler(BETA,&trackvect)); - //std::cout << " After XtalVectSummary ================== " << std::endl; - TVector3 TV90 = trackvect; - TV90.RotateZ(TMath::Pi()/2.); - TVector3 TV270 = trackvect; - TV270.RotateZ(3.0*TMath::Pi()/2.); - TVector3 TV180 = trackvect; - TV180.RotateZ(TMath::Pi()); - - histname = "XtalVectSummary_90"; - obj.FillHistogram(dirname,histname, - 70,20,90,hit.GetCrystalId(), - 1000,0,4000,hit.GetDoppler(BETA,&TV90)); - - histname = "XtalVectSummary_180"; - obj.FillHistogram(dirname,histname, - 70,20,90,hit.GetCrystalId(), - 1000,0,4000,hit.GetDoppler(BETA,&TV180)); - - histname = "XtalVectSummary_270"; - obj.FillHistogram(dirname,histname, - 70,20,90,hit.GetCrystalId(), - 1000,0,4000,hit.GetDoppler(BETA,&TV270)); - - - histname = "XtalVectSummary_WithTC"; - obj.FillHistogram(dirname,histname, - 70,20,90,hit.GetCrystalId(), - 1000,0,4000,hit.GetDoppler(BETA,&trackvect_WithTC)); - - histname = "XtalVectSummary_WithNegTC"; - obj.FillHistogram(dirname,histname, - 70,20,90,hit.GetCrystalId(), - 1000,0,4000,hit.GetDoppler(BETA,&trackvect_WithNegTC)); - - - if(FWDet){ - histname = "QuadVectSummary_FWRing"; - obj.FillHistogram(dirname,histname, - 10,0,10,SummarySlot, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - histname = "GretinaVectorVsDTA_FWRing"; - obj.FillHistogram(dirname,histname, - 1000,-0.06,0.02,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - } else{ - histname = "QuadVectSummary_90DegRing"; - obj.FillHistogram(dirname,histname, - 10,0,10,SummarySlot, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - histname = "GretinaVectorVsDTA_90DegRing"; - obj.FillHistogram(dirname,histname, - 1000,-0.06,0.02,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - } - - - for(unsigned int z3=y+1;z3Size();z3++) { - TGretinaHit hit_3 = gretina->GetGretinaHit(z3); - - histname = "Gamma_Gamma"; - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit.GetDoppler(BETA,&trackvect), - 3000,0,6000,hit_3.GetDoppler(BETA,&trackvect)); - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit_3.GetDoppler(BETA,&trackvect), - 3000,0,6000,hit.GetDoppler(BETA,&trackvect)); - - histname = "Gamma_Gamma_Time"; - obj.FillHistogram(dirname,histname, - 800,-400,400,hit.GetTime()-hit_3.GetTime(), - 3000,0,6000,hit.GetDoppler(BETA,&trackvect)); - obj.FillHistogram(dirname,histname, - 800,-400,400,hit_3.GetTime()-hit.GetTime(), - 3000,0,6000,hit.GetDoppler(BETA,&trackvect)); - } - - //-------------------------------------------------------------------- - - dirname = "InverseMap"; - histname = "S800_YTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetYta()); - - histname = "S800_DTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA_vs_BTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - //-------------------------------------------------------------------- - dirname = "PID"; - if(haspids) { - dirname = "PID_GATED"; - TIter it(gates); - while(TObject *itobj = it.Next()) { - if(!itobj->InheritsFrom(TCutG::Class())) - continue; - TCutG *mypid = (TCutG*)itobj; - if(mypid->IsInside(AllCorrectedOBJ_E1Val,s800->GetIonChamber().Charge())) { - }// end inside PID for Residues - if(mypid->IsInside(AllCorrOBJ_E1Val,AllCorrXFP_E1Val)){ - } - if(mypid->IsInside(AllCorrectedOBJ_E1Val, - s800->GetIonChamber().GetdECorr(&(s800->GetCrdc())))){ - histname = Form("GammaDoppler_Beta_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA)); - for(unsigned int z2_pid=y+1;z2_pidSize();z2_pid++) { - TGretinaHit hit_2_pid = gretina->GetGretinaHit(z2_pid); - - histname = Form("Gamma_Gamma_Beta_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit.GetDoppler(BETA), - 3000,0,6000,hit_2_pid.GetDoppler(BETA)); - obj.FillHistogram(dirname,histname, - 3000,0,6000,hit_2_pid.GetDoppler(BETA), - 3000,0,6000,hit.GetDoppler(BETA)); - } - - } - - // end inside PID for Incoming PID - // if(mypid->IsInside(AllCorrectedOBJ_E1Val,s800->GetCrdc(0).GetDispersiveX())){ - // dirname = Form("TOF_DispX_%s",mypid->GetName()); - // histname = Form("GretinaDoppler_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit.GetDoppler(BETA)); - - // if(gretina->Size()==1){ - // histname = Form("Singles_GretinaDoppler_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit.GetDoppler(BETA)); - // } - - - // histname = Form("GretinaDopplerVsOpenAng_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 1000,-3.15,3.15,openang, - // 2000,0,4000,hit.GetDoppler(BETA)); - - // histname = Form("GretinaDopplerVsDTA_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 1000,-0.2,0.2,s800->GetDta(), - // 2000,0,4000,hit.GetDoppler(BETA)); - - // histname = Form("QuadDoppSummary_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 10,0,10,HoleQMap[hit.GetCrystalId()/4], - // 2000,0,4000,hit.GetDoppler(BETA)); - - // for(int z2=y+1;z2Size();z2++) { - // TGretinaHit hit_2 = gretina->GetGretinaHit(z2); - - // histname = Form("Gamma_Gamma_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit.GetDoppler(BETA), - // 3000,0,6000,hit_2.GetDoppler(BETA)); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit_2.GetDoppler(BETA), - // 3000,0,6000,hit.GetDoppler(BETA)); - - // histname = Form("Gamma_Gamma_Time_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 800,-400,400,hit.GetTime()-hit_2.GetTime(), - // 3000,0,6000,hit.GetDoppler(BETA)); - // obj.FillHistogram(dirname,histname, - // 800,-400,400,hit_2.GetTime()-hit.GetTime(), - // 3000,0,6000,hit.GetDoppler(BETA)); - // } - - // }// end inside PID for Disp X - // if(mypid->IsInside(bank29->Timestamp()-hit.GetTime(),hit.GetCoreEnergy())){// Note GetTime has walk correction. - // dirname = Form("Prompt_Timing_%s",mypid->GetName()); - // histname = Form("GretinaDoppler_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit.GetDoppler(BETA)); - - // if(gretina->Size()==1){ - // histname = Form("Singles_GretinaDoppler_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit.GetDoppler(BETA)); - // } - - - // histname = Form("GretinaDopplerVsOpenAng_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 1000,-3.15,3.15,openang, - // 2000,0,4000,hit.GetDoppler(BETA)); - - // histname = Form("GretinaDopplerVsDTA_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 1000,-0.2,0.2,s800->GetDta(), - // 2000,0,4000,hit.GetDoppler(BETA)); - - // histname = Form("QuadDoppSummary_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 10,0,10,HoleQMap[hit.GetCrystalId()/4], - // 2000,0,4000,hit.GetDoppler(BETA)); - - // for(int z2=y+1;z2Size();z2++) { - // TGretinaHit hit_2 = gretina->GetGretinaHit(z2); - - // histname = Form("Gamma_Gamma_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit.GetDoppler(BETA), - // 3000,0,6000,hit_2.GetDoppler(BETA)); - // obj.FillHistogram(dirname,histname, - // 3000,0,6000,hit_2.GetDoppler(BETA), - // 3000,0,6000,hit.GetDoppler(BETA)); - - // histname = Form("Gamma_Gamma_Time_%s",mypid->GetName()); - // obj.FillHistogram(dirname,histname, - // 800,-400,400,hit.GetTime()-hit_2.GetTime(), - // 3000,0,6000,hit.GetDoppler(BETA)); - // obj.FillHistogram(dirname,histname, - // 800,-400,400,hit_2.GetTime()-hit.GetTime(), - // 3000,0,6000,hit.GetDoppler(BETA)); - // } - // } - // end insided prompt timing peak - }// end iterate over cuts. - } // end "HAS PIDS" - - dirname = "CRDC"; - histname = "CRDC1_X"; - obj.FillHistogram(dirname,histname, - 800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname, - 800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - histname = "CRDC1_Y_vs_S800Timestamp"; - obj.FillHistogram(dirname,histname, - 10000,0,4000,s800->GetTimestamp()/1e8, - 800,-400,400,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2_Y_vs_S800Timestamp"; - obj.FillHistogram(dirname,histname, - 10000,0,4000,s800->GetTimestamp()/1e8, - 800,-400,400,s800->GetCrdc(1).GetNonDispersiveY()); - }// end good correlated events. - - for(int z=0;z36) - break; - int layer = hit.GetSegmentId(z)/6; - dirname = "GretSummPos"; - histname = Form("GretinaPosition_%s",LayerMap[layer].c_str()); - double phi = hit.GetInteractionPosition(z).Phi(); - if(phi<0) phi +=TMath::Pi()*2; - obj.FillHistogram(dirname,histname, - 628,0.0,6.28,phi, - 314,0,3.14,hit.GetInteractionPosition(z).Theta()); - } - //std::cout << " In gret loop after number interactions loop" << std::endl; - dirname = "GretSummPos"; - histname = Form("GretinaPosition"); - obj.FillHistogram(dirname,histname, - 628,0,6.28,hit.GetPhi(), - 314,0,3.14,hit.GetTheta()); - - histname = Form("GretinaPosition_Quad_%i",HoleQMap[hit.GetCrystalId()/4]); - obj.FillHistogram(dirname,histname, - 628,0,6.28,hit.GetPhi(), - 314,0,3.14,hit.GetTheta()); - - histname = Form("GretinaPosition_Xtal_%i",hit.GetCrystalId()); - obj.FillHistogram(dirname,histname, - 628,0,6.28,hit.GetPhi(), - 314,0,3.14,hit.GetTheta()); - - - - - histname = "GretinaEnergyTotal"; - obj.FillHistogram(histname, - 8000,0,4000,hit.GetCoreEnergy()); - //-------------------------------------------------------------------- - dirname = "DopplerGretResDiag"; - histname = "GretinaDopplerTotal"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA)); - - double openang_Spec = hit.GetPosition().Phi()-trackvect_Spec.Phi(); - - histname = "GretinaDopplerVsOpenAng"; - obj.FillHistogram(dirname,histname, - 1000,-3.15,3.15,openang_Spec, - 2000,0,4000,hit.GetDoppler(BETA)); - - histname = "GretinaDopplerVsDTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA)); - - histname = "QuadDoppSummary"; - obj.FillHistogram(dirname,histname, - 10,0,10,HoleQMap[hit.GetCrystalId()/4], - 2000,0,4000,hit.GetDoppler(BETA)); - - histname = "GretinaDopplerBeta"; - double beta = 0.2; - for(int z=0;z<100;z++) { - beta += .3/100.0; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetCoreEnergy(beta), - 101,0.2,0.5,beta); - } - - //-------------------------------------------------------------------- - dirname = "VectCorrByXtal"; - histname = Form("Gret_VectCorr_Xtal"); - - obj.FillHistogram(dirname,histname, - 100,0,100,hit.GetCrystalId(), - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - - //-------------------------------------------------------------------- - dirname = "VectGretResDiag"; - histname = "GretinaDoppVectTotal"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - - histname = "GretinaDoppVectVsOpenAng"; - obj.FillHistogram(dirname,histname, - 1000,-3.15,3.15,openang_Spec, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - - histname = "QuadDoppVectSummary"; - obj.FillHistogram(dirname,histname, - 10,0,10,HoleQMap[hit.GetCrystalId()/4], - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - - histname = "GretinaDoppVectPosLoopZ"; - // double z_ = -5.0; - // double zdef = GValue::FindValue("GRETINA_Z_OFFSET")->GetValue(); - // for(int z=0;z<100;z++) { - // z_ += 10.0/100.0; - // GValue::FindValue("GRETINA_Z_OFFSET")->SetValue(z_); - // obj.FillHistogram(dirname,histname, - // 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec), - // 101,-5.0,5.0,z_); - // } - // GValue::FindValue("GRETINA_Z_OFFSET")->SetValue(zdef); - //-------------------------------------------------------------------- - dirname = "GretSummCoreCharge"; - histname = Form("Q%iCoreCharge",HoleQMap[hit.GetCrystalId()/4]); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+0., - 4000,0,32000,((double)hit.GetCoreCharge(0))); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+1., - 4000,0,32000,((double)hit.GetCoreCharge(1))); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+2., - 4000,0,32000,((double)hit.GetCoreCharge(2))); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+3., - 4000,0,32000,((double)hit.GetCoreCharge(3))); - }// end if(S800)!!!!!!!! - }// end of everything? -} diff --git a/histos/MakeHistos.cxx b/histos/MakeHistos.cxx deleted file mode 100644 index 132101cc..00000000 --- a/histos/MakeHistos.cxx +++ /dev/null @@ -1,622 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -//#define Q1 15 -//#define Q2 7 -//#define Q3 8 -//#define Q4 16 -//#define Q5 9 -//#define Q6 14 -//#define Q7 17 -//#define Q8 6 -//#define Q9 19 - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - TVector3 trackvect_top(0,0,1); - TVector3 trackvect_Spec(0,0,1); - - double E1_TDC_low = GValue::Value("E1_TDC_low"); - double E1_TDC_high = GValue::Value("E1_TDC_high"); - double BETA = GValue::Value("BETA"); - - TList *gates = &(obj.GetGates()); - bool haspids = gates->GetSize(); - std::string histname = ""; - std::string dirname = ""; - //std::cout << " Before Bank29" << std::endl; - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - //std::cout << " After Bank29 Before bad gretina RETURN" << std::endl; - - if(!gretina || gretina->Size()<1 || gretina->Size()>(7*4)) - return; - - //std::cout << " Passed GRET Check, Before S800-1" << std::endl; - if(s800) { - //std::cout << " Before ExitTargetVect_Spec " << std::endl; - trackvect_Spec=s800->ExitTargetVect(6); - - dirname = "S800"; - histname = "S800_DTA"; - //std::cout << " Before first DTA " << std::endl; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - histname = "S800_ATA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta()); - histname = "S800_BTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetBta()); - histname = "S800_YTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetYta()); - histname = "ATA_vs_BTA_Spec"; - obj.FillHistogram(dirname,histname, - 300,-0.2,0.2,s800->GetAta(), - 300,-0.2,0.2,s800->GetBta()); - - dirname = ""; - } - - //std::cout << " After S800-1" << std::endl; - - //if(s800) { - //std::string histname = "S800_DTA"; - //obj.FillHistogram(histname,200,-10,10,s800->GetDta()); - - //histname = "S800_YTA"; - //obj.FillHistogram(histname,200,-10,10,s800->GetYta()); - - //} - - double gsum = 0.0; - for(unsigned int y=0;ySize();y++) { - TGretinaHit hit = gretina->GetGretinaHit(y); - gsum += hit.GetCoreEnergy(); - - for(unsigned int z=y+1;zSize();z++) { - TGretinaHit hit2 = gretina->GetGretinaHit(z); - histname = "Gamma_Gamma"; - obj.FillHistogramSym(histname,2000,0,4000,hit.GetCoreEnergy(), - 2000,0,4000,hit2.GetCoreEnergy()); - histname = "Gamma_Gamma_Time"; - obj.FillHistogram(histname,800,-400,400,hit2.GetTime()-hit.GetTime(), - 2000,0,4000,hit2.GetCoreEnergy()); - obj.FillHistogram(histname,800,-400,400,hit.GetTime()-hit2.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - } - //std::cout << " After gretina hit2 loop" << std::endl; - if(bank29) { - dirname = "GretSummTime"; - histname = "Gretina_Bank29_time"; - obj.FillHistogram(dirname,histname, - 600,-600,600,bank29->Timestamp()-hit.GetTimestamp(), - 2000,0,4000,hit.GetCoreEnergy()); - histname = "Gretina_t0_Bank29_time"; - obj.FillHistogram(dirname,histname, - 600,-600,600,bank29->Timestamp()-hit.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - } - //std::cout << " In gret loop after bank29" << std::endl; - if(s800) { - TVector3 trackvect=s800->ExitTargetVect(); - TVector3 zAxis(0,0,1); - TVector3 NormResPlane = trackvect.Cross(zAxis); - TVector3 NormGammaPlane = hit.GetPosition().Cross(zAxis); - TVector3 NormDiff = NormResPlane-NormGammaPlane; - TVector3 NormCrossNorm = NormResPlane.Cross(NormGammaPlane); - double openang = NormResPlane.Angle(NormGammaPlane); - - double openang_Cos = TMath::ACos(NormResPlane.Dot(NormGammaPlane)/(NormResPlane.Mag()*NormGammaPlane.Mag())); - if(NormResPlane.Dot(NormGammaPlane)>0 && (NormResPlane.Mag()*NormGammaPlane.Mag())<0) - openang_Cos = 2.0*TMath::Pi() - openang_Cos; - if(NormResPlane.Dot(NormGammaPlane)<0 && (NormResPlane.Mag()*NormGammaPlane.Mag())<0) - openang_Cos = 2.0*TMath::Pi() - openang_Cos; - - double openang_Dirk = (2.0*TMath::Pi() - s800->Azita()) - TMath::Abs(hit.GetPosition().Phi()); - - if(openang_Dirk<0) openang_Dirk += 2.0*TMath::Pi(); - dirname = "Checking_OpenAngCalc"; - histname = "GretinaDopplerVsOpenAng_CheckCalc"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA), - 1000,0,6.3,openang); - - histname = "GretinaDopplerVsOpenAng_CalcUsingCos"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA), - 2000,-6.3,6.3,openang_Cos); - - histname = "GretinaDopplerVspenAng_Dirk"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA), - 1000,0,6.3,openang_Dirk); - - - histname = "GretinaDopplerVsOpenAng_TrackCorr_CheckCalc"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect), - 1000,0,6.3,openang); - - histname = "GretinaDopplerVsOpenAng_TrackCorr_CalcUsingCos"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect), - 2000,-6.3,6.3,openang_Cos); - - histname = "GretinaDopplerVspenAng_TrackCorr_Dirk"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect), - 1000,0,6.3,openang_Dirk); - - histname = Form("GretinaVecCorr"); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - - - histname = Form("GretinaDopplerCorr"); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA)); - - - - - - dirname = "GretSummTime"; - histname = "Gretina_S800_time"; - obj.FillHistogram(dirname,histname, - 1200,-600,600,s800->Timestamp()-hit.GetTimestamp(), - 2000,0,4000,hit.GetCoreEnergy()); - histname = "Gretina_t0_S800_time"; - obj.FillHistogram(dirname,histname, - 1200,-600,600,s800->Timestamp()-hit.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - - dirname = "PID"; - histname = "TDC_vs_DispX"; - obj.FillHistogram(dirname,histname, - 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - histname = "TDC_vs_AFP"; - obj.FillHistogram(dirname,histname, - 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - 600,-0.1,0.1,s800->GetAFP()); - - histname ="PID_TDC"; - double low = GValue::Value("PID_LOW"); - double high = GValue::Value("PID_HIGH"); - obj.FillHistogram(dirname,histname, - 1000,-1000,000,s800->GetCorrTOF_OBJ(), - 1000,low,high,s800->GetIonChamber().Charge()); - - double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - 2000,10000,60000,s800->GetIonChamber().Charge()); - } - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - if(haspids) { - dirname = "PID_GATED"; - TIter it(gates); - while(TObject *itobj = it.Next()) { - if(!itobj) - continue; - - if(!itobj->InheritsFrom(TCutG::Class())) - continue; - TCutG *mypid = (TCutG*)itobj; - if(mypid->IsInside(s800->GetCorrTOF_OBJ(),s800->GetIonChamber().Charge())) { - TVector3 trackvect=s800->ExitTargetVect(); - - histname = Form("GretinaDopplerBeta_%s",mypid->GetName()); - double _beta = 0.2; - for(int z=0;z<100;z++){ - _beta+=0.3/100.0; - obj.FillHistogram(dirname,histname, - 101,0.2,0.5,_beta, - 2000,0,4000,hit.GetDoppler(_beta)); - } - //----------------------------------------------------- - histname = Form("GretinaDoppler_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA)); - - histname = Form("GretinaDoppVsDTA_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 1000,-0.3,0.3,s800->GetDta(), - 1000,0,4000,hit.GetDoppler(BETA)); - //----------------------------------------------------- - histname = Form("GretinaVecCorr_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect)); - histname = Form("GretinaVecCorrVsDTA_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 1000,-0.3,0.3,s800->GetDta(), - 1000,0,4000,hit.GetDoppler(BETA,&trackvect)); - //----------------------------------------------------- - histname = Form("Gretina_dB_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler_dB(BETA,&trackvect,s800->GetDta())); - - histname = Form("Gretina_dB_VsDTA_%s",mypid->GetName()); - obj.FillHistogram(dirname,histname, - 1000,-0.3,0.3,s800->GetDta(), - 1000,0,4000,hit.GetDoppler_dB(BETA,&trackvect,s800->GetDta())); - } - } - } - //std::cout << " In gret loop + s800 before haspids" << std::endl; - histname = "E1_m_TDC"; - obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - histname = "E1Raw"; - obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - histname = "M_E1Raw"; - for(int z=0;zGetMTof().E1UpSize();z++) - obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - histname = "IonChamberSum"; - obj.FillHistogram(histname,4000,0,32000,s800->GetIonChamber().GetSum()); - } - //std::cout << " In gret loop after s800" << std::endl; - histname = Form("GretinaEnergyTheta"); - obj.FillHistogram(histname,4000,0,4000,hit.GetCoreEnergy(), - 314,0,3.14,hit.GetTheta()); - //if(hit.GetPad()==0) { - // histname = Form("GretinaOverview_pad0"); - // obj.FillHistogram(histname,4000,0,4000,hit.GetCoreEnergy(), - // 100,0,100,hit.GetCrystalId()); - //} - histname = Form("GretinaOverview"); - obj.FillHistogram(histname,4000,0,4000,hit.GetCoreEnergy(), - 100,0,100,hit.GetCrystalId()); - - histname = Form("GretinaSum"); - obj.FillHistogram(histname,10000,0,10000,hit.GetCoreEnergy()); - - histname = Form("GretinaDecompErrorCode"); - obj.FillHistogram(histname,150,0,150,hit.GetPad()); - - //std::cout << " In gret loop before Number of interactions loop" << std::endl; - // - //histname = Form("Q%i_detmap",HoleQMap[hit.GetCrystalId()/4]); - //obj.FillHistogram(histname,160,0,160,hit.GetCrystalId()%4+9, - // 4000,0,4000,hit.GetCoreEnergy()); - - - for(int z=0;z36) - break; - int layer = hit.GetSegmentId(z)/6; - dirname = "GretSummPos"; - histname = Form("GretinaPosition_%s",LayerMap[layer].c_str()); - double phi = hit.GetInteractionPosition(z).Phi(); - if(phi<0) phi +=TMath::Pi()*2; - if(hit.GetPad()==0) { - obj.FillHistogram(dirname,histname, - 628,0.0,6.28,phi, - 314,0,3.14,hit.GetInteractionPosition(z).Theta()); - } - } - //std::cout << " In gret loop after number interactions loop" << std::endl; - dirname = "GretSummPos"; - if(hit.GetPad()==0) { - histname = Form("GretinaPosition"); - obj.FillHistogram(dirname,histname, - 628,0,6.28,hit.GetPhi(), - 314,0,3.14,hit.GetTheta()); - } - histname = "GretinaEnergyTotal"; - obj.FillHistogram(histname, - 8000,0,4000,hit.GetCoreEnergy()); - //std::cout << "After GretEnergyTotal " << std::endl; - //-------------------------------------------------------------------- - dirname = "DopplerGretResDiag"; - histname = "GretinaDopplerTotal"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA)); - - //std::cout << " Before Opening angle calculation " << std::endl; - double openang = hit.GetPosition().Phi()-trackvect_top.Phi(); - double openang_Spec = hit.GetPosition().Phi()-trackvect_Spec.Phi(); - - histname = "GretinaDopplerVsOpenAng"; - obj.FillHistogram(histname, - 1000,-3.15,3.15,openang, - 2000,0,4000,hit.GetDoppler(BETA)); - if(s800){ - histname = "GretinaDopplerVsDTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA)); - - } - - histname = "QuadDoppSummary"; - obj.FillHistogram(dirname,histname, - 10,0,10,HoleQMap[hit.GetCrystalId()/4], - 2000,0,4000,hit.GetDoppler(BETA)); - - histname = "GretinaDopplerBeta"; - double beta = 0.00; - for(int z=0;z<100;z++) { - beta += .3/100.0; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetCoreEnergy(beta), - 101,0.2,0.5,beta); - } - //std::cout << " After Beta stuff" << std::endl; - - //-------------------------------------------------------------------- - dirname = "VectCorrByXtal"; - histname = Form("Gret_VectCorr_Xtal"); - - obj.FillHistogram(dirname,histname, - 100,0,100,hit.GetCrystalId(), - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - - //std::cout << "After vector correction by crystal" << std::endl; - //-------------------------------------------------------------------- - dirname = "VectGretResDiag"; - histname = "GretinaDoppVectTotal"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_top)); - - //std::cout << "After total (1d) plot made, before vs opening angle" << std::endl; - histname = "GretinaDoppVectVsOpenAng"; - obj.FillHistogram(dirname,histname, - 1000,-3.15,3.15,openang, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_top)); - - histname = "GretinaDoppVectTotal_Spec"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - - //std::cout << "After one done with Spec" << std::endl; - histname = "GretinaDoppVectVsOpenAng_Spec"; - obj.FillHistogram(dirname,histname, - 1000,-3.15,3.15,openang_Spec, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - - if(s800){ - //std::cout << " Before dopp vs DTA" << std::endl; - histname = "GretinaDoppVectVsDTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta(), - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - } - //std::cout << " After dopp vs DTA" << std::endl; - histname = "QuadDoppVectSummary"; - obj.FillHistogram(dirname,histname, - 10,0,10,HoleQMap[hit.GetCrystalId()/4], - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec)); - //std::cout << "Before loop over z value" << std::endl; - histname = "GretinaDoppVectPosLoopZ"; - double z_ = -5.0; - //std::cout << "Find val : " << GValue::Value("GRETINA_Z_OFFSET") << std::endl; - double zdef = GValue::Value("GRETINA_Z_OFFSET"); - //std::cout << "zdef = " << zdef << std::endl; - if(!(std::isnan(zdef))){ - //std::cout << " In isnan condition" << std::endl; - for(int z=0;z<100;z++) { - z_ += 10.0/100.0; - GValue::FindValue("GRETINA_Z_OFFSET")->SetValue(z_); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec), - 101,-5.0,5.0,z_); - } - GValue::FindValue("GRETINA_Z_OFFSET")->SetValue(zdef); - } - //std::cout << " After gretina z offset gvalue stuff" << std::endl; - - /* histname = "GretinaDoppVectPosLoopX"; - double x_ = -5.0; - double xdef = GValue::FindValue("GRETINA_X_OFFSET")->GetValue(); - for(int z=0;z<100;z++) { - x_ += 10.0/100.0; - GValue::FindValue("GRETINA_X_OFFSET")->SetValue(x_); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec), - 101,-5.0,5.0,x_); - } - GValue::FindValue("GRETINA_X_OFFSET")->SetValue(xdef); - - - histname = "GretinaDoppVectPosLoopY"; - double y_ = -5.0; - double ydef = GValue::FindValue("GRETINA_Y_OFFSET")->GetValue(); - for(int z=0;z<100;z++) { - y_ += 10.0/100.0; - GValue::FindValue("GRETINA_Y_OFFSET")->SetValue(y_); - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler(BETA,&trackvect_Spec), - 101,-5.0,5.0,y_); - } - GValue::FindValue("GRETINA_Y_OFFSET")->SetValue(ydef);*/ - //-------------------------------------------------------------------- - if(s800){ - dirname = "MomentumGretResDiag_Spec"; - histname = "GretinaDoppMomTotal"; - obj.FillHistogram(dirname,histname, - 2000,0,4000,hit.GetDoppler_dB(BETA,&trackvect_Spec,s800->GetDta())); - - histname = "GretinaDoppMomVsOpenAng"; - obj.FillHistogram(dirname,histname, - 1000,-3.15,3.15,openang_Spec, - 2000,0,4000,hit.GetDoppler_dB(BETA,&trackvect_Spec,s800->GetDta())); - - histname = "GretinaDoppMomVsDTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta(), - 2000,0,4000,hit.GetDoppler_dB(BETA,&trackvect_Spec,s800->GetDta())); - - histname = "QuadDoppMomSummary"; - obj.FillHistogram(dirname,histname, - 10,0,10,HoleQMap[hit.GetCrystalId()/4], - 2000,0,4000,hit.GetDoppler_dB(BETA,&trackvect_Spec,s800->GetDta())); - } - //std::cout << "After momentum gretina resolution diagnosis" << std::endl; - //==================================================================== - dirname = "GretSummCoreCharge"; - histname = Form("Q%iCoreCharge",HoleQMap[hit.GetCrystalId()/4]); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+0., - 4000,0,32000,((double)hit.GetCoreCharge(0))); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+1., - 4000,0,32000,((double)hit.GetCoreCharge(1))); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+2., - 4000,0,32000,((double)hit.GetCoreCharge(2))); - obj.FillHistogram(dirname,histname, - 16,0,16,4*hit.GetCrystalNumber()+3., - 4000,0,32000,((double)hit.GetCoreCharge(3))); - - //std::cout << "After gretina core charge summary" << std::endl; - /* histname = "GretinaDopplerBeta"; - double beta = 0.2; - for(int z=0;z<100;z++) { - beta += .3/100.0; - obj.FillHistogram(histname,8000,0,4000,hit.GetCoreEnergy(beta), - 101,0.2,0.5,beta); - }*/ - - histname = Form("Q%iCoreCharge",HoleQMap[hit.GetCrystalId()/4]); - //if(HoleQMap[hit.GetHoleNumber()]==0) - // printf("HoleQMap[hit.GetHoleNumber() = 0 is %i\n",hit.GetHoleNumber()); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+0., - 4000,0,32000,((double)hit.GetCoreCharge(0))); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+1., - 4000,0,32000,((double)hit.GetCoreCharge(1))); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+2., - 4000,0,32000,((double)hit.GetCoreCharge(2))); - obj.FillHistogram(histname,16,0,16,4*hit.GetCrystalNumber()+3., - 4000,0,32000,((double)hit.GetCoreCharge(3))); - - histname = "CrystalId_hitpattern"; - obj.FillHistogram(histname,100,0,100,hit.GetCrystalId()); - } - //std::cout << " After gret loop " << std::endl; - if(gsum>1.0) { - - histname = "GCalorimeter"; - obj.FillHistogram(histname,16000,0,8000,gsum); - /* NOTE -> largesthit is not set anywhere - TGretinaHit hit = gretina->GetGretinaHit(largesthit); - histname = "GCalorimeter_Theta"; - obj.FillHistogram(histname,314,0,3.14,hit.GetTheta(), - 8000,0,8000,gsum);*/ - } - //std::cout << " After Gret Calorimeter" << std::endl; - if(numobj!=list->GetSize()) - list->Sort(); - //std::cout << " end" << std::endl; -} diff --git a/histos/MakeHistosGretinaBlank.cxx b/histos/MakeHistosGretinaBlank.cxx new file mode 100644 index 00000000..cc7739ef --- /dev/null +++ b/histos/MakeHistosGretinaBlank.cxx @@ -0,0 +1,114 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" + + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 19 +#define Q10 6 +#define Q11 9 +#define Q12 20 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; + HoleQMap[Q12] = 12; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank88 *bank88 = obj.GetDetector(); + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + std::string histname = ""; + std::string dirname = ""; + + + // if(bank88) { + // for(unsigned int x=0; xSize(); x++) { + // TMode3Hit &hit = (TMode3Hit&)bank88->GetHit(x); + // std::string histname = Form("bank88_%i",hit.GetChannel()); + // obj.FillHistogram(histname,16000,0,64000,hit.Charge()); + // } + // } + + if(!gretina) + return; + + + for(unsigned int x=0; xSize(); x++) { + TGretinaHit xhit = gretina->GetGretinaHit(x); + + // 1D hitogram + // obj.FillHistogram(dirname,histname,bins,xlow,xhigh,xvalue); + for(unsigned int y=0; ySize(); y++) { + TGretinaHit yhit = gretina->GetGretinaHit(y); + + // 2D hitogram + // obj.FillHistogram(dirname,histname,xbins,xlow,xhigh,xvalue, + // ybins,ylow,yhigh,yvalue); + + } + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/histos/MakeHistosInBeam.cxx b/histos/MakeHistosInBeam.cxx deleted file mode 100644 index 476dd25d..00000000 --- a/histos/MakeHistosInBeam.cxx +++ /dev/null @@ -1,528 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TBank29.h" -#include "TS800.h" -#include "TS800Sim.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TS800Sim *s800Sim = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - Int_t energyNChannels = 8192; - Double_t energyLlim = 0.; - Double_t energyUlim = 8192.; - - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - obj.FillHistogram("sim","beta", - 500, 0, 0.5, - hit.GetBeta()); - obj.FillHistogram("sim","beta_z", - 1000,-5,5., - hit.GetZ(), - 300, 0.2, 0.5, - hit.GetBeta()); - } - } - - if(!s800Sim) - return; - - if(s800Sim->Size() > 0){ - // std::cout << "In MakeHistos:" << std::endl; - - // std::cout << " time stamp = " - // << s800Sim->Timestamp() << std::endl; - - // std::cout << " size = " - // << s800Sim->Size() - // << std::endl; - - // std::cout << std::flush; - - Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); - - // std::cout << " ATA = " - // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; - - // std::cout << " BTA = " - // << s800Sim->GetS800SimHit(0).GetBTA() << std::endl; - - // std::cout << " DTA = " - // << dta << std::endl; - - - obj.FillHistogram("s800","dta", - 200, -0.10, 0.10, - dta); - - // Rough dta acceptance cut - if(dta < -0.06 || dta > 0.06) - return; - - obj.FillHistogram("s800","dta_cut", - 200, -0.10, 0.10, - dta); - - obj.FillHistogram("s800","ata", - 200, -100, 100, - s800Sim->GetS800SimHit(0).GetATA()); - - obj.FillHistogram("s800","bta", - 200, -100, 100, - s800Sim->GetS800SimHit(0).GetBTA()); - - Double_t xsin, ysin, scatter; - - xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); - ysin = -sin(s800Sim->GetS800SimHit(0).GetBTA()/1000.); - scatter = asin(sqrt(xsin*xsin + ysin*ysin))*1000.; - - obj.FillHistogram("s800","scatter", - 4096, 0, 300, - scatter); - } - - if(!gretina) - return; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset,yoffset,zoffset); - - // (optionally define extra beta values in gvalues file) - const Int_t nBetas = 1; - Double_t betas[nBetas] = {beta}; - - Double_t calorimeterEnergy = 0.; - Double_t calorimeterEnergy_gaus = 0.; - std::vector hits; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Addback preprocessing - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += hit.GetCoreEnergy(); - calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - hits.push_back(hit); - - } - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - obj.FillHistogram("energy", "overview_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - - for(int i=0; iGaus(1,1./1000.); - for(int y=x+1; ySize(); y++){ - - TGretinaHit hit2 = gretina->GetGretinaHit(y); - Double_t e2 = hit2.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.); - - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/16, energyLlim, energyUlim/2, e1, - energyNChannels/16, energyLlim, energyUlim/2, e2); - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/8, energyLlim, energyUlim, e2, - energyNChannels/8, energyLlim, energyUlim, e1); - } - - obj.FillHistogram("energy", - Form("dop_%.0f", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])); - - obj.FillHistogram("energy", - Form("dop_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("energy", - Form("dop_fw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } else { - obj.FillHistogram("energy", - Form("dop_bw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } - } - - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("position", "theta_vs_phi_fw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } else { - obj.FillHistogram("position", "theta_vs_phi_bw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - obj.FillHistogram("addback", "calorimeter_gaus", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy_gaus); - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - Double_t addbackEnergy_gaus = 0.; - TVector3 firstHitPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - addbackEnergy_gaus += - cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - // Find the largest IP in the cluster and save its position - // for Doppler correction. - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) - > firstHitEnergy){ - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; - firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy[nBetas] = {0.}; - Double_t dopplerABEnergy_gaus[nBetas] = {0.}; - for(int b=0; bGetSize()) - list->Sort(); - -} diff --git a/histos/MakeHistosInBeamLH.cxx b/histos/MakeHistosInBeamLH.cxx deleted file mode 100644 index a51c0a2b..00000000 --- a/histos/MakeHistosInBeamLH.cxx +++ /dev/null @@ -1,536 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TBank29.h" -#include "TS800.h" -#include "TS800Sim.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -// LH-target setup: 8 Quads, Q4 @ LBNL -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TS800Sim *s800Sim = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - // These are written for every event, not just those in which - // gamma rays are detected, so catch them first. - if(gretSim){ - if(gretSim->Size() > 0){ - obj.FillHistogram("sim","beta", - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - obj.FillHistogram("sim","z", - 1000,-50,50., - gretSim->GetGretinaSimHit(0).GetZ()); - obj.FillHistogram("sim","beta_z", - 1000,-50.,50., - gretSim->GetGretinaSimHit(0).GetZ(), - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - obj.FillHistogram("sim","theta", - 180,0,180., - gretSim->GetGretinaSimHit(0).GetTheta()*TMath::RadToDeg()); - } - } - - - if(!s800Sim) - return; - - if(s800Sim->Size() > 0){ - // std::cout << "In MakeHistos:" << std::endl; - - // std::cout << " time stamp = " - // << s800Sim->Timestamp() << std::endl; - - // std::cout << " size = " - // << s800Sim->Size() - // << std::endl; - - // std::cout << std::flush; - - Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); - - // std::cout << " ATA = " - // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; - - // std::cout << " BTA = " - // << s800Sim->GetS800SimHit(0).GetBTA() << std::endl; - - // std::cout << " DTA = " - // << dta << std::endl; - - - obj.FillHistogram("s800","dta", - 200, -0.10, 0.10, - dta); - - // Rough dta acceptance cut - if(dta < -0.06 || dta > 0.06) - return; - - obj.FillHistogram("s800","dta_cut", - 200, -0.10, 0.10, - dta); - - obj.FillHistogram("s800","ata", - 200, -100, 100, - s800Sim->GetS800SimHit(0).GetATA()); - - obj.FillHistogram("s800","bta", - 200, -100, 100, - s800Sim->GetS800SimHit(0).GetBTA()); - - Double_t xsin, ysin, scatter; - - xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); - ysin = -sin(s800Sim->GetS800SimHit(0).GetBTA()/1000.); - scatter = asin(sqrt(xsin*xsin + ysin*ysin))*1000.; - - obj.FillHistogram("s800","scatter", - 4096, 0, 300, - scatter); - } - - if(!gretina) - return; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset,yoffset,zoffset); - - // (optionally define extra beta values in gvalues file) - const Int_t nBetas = 1; - Double_t betas[nBetas] = {beta}; - - Int_t energyNChannels = 8192; - Double_t energyLlim = 0.; - Double_t energyUlim = 8192.; - - Double_t calorimeterEnergy = 0.; - Double_t calorimeterEnergy_gaus = 0.; - std::vector hits; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Addback preprocessing - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += hit.GetCoreEnergy(); - calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - hits.push_back(hit); - - } - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - obj.FillHistogram("energy", "overview_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - - for(int i=0; iGaus(1,1./1000.); - for(int y=x+1; ySize(); y++){ - - TGretinaHit hit2 = gretina->GetGretinaHit(y); - Double_t e2 = hit2.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.); - - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/16, energyLlim, energyUlim/2, e1, - energyNChannels/16, energyLlim, energyUlim/2, e2); - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/8, energyLlim, energyUlim, e2, - energyNChannels/8, energyLlim, energyUlim, e1); - } - - obj.FillHistogram("energy", - Form("dop_%.0f", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])); - - obj.FillHistogram("position", - Form("dop_theta_%.0f",betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i]), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - obj.FillHistogram("energy", - Form("dop_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("energy", - Form("dop_fw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } else { - obj.FillHistogram("energy", - Form("dop_bw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } - } - - obj.FillHistogram("position", "theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("position", "theta_fw", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("position", "theta_vs_phi_fw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } else { - obj.FillHistogram("position", "theta_bw", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("position", "theta_vs_phi_bw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - obj.FillHistogram("addback", "calorimeter_gaus", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy_gaus); - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - Double_t addbackEnergy_gaus = 0.; - TVector3 firstHitPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - addbackEnergy_gaus += - cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - // Find the largest IP in the cluster and save its position - // for Doppler correction. - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) - > firstHitEnergy){ - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; - firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy[nBetas] = {0.}; - Double_t dopplerABEnergy_gaus[nBetas] = {0.}; - for(int b=0; bGetSize()) - list->Sort(); - -} diff --git a/histos/MakeHistosSources.cxx b/histos/MakeHistosSources.cxx deleted file mode 100644 index 5e0cae31..00000000 --- a/histos/MakeHistosSources.cxx +++ /dev/null @@ -1,405 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - // TBank29 *bank29 = obj.GetDetector(); - // TS800 *s800 = obj.GetDetector(); - - if(!gretina) - return; - - Int_t energyNChannels = 4000; - Double_t energyLlim = 0.; - Double_t energyUlim = 4000.; - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - // Gamma-gated crystal spectrum - Double_t eGateLlim = 1327.5; - Double_t eGateUlim = 1337.5; - int iGate = -1; - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if( hit.GetCoreEnergy() > eGateLlim && - hit.GetCoreEnergy() < eGateUlim ) - iGate = i; - } - if(iGate>=0){ - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if(i != iGate){ - obj.FillHistogram("energy", - Form("energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - obj.FillHistogram("energy", - Form("fold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, hit.NumberOfInteractions()); - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - Form("segfold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, segment_fold); - - } - } - } - - for(int x=0; xSize(); x++){ - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Addback preprocessing - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += hit.GetCoreEnergy(); - - hits.push_back(hit); - - } - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, hit.NumberOfInteractions()); - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - "segfold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, segment_fold); - - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", "energy_A", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - else - obj.FillHistogram("energy", "energy_B", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - // Position spectra in crystal coordinates - if(hit.NumberOfInteractions()){ - obj.FillHistogram("position", - Form("crys_%d_x", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X()); - - obj.FillHistogram("position", - Form("crys_%d_y", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_z", hit.GetCrystalId()), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_xy", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_xz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_yz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - } - - int max_layer = -1; - for(int y=0; y < hit.NumberOfInteractions(); y++){ - - int layer = hit.GetSegmentId(y)/6; - - if(layer > max_layer) max_layer = layer; - - obj.FillHistogram("layers", - Form("theta_vs_phi_%s", LayerMap[layer].c_str()), - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - obj.FillHistogram("layers", "max_layer", 12, -2, 10, - max_layer); - - if(max_layer == 5){ - obj.FillHistogram("energy", "energy_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - obj.FillHistogram("energy", "overview_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - } - - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("energy", - Form("energy_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", - Form("energy_A_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - else - obj.FillHistogram("energy", - Form("energy_B_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - } - - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - - // For energy-gated addback spectra - Double_t ABenergy[100]; - TString ABtype[100]; - Int_t Naddback = 0; - iGate = -1; - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1) - addbackType = "addback_n0"; - else if(neighbors == 1 && cluster.size() == 2) - addbackType = "addback_n1"; - else if(neighbors == 3 && cluster.size() == 3) - addbackType = "addback_n2"; - else - addbackType = "addback_ng"; - - // Fill addback histograms. - - obj.FillHistogram("addback", addbackType, - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - - if(addbackType == "addback_n0" - || addbackType == "addback_n1"){ - obj.FillHistogram("addback", "addback_n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - if(addbackType == "addback_n0" - || addbackType == "addback_n1" - || addbackType == "addback_n2"){ - obj.FillHistogram("addback", "addback_n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - - // For energy-gated addback spectra - if(addbackEnergy > eGateLlim && - addbackEnergy < eGateUlim) - iGate = Naddback; - - ABenergy[Naddback] = addbackEnergy; - ABtype[Naddback] = addbackType; - Naddback++; - - } - - // Fill energy-gated addback spectra - if(iGate >= 0){ - for(int i = 0; iGetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistosSourcesSim.cxx b/histos/MakeHistosSourcesSim.cxx deleted file mode 100644 index 3ecef7c0..00000000 --- a/histos/MakeHistosSourcesSim.cxx +++ /dev/null @@ -1,439 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -Double_t measuredE(Double_t energy){ - Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); - if(std::isnan(resPar1)) - resPar1 = 1.2; - Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); - if(std::isnan(resPar2)) - resPar2 = 0.0005; - - return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - Int_t energyNChannels = GValue::Value("CHANNELS"); - if(std::isnan(energyNChannels)) - energyNChannels = 10000; - - Double_t energyLlim = GValue::Value("LOWER_LIMIT"); - if(std::isnan(energyLlim)) - energyLlim = 0; - - Double_t energyUlim = GValue::Value("UPPER_LIMIT"); - if(std::isnan(energyUlim)) - energyUlim = 10000; - - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - } - } - - if(!gretina) - return; - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - // Gamma-gated crystal spectrum - Double_t eGateLlim = 1327.5; - Double_t eGateUlim = 1337.5; - int iGate = -1; - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if( hit.GetCoreEnergy() > eGateLlim && - hit.GetCoreEnergy() < eGateUlim ) - iGate = i; - } - if(iGate>=0){ - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if(i != iGate){ - Double_t mE = measuredE(hit.GetCoreEnergy()); - obj.FillHistogram("energy", - Form("energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", - Form("fold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, hit.NumberOfInteractions()); - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - Form("segfold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, segment_fold); - - } - } - } - - // Addback preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += measuredE(hit.GetCoreEnergy()); - hits.push_back(hit); - - } - } - - int max_layer = -1; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - Double_t mE = measuredE(hit.GetCoreEnergy()); - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, mE, - 200, 0, 200, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, mE); - - if(gretSim && gretSim->Size()>0 && - gretSim->GetGretinaSimHit(0).IsFEP()){ - obj.FillHistogram("energy", "photopeak", - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", "overview_photopeak", - energyNChannels, energyLlim, energyUlim, mE, - 200, 0, 200, hit.GetCrystalId()); - } - - obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, hit.NumberOfInteractions()); - - // Symmetrized gamma-gamma matrix - for(int y=x+1; ySize(); y++){ - TGretinaHit hit2 = gretina->GetGretinaHit(y); - Double_t mE2 = measuredE(hit2.GetCoreEnergy()); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE, - energyNChannels/4, energyLlim, energyUlim, mE2); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE2, - energyNChannels/4, energyLlim, energyUlim, mE); - } - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - "segfold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, segment_fold); - - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", "energy_A", - energyNChannels, energyLlim, energyUlim, mE); - else - obj.FillHistogram("energy", "energy_B", - energyNChannels, energyLlim, energyUlim, mE); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("position", "phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - // Position spectra in crystal coordinates - if(hit.NumberOfInteractions()){ - obj.FillHistogram("position", - Form("crys_%d_x", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X()); - - obj.FillHistogram("position", - Form("crys_%d_y", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_z", hit.GetCrystalId()), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_xy", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_xz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_yz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - } - - for(int y=0; y < hit.NumberOfInteractions(); y++){ - - int layer = hit.GetSegmentId(y)/6; - - // Look for a segment in the layer with > 50 keV deposited - // to avoid segment threshold issues when compared with - // measurements. (Make sure the measured spectra are sorted - // with the same constraint.) - if(layer > max_layer && hit.GetSegmentEng(y) > 50.) { - max_layer = layer; - } - - obj.FillHistogram("layers", - Form("theta_vs_phi_%s", LayerMap[layer].c_str()), - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - obj.FillHistogram("layers", "max_layer", 12, -2, 10, - max_layer); - - if(max_layer == 5){ - obj.FillHistogram("energy", "energy_involves_phi", - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", "overview_involves_phi", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - if(gretSim && gretSim->Size()>0 && - gretSim->GetGretinaSimHit(0).IsFEP()){ - obj.FillHistogram("energy", "photopeak_involves_phi", - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", "overview_photopeak_involves_phi", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - } - } - - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("energy", - Form("energy_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", - Form("energy_A_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - else - obj.FillHistogram("energy", - Form("energy_B_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - } - - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("addback", - Form("calorimeter_below_%s", - LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - } - } - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1) - addbackType = "addback_n0"; - else if(neighbors == 1 && cluster.size() == 2) - addbackType = "addback_n1"; - else if(neighbors == 3 && cluster.size() == 3) - addbackType = "addback_n2"; - else - addbackType = "addback_ng"; - - // Fill addback histograms. - - obj.FillHistogram("addback", addbackType, - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - - if(addbackType == "addback_n0" - || addbackType == "addback_n1"){ - obj.FillHistogram("addback", "addback_n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - if(addbackType == "addback_n0" - || addbackType == "addback_n1" - || addbackType == "addback_n2"){ - obj.FillHistogram("addback", "addback_n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - - } - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistos_Crdcs.cxx b/histos/MakeHistos_Crdcs.cxx new file mode 100644 index 00000000..1ceddccd --- /dev/null +++ b/histos/MakeHistos_Crdcs.cxx @@ -0,0 +1,492 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TOBJ.h" +#include "TFastScint.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" +#include "TChain.h" + +std::vector incoming_cuts ; +std::vector outgoing_cuts ; +std::vector tofcuts ; +std::vector pidcuts; +std::vector tmppidcuts; +int gates_loaded=0; + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 9 +#define Q10 6 +#define Q11 19 +//#define Q12 20 + +#define BETA .36 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + +void CheckDAQCorrelation(TRuntimeObjects& obj){ + + TGretina *gretina = obj.GetDetector(); + TBank88 *bank88 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + + std::string dirname = "DAQ_Correlation"; + + // Check tdiff between different DAQsys + if(bank88&&s800){ + obj.FillHistogram(dirname,"tdiff_bank88_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-bank88->GetTimestamp()); + } + if(bank88&&gretina){ + obj.FillHistogram(dirname,"tdiff_bank88_gretina",3600,0,7200,bank88->GetTimestamp(),1000,-2000,2000,gretina->GetGretinaHit(0).Timestamp()-bank88->GetTimestamp()); + } + if(obj_sci&&s800){ + obj.FillHistogram(dirname,"tdiff_ddas_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-obj_sci->GetOBJHit(0).GetExternalTimestamp()*8); + } + if(s800&&gretina){ + obj.FillHistogram(dirname,"tdiff_s800_gretina",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-gretina->GetGretinaHit(0).Timestamp()); + } + if(obj_sci&&gretina){ + obj.FillHistogram(dirname,"tdiff_gretina_ddas",3600,0,7200,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8/1e8,1000,-2000,2000,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8-gretina->GetGretinaHit(0).Timestamp()); + } + + // Check tdiff between differnent DAQ sys with different triggers + if(s800 && s800->GetTrigger().GetRegistr() <100 && s800->GetTrigger().GetRegistr()>0){ + TString dirname = Form("DAQ_Correlation_trigger_%d",s800->GetTrigger().GetRegistr()); + if(bank88&&s800){ + obj.FillHistogram(dirname,"tdiff_bank88_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-bank88->GetTimestamp()); + } + if(bank88&&gretina){ + obj.FillHistogram(dirname,"tdiff_bank88_gretina",3600,0,7200,bank88->GetTimestamp(),1000,-2000,2000,gretina->GetGretinaHit(0).Timestamp()-bank88->GetTimestamp()); + } + if(obj_sci&&s800){ + obj.FillHistogram(dirname,"tdiff_ddas_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-obj_sci->GetOBJHit(0).GetExternalTimestamp()*8); + } + if(s800&&gretina){ + obj.FillHistogram(dirname,"tdiff_s800_gretina",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-gretina->GetGretinaHit(0).Timestamp()); + } + if(obj_sci&&gretina){ + obj.FillHistogram(dirname,"tdiff_gretina_ddas",3600,0,7200,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8/1e8,1000,-2000,2000,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8-gretina->GetGretinaHit(0).Timestamp()); + } + } +} + + + +/* + +------------------------------ +GRETINA +------------------------------ + +*/ + + +void MonitorOBJScintillator_DDAS(TRuntimeObjects &obj){ + TOBJ *obj_sci = obj.GetDetector(); + if(obj_sci){ + std::string dirname = "OBJSci"; + for(size_t x = 0; xSize();x++){ + auto objhit = obj_sci->GetOBJHit(x); + obj.FillHistogram(dirname,"Energy_of_OBJSci",1000,0,40000,objhit.GetEnergy()); + if(objhit.GetPileup()){ + obj.FillHistogram(dirname,"Energy_of_OBJSci_Pileup",1000,0,40000,objhit.GetEnergy()); + }else{ + obj.FillHistogram(dirname,"Energy_of_OBJSci_noPileup",1000,0,40000,objhit.GetEnergy()); + } + + } + } + +} + +void MonitorCrdcs(TRuntimeObjects& obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "CRDC_Det"; + auto crdc1 = s800->GetCrdc(0); + auto crdc2 = s800->GetCrdc(1); + Double_t crdc1_x = crdc1.GetDispersiveX(); + Double_t crdc1_y = crdc1.GetNonDispersiveY(); + Double_t crdc2_x = crdc2.GetDispersiveX(); + Double_t crdc2_y = crdc2.GetNonDispersiveY(); + + obj.FillHistogram(dirname,"Crdc1_xy",800,-0,0,crdc1_x,800,-0,0,crdc1_y); + obj.FillHistogram(dirname,"Crdc2_xy",800,-0,0,crdc2_x,800,-0,0,crdc2_y); + + + if(s800 && s800->GetTrigger().GetRegistr() <100 && s800->GetTrigger().GetRegistr()>0){ + TString histname = Form("crdc1_anode_time_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),500,-2000,5000,crdc1.GetAnode(),500,-2000,5000,crdc1.GetTime()); + histname = Form("crdc2_anode_time_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),500,-2000,5000,crdc2.GetAnode(),500,-2000,5000,crdc2.GetTime()); + histname = Form("crdc1_xy_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),800,-400,400,crdc1_x,800,-400,400,crdc1_y); + histname = Form("crdc2_xy_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),800,-400,400,crdc2_x,800,-400,400,crdc2_y); + } + +} + + +void MonitorICs(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "ION_Chamber"; + auto ic = s800->GetIonChamber(); + for(int x = 0; xGetCrdc(0); + obj.FillHistogram(dirname,"ICEnergy_crdc1x",800,-400,400,crdc1.GetDispersiveX(),1000,0,4000,ic.GetSum()); + obj.FillHistogram(dirname,"ICAVEnergy_crdc1x",800,-400,400,crdc1.GetDispersiveX(),1000,0,4000,ic.GetAve()); + obj.FillHistogram(dirname,"ICEnergy_crdc1y",800,-400,400,crdc1.GetNonDispersiveY(),1000,0,4000,ic.GetSum()); + obj.FillHistogram(dirname,"ICAVEnergy_crdc1y",800,-400,400,crdc1.GetNonDispersiveY(),1000,0,4000,ic.GetAve()); + obj.FillHistogram(dirname,"ICAVEnergy_ts",3600,0,7200,s800->Timestamp()/1e8,1000,0,4000,ic.GetAve()); +} + +void OutgoingPID(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "OUT_PID"; + auto ic = s800->GetIonChamber(); + auto crdc1 = s800->GetCrdc(0); + obj.FillHistogram(dirname,"TOF-dE",2000,-2000,0,s800->GetCorrTOF_OBJ_MESY(0),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + obj.FillHistogram(dirname,"dE-Crdc1x",800,-400,400,crdc1.GetDispersiveX(),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + + /* + auto obj_sci = obj.GetDetector(); + if(!obj_sci) return; + if(tmppidcuts.at(0)->IsInside(s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),obj_sci->GetOBJHit(0).GetEnergy())){ + obj.FillHistogram(dirname,"TOF-dE-gated-by-sci",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + } + */ +} + +void IncomingPID(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + if(!s800 || !obj_sci) return; + + std::string dirname = "INC_PID"; + TString histname; + for(size_t x = 0; xSize();x++) + obj.FillHistogram(dirname,"TOF-dE-Sci",4000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),10000,0,40000,obj_sci->GetOBJHit(x).GetEnergy()); + obj.FillHistogram(dirname,"TOF-dE-PIN",4000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),1000,0,4000,s800->GetPinE()); + + obj.FillHistogram(dirname,"TOF-dE-Sci-raw",5000,-10000,0,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + histname = Form("TOF-dE-Sci-raw_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),5000,-10000,0,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + obj.FillHistogram(dirname,"TOF-Obj-Rf-dE-Sci-raw",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetMRf(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + obj.FillHistogram(dirname,"TOF-xfp-Rf-dE-Sci-raw",4000,-10000,10000,s800->GetRawXF_MESY(0)-s800->GetMRf(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); +// obj.FillHistogram(dirname,"TOF-dE-PIN-raw",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); +/* + if(tmppidcuts.at(0)->IsInside(s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),obj_sci->GetOBJHit(0).GetEnergy())){ + obj.FillHistogram(dirname,"TOF-dE-PIN-raw-gated",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); + } +*/ +} + +void MonitorTOF(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "TOF_Packet"; + auto tof = s800->GetTof(); + obj.FillHistogram(dirname,"OBJ_TAC",4000,-2000,2000,s800->GetOBJRaw_TAC()); + obj.FillHistogram(dirname,"XFP_TAC",4000,-2000,2000,s800->GetXFRaw_TAC()); + obj.FillHistogram(dirname,"OBJ-XFP",4000,-2000,2000,s800->GetXFRaw_TAC()-s800->GetOBJRaw_TAC()); + obj.FillHistogram(dirname,"OBJ_vs_XFP",1000,-2000,2000,tof.GetTacOBJ(),1000,-2000,2000,tof.GetTacXFP()); + + auto mtof = s800->GetMTof(); + for(int x = 0; x < mtof.XfpSize(); x++) + for(int y = 0; y < mtof.E1UpSize();y++){ + obj.FillHistogram(dirname,"XFP-E1_Mesy",1000,-10000,10000,s800->GetRawXF_MESY(x)-s800->GetRawE1_MESY(y)); + obj.FillHistogram(dirname,"XFP-E1_Mesy_vs_AFP",3000,-4000,8000,s800->GetCorrTOF_XFP_MESY(x*y+y),1000,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"XFP-E1_Mesy_vs_XFP",3000,-4000,8000,s800->GetCorrTOF_XFP_MESY(x*y+y),1000,-400,400,s800->GetXFP()); + } + + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.E1UpSize();y++){ + obj.FillHistogram(dirname,"OBJ-E1_Mesy",1000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawE1_MESY(y)); + obj.FillHistogram(dirname,"OBJ-E1_Mesy_vs_AFP",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(x*y+y),1000,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"OBJ-E1_Mesy_vs_XFP",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(x*y+y),1000,-400,400,s800->GetXFP()); + } + + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.XfpSize();y++){ + obj.FillHistogram(dirname,"XFP-OBJ_Mesy",1000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y)); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_AFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),100,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_BFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),100,-0.1,0.1,s800->GetBFP()); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_XFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),1000,-400,400,s800->GetXFP()); + } + obj.FillHistogram(dirname,"XFP_multi_1d",100,0,100,mtof.XfpSize()); + obj.FillHistogram(dirname,"OBJ_multi_1d",100,0,100,mtof.ObjSize()); + obj.FillHistogram(dirname,"E1Up_multi_1d",100,0,100,mtof.E1UpSize()); + obj.FillHistogram(dirname,"XFP_OBJ_multi_2d",50,0,50,mtof.XfpSize(),50,0,50,mtof.ObjSize()); + obj.FillHistogram(dirname,"XFP_E1Up_multi_2d",50,0,50,mtof.XfpSize(),50,0,50,mtof.E1UpSize()); + for(int x = 0; x < mtof.XfpSize(); x++){ + obj.FillHistogram(dirname,"XFP_Mesy_1d",1000,0,100000,s800->GetRawXF_MESY(x)); + } + + for(int x = 0; x < mtof.ObjSize(); x++){ + obj.FillHistogram(dirname,"OBJ_Mesy_1d",1000,0,100000,s800->GetRawOBJ_MESY(x)); + } + for(int x = 0; x < mtof.E1UpSize(); x++){ + obj.FillHistogram(dirname,"E1_Mesy_1d",1000,-0,100000,s800->GetRawE1_MESY(x)); + } + + obj.FillHistogram(dirname,"XFP_vs_OBJ_MESY",2000,27000,31000,mtof.GetCorrelatedObj(),2000,28000,36000,mtof.GetCorrelatedXfp()); + + + if(s800 && s800->GetTrigger().GetRegistr() <100 && s800->GetTrigger().GetRegistr()>0){ + TString histname = Form("XFP_%d",s800->GetTrigger().GetRegistr()); + for(int x = 0; x < mtof.XfpSize(); x++) + obj.FillHistogram(dirname,histname.Data(),1000,-10000,40000,s800->GetRawXF_MESY(x)); + histname = Form("OBJ_%d",s800->GetTrigger().GetRegistr()); + for(int x = 0; x < mtof.ObjSize(); x++) + obj.FillHistogram(dirname,histname.Data(),1000,-10000,40000,s800->GetRawOBJ_MESY(x)); + histname = Form("E1_%d",s800->GetTrigger().GetRegistr()); + for(int x = 0; x < mtof.E1UpSize(); x++) + obj.FillHistogram(dirname,histname.Data(),1000,-10000,40000,s800->GetRawE1_MESY(x)); + histname = Form("XFP-OBJ_%d",s800->GetTrigger().GetRegistr()); + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.XfpSize();y++){ + obj.FillHistogram(dirname,histname.Data(),5000,-8000,-3000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y)); + } + histname = Form("XFP-OBJ-TAC_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),40000,-2000,2000,s800->GetXFRaw_TAC()-s800->GetOBJRaw_TAC()); + } +} + +void CountOBJ(TRuntimeObjects &obj){ + if(pidcuts.size()==0) return; + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + if(!s800) return; + auto ic = s800->GetIonChamber(); + auto crdc1 = s800->GetCrdc(0); + double tof = s800->GetCorrTOF_OBJ_MESY(0); + double dE = ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY()); + std::string dirname="Count_OBJ"; + for(size_t x = 0; xIsInside(tof,dE)){ + histname = Form("tof-dE_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,3000,-4000,8000,tof,4000,0,4000,dE); + } + } + if(!obj_sci) return; + auto mtof = s800->GetMTof(); + if(tofcuts.size()==1 && !(tofcuts.at(0)->IsInside(mtof.GetCorrelatedObj(),mtof.GetCorrelatedXfp()))) return; + + obj.FillHistogram(dirname,"tof-dE",3000,-4000,8000,tof,4000,0,4000,dE); + + std::string dirname2="Check_Mdis"; + for(size_t x = 0; xIsInside(tof,dE)){ + histname = Form("CRDC1_x_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname2,histname,800,-400,400,crdc1.GetDispersiveX()); + dirname2 = "INC_PID"; + histname = Form("TOF_dE_Sci_Raw_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); +// histname = Form("TOF_dE_Pin_Raw_%s",pidcuts.at(x)->GetName()); +// obj.FillHistogram(dirname,histname,4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); + } + + } + if(!obj_sci) return; + for(size_t y = 0; y < pidcuts.size(); y++){ + + std::string histname; + if(pidcuts.at(y)->IsInside(tof,dE)){ + histname = Form("Energy_of_OBJSci_%s",pidcuts.at(y)->GetName()); + for(size_t x = 0; xSize();x++){ + double tdiff = s800->GetTimestamp()-obj_sci->GetOBJHit(x).GetExternalTimestamp()*8; + if(tdiff>20&&tdiff<60) + obj.FillHistogram(dirname,histname,1000,0,40000,obj_sci->GetOBJHit(x).GetEnergy()); + } + } + } + +} + +void MonitorPin(TRuntimeObjects &obj){ + + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "PIN"; + obj.FillHistogram(dirname,"Pin_energy",4000,0,4000,s800->GetPinE()); +} + +void LoadGates(TRuntimeObjects &obj){ + TList *gates = &(obj.GetGates()); + if(!gates||gates->GetSize()==0) return; + + if(gates_loaded!=gates->GetSize()){ + TIter iter(gates); + while(TObject *obj = iter.Next()){ + GCutG *gate = (GCutG*)obj; + std::string tag = gate->GetTag(); + std::cout<<"tag : "<(); + if(s800) + obj.FillHistogram("triggers",20,0,20,s800->GetTrigger().GetRegistr()); +} + +void MonitorGretina(TRuntimeObjects &obj){ + TGretina *gretina = obj.GetDetector(); + if(!gretina) return; + + std::string dirname = "Gretina_Raw"; + + for(size_t x = 0 ; x < gretina->Size(); x++){ + auto ghit = gretina->GetGretinaHit(x); + int quad = HoleQMap[ghit.GetHoleNumber()]; + int pos = (ghit.GetCrystalId()%4) + 1; + obj.FillHistogram(dirname,"xtal_pad",130,0,130,ghit.GetPad(),44,0,44,quad*4+pos-5); + if(!ghit.GetPad()){ + obj.FillHistogram(dirname,"theta_phi",180,0,TMath::Pi(),ghit.GetTheta(),180,0,2*TMath::Pi(),ghit.GetPhi()); + obj.FillHistogram(dirname,"xtal_energy",4000,0,4000,ghit.GetCoreEnergy(),44,0,44,quad*4+pos-5); + } + + } +} + +void GammaRayTag(TRuntimeObjects &obj){ + if(pidcuts.size()<=0) return; + + auto s800 = obj.GetDetector(); + auto gretina = obj.GetDetector(); + + if(!s800 || !gretina) return; + + auto ic = s800->GetIonChamber(); + auto crdc1 = s800->GetCrdc(0); + double tof = s800->GetCorrTOF_OBJ_MESY(0); + double dE = ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY()); + + std::string dirname = "GammaRayTag"; + + for(size_t x = 0 ; xIsInside(tof,dE)){ + for(size_t y = 0; y < gretina->Size(); y++){ + double tdiff = s800->Timestamp()-gretina->GetGretinaHit(y).Timestamp(); + if(tdiff<50 || tdiff>150) continue; + obj.FillHistogram(dirname,gate->GetName(),4000,0,4000,gretina->GetGretinaHit(y).GetDoppler(0.38)); + obj.FillHistogram(dirname,Form("energy_vs_theta_%s",gate->GetName()),180,0,TMath::Pi(),gretina->GetGretinaHit(y).GetTheta(),4000,0,4000,gretina->GetGretinaHit(y).GetDoppler(0.38)); + } + } + } +} + +//////////////////////////// +/* + +--------------------------------------- +Histograms are made. Gates are loaded. +--------------------------------------- + +*/ +//////////////////////////// + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + + + InitMap(); + +// LoadGates(obj); +// CheckDAQCorrelation(obj); + + // Quite important for online monitoring +// MonitorOBJScintillator_DDAS(obj); + MonitorCrdcs(obj); +// MonitorICs(obj); +// MonitorTOF(obj); +// MonitorPin(obj); +// MonitorGretina(obj); + +// OutgoingPID(obj); +// IncomingPID(obj); +// CountOBJ(obj); +// DrawTrigReg(obj); +// +// GammaRayTag(obj); + + return; + + +///////////////////////// + +} diff --git a/histos/MakeHistos_DDAS.cxx b/histos/MakeHistos_DDAS.cxx new file mode 100644 index 00000000..4ce645f2 --- /dev/null +++ b/histos/MakeHistos_DDAS.cxx @@ -0,0 +1,433 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TFastScint.h" +#include "TOBJ.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" + + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 19 +#define Q10 6 +#define Q11 9 +//#define Q12 20 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank88 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TOBJ *objs = obj.GetDetector(); + + + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + std::string histname = ""; + std::string dirname = ""; + + if(objs){ + static long long first_ts = 0; + static int total_events = 0; + for(size_t i = 0; i< objs->Size(); i++){ + TOBJHit ohit = objs->GetOBJHit(i); + obj.FillHistogram("ddas_dir","ddas_energy",1000,0,50000,ohit.GetEnergy()); +// long long tdiff = objs->Timestamp()-first_ts; + long long tdiff = ohit.Timestamp()-first_ts; + obj.FillHistogram("ddas_dir","ddas_tdiff",1000000,-1000,6000000,tdiff); + total_events++; + obj.FillHistogram("ddas_dir","total_events_vs_ts",360,0,360,ohit.Timestamp()/1e8,1000,0,1e7,total_events); + if(tdiff>=6000000) std::cout<<"tdiff: "<size()>0){ + std::vector *tr = ohit.GetTrace(); + for(size_t j = 0; jsize();j++){ + obj.FillHistogram("ddas_dir","trace",1000,0,1000,j,1000,-10000 ,40000,tr->at(j)); + } + } + } + } + + return; + + if(s800) { + obj.FillHistogram("E1Up_Singles",2000,0,2000,s800->GetScint().GetEUp()) ; + + } + + + + if(bank29) { + for(unsigned int x=0; xSize(); x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + std::string histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(histname,16000,0,64000,hit.Charge()); + } + if(s800) { + std::string histname = "S800_Bank88_timestamp_difference"; + obj.FillHistogram(histname,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_timestamp_difference_vs_bank29time"; + obj.FillHistogram(histname,7200,0,7200,bank29->Timestamp()*1e-8,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_timestamp_difference_vs_s800time"; + obj.FillHistogram(histname,7200,0,7200,s800->Timestamp()*1e-8,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + //obj.FillHistogram("E1_Down",1000,0,4000),s800-> GetScint().GetEDown()) ; + } + } + if(!gretina) + return; + + if(gretina) { + + // gretina->CleanHits(); + //double sumsegener = 0 ; + for(unsigned int i=0; iSize(); i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + //hit.Print(); + //hit.TrimSegments(0); + //hit.Print(); + + int hole = HoleQMap[hit.GetHoleNumber()]; + obj.FillHistogram("summary",10000,0,10000,hit.GetCoreEnergy(), + 200,0,200,hit.GetCrystalId()); + obj.FillHistogram(Form("quad%02i",hit.GetCrystalId()),10000,0,10000,hit.GetCoreEnergy()); + + int quad = HoleQMap[hit.GetHoleNumber()]; + int p = (hit.GetCrystalId() % 4) +1; + + obj.FillHistogram(Form("q%02i_p%i",quad,p),10000,0,10000,hit.GetCoreEnergy()); + + obj.FillHistogram("sum",10000,0,10000,hit.GetCoreEnergy()); + + histname="position"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + + dirname = "GretSummCoreCharge"; + histname = Form("Q%iCoreCharge",HoleQMap[hit.GetCrystalId()/4]); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+0., + 64000,0,64000,((double)hit.GetCoreCharge(0))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+1., + 64000,0,64000,((double)hit.GetCoreCharge(1))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+2., + 64000,0,64000,((double)hit.GetCoreCharge(2))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+3., + 64000,0,64000,((double)hit.GetCoreCharge(3))); + + + +//double previous = 0 ; + +//hit.TrimSegments(0); + for(int z=0; z500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + } + } + +//outside of loop +//histname = Form("GretinaSummaryX%02i",hit.GetCrystalId()); +//dirname = "Summary_Segments_outside_loop"; +// obj.FillHistogram(dirname,histname,40,0,40,hit.GetSegmentId(), +//2000,0,4000,hit.GetSegmentEng(isegid)); + +//histname = Form("Gretina_SegIDenergy_X%02i",hit.GetCrystalId()); +// obj.FillHistogram(dirname,histname,2000,0,4000,sumsegener); + + +// for(unsigned int k=i+1;kSize();k++) { +//TGretinaHit hit2 = gretina->GetGretinaHit(z); +//histname = Form("Segment_Correlations_X%02i",hit.GetCrystalId()); +// obj.FillHistogram(histname,40,0,40,hit.GetSegmentId(z), +// 40,0,40,hit2.GetSegmentId(z));} + + + //double segone = hit.GetSegmentEng(z) ; +// double totalseg = totalseg+segone ; + +//histname = Form("GretinaSummaryX%02i_summed",hit.GetCrystalId()); + // obj.FillHistogram(histname,2000,0,4000,totalseg); + + + + if(hit.GetPad()==0) { + histname="position_good_Decomp"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + + + histname="position_good_Decomp_with_CC_gate_bt_1000keV"; + if(hit.GetCoreEnergy()>1000) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + histname="position_good_Decomp_with_CC_gate_bt_500keV"; + if(hit.GetCoreEnergy()>500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + histname="position_good_Decomp_with_CC_gate_lt_500keV"; + if(hit.GetCoreEnergy()<500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + } + + + + // histname="Id_hole"; + // obj.FillHistogram(histname,100,0,100,hit.GetCrystalId(), + // 20,0,20,hole);} + + //histname="Theta_id"; + //obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + //200,0,200,hit.GetCrystalId()); + + //histname="phi_id"; + //obj.FillHistogram(histname,360,0,360,hit.GetPhiDeg(), + //200,0,200,hit.GetCrystalId()); + + + if(hole!=0) { + dirname = Form("Det%i",hole); + histname = Form("Gretina_X_Y_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,720,-360,360,hit.GetX(), + 720,-360,360,hit.GetY()); + + histname = Form("Gretina_X_Y_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,720,-360,360,hit.GetX(), + 720,-360,360,hit.GetY()); + +//if(bank29){ +//histname = Form("Gretina_EnergyTime_Cry%02i_Det%02i",hit.GetCrystalId(),hole); +//obj.FillHistogram(dirname,histname,7200,0,7200,bank29->Timestamp()*1e-8, +// 10000,0,10000,hit.GetCoreEnergy());} + + for(int j=0; j<4; j++) { + histname = Form("Cores_charge_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(dirname,histname,4,0,4,j,16000,0,64000,hit.GetCoreCharge(j)); + } + + +// Baseline not implemented yet + /* + for(int j=0;j<4;j++){ + histname = Form("Gretina_Baseline_Det%02i_Digi%i",hole,j); + obj.FillHistogram(dirname,histname,32000,0,32000,hit.GetCoreCharge(j), + 32000,0,32000,hit.GetBaseline());} + */ + + +// histname = Form("Gretina_CoreEnergy_CryNum%02i_Det%02i",hit.GetCrystalNumber(),hole); +// obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetCoreEnergy()); + +//histname = Form("Gretina_CoreEnergy_CryNum%02i_Hole%02i",hit.GetCrystalNumber(),hit.GetHoleNumber()); + // obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetCoreEnergy()); + +//histname = Form("Gretina_Theta_Id_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + // obj.FillHistogram(dirname,histname,360,0,360,hit.GetThetaDeg(), + // 200,0,200,hit.GetCrystalId()); + +//histname = Form("Gretina_Phi_Id_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + // obj.FillHistogram(dirname,histname,360,0,360,hit.GetPhiDeg(), + // 200,0,200,hit.GetCrystalId()); + + histname = Form("Gretina_GetPad_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,360,-1,141,hit.GetPad()); + + histname = Form("Gretina_Position_Det%02i",hole); + obj.FillHistogram(dirname,histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + + + //double radius=((hit.GetX())^2+(hit.GetY())^2)^0.5 ; + + // histname="z-r"; + // obj.FillHistogram(histname,360,0,360,hit.GetZ(), + // 360,0,360,radius); + + if(bank29) { + histname = "Gretina_Bank88_timediff_energy"; + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + histname = "Gretina_Bank88_timediff_vs_bank29time"; + obj.FillHistogram(histname,7200,0,7200,bank29->Timestamp()*1e-8,700,-400,1000,bank29->Timestamp()-hit.GetTime()); + + + histname = "Bank29_Charge"; + obj.FillHistogram(histname,2000,-10000,10000,bank29->GetCharge()); + + + } + + if(s800) { + + if(s800->GetScint().GetEUp()>1560 && s800->GetScint().GetEUp()<1750) { + + histname = "Gretina_S800_coincidence_gateon_1332keV"; + obj.FillHistogram(histname,2000,0,4000,hit.GetCoreEnergy()); + } + + histname = "Gretina_S800_time"; + obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + // obj.FillHistogram("E1_Down_coincidence_with_Gretina",2000,0,2000,s800->GetScint().GetEDown()); + obj.FillHistogram("E1_Up_coincidence_with_Gretina",2000,0,2000,s800->GetScint().GetEUp()); + //histname = "Gretina_t0_S800_time"; + //obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetT0(), + //2000,0,4000,hit.GetCoreEnergy()); + + } + + if(s800 && bank29) { + std::string histname = "GretinaEnergy_Bank88-S800_timestamp_difference"; + obj.FillHistogram(histname,400,-400,400,bank29->Timestamp()-s800->Timestamp(), 2000,0,4000,hit.GetCoreEnergy()); + } + + } + } + + + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistos_Gretina.cxx b/histos/MakeHistos_Gretina.cxx new file mode 100644 index 00000000..c082c9e1 --- /dev/null +++ b/histos/MakeHistos_Gretina.cxx @@ -0,0 +1,1245 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TOBJ.h" +#include "TFastScint.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" +#include "TChain.h" + +std::vector incoming_cuts ; +std::vector outgoing_cuts ; +std::vector tofcuts ; +std::vector pidcuts; +std::vector tmppidcuts; +int gates_loaded=0; + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 9 +#define Q10 6 +#define Q11 19 +//#define Q12 20 + +#define BETA .36 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + +/* + +------------------------------ +INCOMING (to be done if XFP used) +------------------------------ + +*/ + + +bool IncomingBeam(TRuntimeObjects& obj,GCutG *outgoing) { + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge())) + return false; + } + + std::string dirname; + if(outgoing) + dirname = Form("incoming_%s",outgoing->GetName()); + else + dirname = "incoming"; + + std::string histname; + //TMTof &mtof = s800->GetMTof(); + unsigned int reg = s800->GetReg(); + + histname = "OBJ_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()); + histname = "XFP_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacXFP()); + + histname = "OBJ_TAC-XFP_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + + histname = "OBJ_TAC_XFP_TAC_2D"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJTAC(),4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); + + histname = "Obj-Xfp_Mesytech"; + obj.FillHistogram(dirname,histname,10000,-10000,0,s800->GetMTof().GetCorrelatedObj()-s800->GetMTof().GetCorrelatedXfp()); + + histname = "Obj_Xfp_Mesytech_2D"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedObjE1(),8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + if(reg&1){ + histname = "OBJ_TAC-XFP_TAC_Reg1"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + + histname = "Obj-Xfp_Mesytech_Reg1"; + obj.FillHistogram(dirname,histname,10000,-10000,0,s800->GetMTof().GetCorrelatedObj()-s800->GetMTof().GetCorrelatedXfp()); + + histname = "Obj_Xfp_Mesytech_2D_Reg1"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedObjE1(),8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + + } + + + if(reg&2){ + histname = "OBJ_TAC-XFP_TAC_Reg2"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + + histname = "Obj-Xfp_Mesytech_Reg2"; + obj.FillHistogram(dirname,histname,10000,-10000,0,s800->GetMTof().GetCorrelatedObj()-s800->GetMTof().GetCorrelatedXfp()); + + histname = "Obj_Xfp_Mesytech_2D_Reg2"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedObjE1(),8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + } + +/* + histname = "Obj_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTOF_ObjE1()); + histname = "Obj_Rf"; + obj.FillHistogram(dirname,histname,8000,-3200,32000,s800->GetMTOF_ObjRf()); + histname = "Xfp_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTOF_XfpE1()); + histname = "Rf_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,64000,s800->GetMTOF_RfE1()); + + histname = "obj_rf_2d"; + obj.FillHistogram(dirname,histname,1600,-8000,0,s800->GetMTOF_ObjE1(), + 1600,-24000,-16000,s800->GetMTOF_RfE1()); +*/ + + //histname = "obj_xfp_2d"; + //obj.FillHistogram(dirname,histname,800,0,64000,s800->GetMTOF_ObjE1(), + // 800,0,64000,s800->GetMTOF_XfpE1()); + + //histname = "trigger_bit"; + //unsigned short bits = s800->GetTrigger().GetRegistr(); + //for(int j=0;j<16;j++) { + // if(((bits>>j)&0x0001)) + // obj.FillHistogram(dirname,histname,20,0,20,j); + // } + histname = "trigger_raw"; + obj.FillHistogram(dirname,histname,20,0,20,s800->GetTrigger().GetRegistr()); + + return true; +} + +/* + +------------------------------ +OUTGOING +------------------------------ + +*/ + +bool OutgoingBeam(TRuntimeObjects& obj,GCutG *incoming) { + TS800 *s800 = obj.GetDetector(); + + double objtime1 = s800->GetTof().GetOBJ(); + double xfptime1 = s800->GetTof().GetXFP(); +// double afp = s800->GetAFP(); +// double bfp = s800->GetBFP(); + // double ic_sum = s800->GetIonChamber().GetAve(); + //double yfp1 = s800->GetYFP(0) ; + //double ic_sum = s800->GetIonChamber().GetAve(); + +// double obj_corr = s800->GetCorrTOF_OBJ(); +// double ic_sum = s800->GetIonChamber().GetAve(); + + if(!s800) + return false; + + std::string dirname; + if(incoming) + dirname = Form("outgoing_%s",incoming->GetName()); + else + dirname = "outgoing"; + +// if(incoming) { +// if(!incoming->IsInside(s800->GetMTOF_ObjE1(),s800->GetMTOF_RfE1())) +// return false; +// } + + + std::string histname; + std::string histname2; + TIonChamber ion = s800->GetIonChamber(); + histname = "ion_summary"; + histname2 = "ion_summary2"; + for(int i=0;iGetEventCounter()); + +// histname = "Event_Counter_vs_Timestamp"; +// obj.FillHistogram(dirname,histname,7200,0,7200,s800->GetTimestamp()*1e-8,1e+7,0,1e+7,s800->GetEventCounter()); + + +// histname = "AFP_vs_BFP"; +// obj.FillHistogram(dirname,histname, +// 1000,-500,500,afp, +// 1000,-500,500,bfp); + + histname = "AFP_vs_BFP"; + obj.FillHistogram(dirname,histname,2000,-10,10,s800->GetAFP(),2000,-10,10,s800->GetBFP()); + + + histname = "IC_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 1000,0,2000,s800->GetCorrTOF_OBJTAC(), + 1000,0,2000,s800->GetIonChamber().GetAve()); + + obj.FillHistogram(dirname,"IC_dE_vs_OBJC", + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + double crdc1 = s800->GetCrdc(0).GetDispersiveX(); + + histname = "IC_Sum"; + obj.FillHistogram(dirname,histname,1000,0,2000,s800->GetIonChamber().GetAve()); + + histname = "IC_dE"; + obj.FillHistogram(dirname,histname,1000,0,5000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "CRDC1_X_vs_ICdE_Corr"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX(), + 5000,0,5000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "CRDC1_Y_vs_Time"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetNonDispersiveY(), + 3600,0,7200,s800->Timestamp()*1e-8); + + histname = "CRDC1_Time_vs_Timestamp"; + obj.FillHistogram(dirname,histname,1000,-2000,2000,s800->GetCrdc(0).GetTime(),3600,0,7200,s800->Timestamp()*1e-8); + + + //histname = "CRDC1_Pad"; + //obj.FillHistogram(dirname,histname,256,0,256,s800->GetCrdc(0).GetPad()); + + + + + histname = "CRDC1_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); + + histname = "CRDC1_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + + histname = "CRDC2_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(1).GetNonDispersiveY()); + + obj.FillHistogram(dirname,"CRDC1", + 800,-400,400,s800->GetCrdc(0).GetDispersiveX(), + 4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + + obj.FillHistogram(dirname,"CRDC2", + 8000,-400,400,s800->GetCrdc(1).GetDispersiveX(), + 4000,-2000,2000,s800->GetCrdc(1).GetNonDispersiveY()); + + //histname = "OBJ"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetOBJ()); + + //histname = "OBJ_Mesy"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetRawOBJ_MESY()); + +int ObjSize = s800->GetMTof().ObjSize(); +int XfpSize = s800->GetMTof().XfpSize(); +int E1UpSize = s800->GetMTof().E1UpSize(); + +for(int i=0;iGetMTof().fObj.at(i)-s800->GetMTof().fE1Up.at(j));}} + +for(int i=0;iGetMTof().fXfp.at(i)-s800->GetMTof().fE1Up.at(j));}} + + histname = "OBJ_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedObjE1()); + + histname = "OBJ_Corrected"; + obj.FillHistogram(dirname,histname,1200,-60000,60000,s800->GetCorrTOF_OBJ_MESY()); + + histname = "OBJ_MESY_vs_Timestamp"; + obj.FillHistogram(dirname,histname,4000,-20000,20000,s800->GetMTof().GetCorrelatedObjE1(),3600,0,7200,s800->Timestamp()*1e-8); + + histname = "XFP_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + histname = "XFP_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + histname = "XFPE1-OBJE1_OBJCorr_Correlation"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY()); + +if(s800->Timestamp()*1e-8>400){ + histname = "XFPE1-OBJE1_OBJCorr_Correlation_withclosedslits"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY());} + +if(s800->Timestamp()*1e-8<400){ + histname = "XFPE1-OBJE1_OBJCorr_Correlation_withopenslits"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY());} + + histname = "XFP_MESY_vs_Timestamp"; + obj.FillHistogram(dirname,histname,4000,-20000,20000,s800->GetMTof().GetCorrelatedXfpE1(),3600,0,3600,s800->Timestamp()*1e-8); + + + obj.FillHistogram(dirname,"IC_dE_vs_OBJCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + obj.FillHistogram(dirname,"IC_dE_vs_XFPCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_XFP_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + histname = "AFP_vs_OBJC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-20000,20000,s800->GetCorrTOF_OBJ_MESY()); // check units of AFP + + histname = "XFP_vs_OBJC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-20000,20000,s800->GetCorrTOF_OBJ_MESY()); + + histname = "AFP_vs_XFPC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-20000,20000,s800->GetCorrTOF_XFP_MESY()); // check units of AFP + + histname = "XFP_vs_XFPC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-20000,20000,s800->GetCorrTOF_XFP_MESY()); + + histname = "E1_vs_OBJ"; + obj.FillHistogram(dirname,histname, + 6000,-30000,30000,s800->GetMTof().GetCorrelatedE1Up(), + 6000,-30000,30000,s800->GetMTof().GetCorrelatedObjE1()); + + + histname = "OBJ_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()); + + histname = "OBJ_TAC_Corr"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); + + histname = "OBJ_ToFE1_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTofE1_TAC()); + + //histname = "RF"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetRF()); + + histname = "OBJ_Corr"; +obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJ()); + + histname = "XFP_TAC_ICdE"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_XFPTAC(),4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + histname = "Time_E1Up"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetScint().GetTimeUp()); + + histname = "AFP_vs_OBJTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); // check units of AFP + + histname = "XFP_vs_OBJTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); + + + histname = "AFP_vs_XFPTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); // check units of AFP + + histname = "XFP_vs_XFPTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); + +/* + histname = "AFP_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 1000,0,1000,obj_corr); // check units of AFP + + histname = "XFP_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(0), + 1000,0,1000,obj_corr); +*/ + + + return true; +} + +void CheckDAQCorrelation(TRuntimeObjects& obj){ + + TGretina *gretina = obj.GetDetector(); + TBank88 *bank88 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + + std::string dirname = "DAQ_Correlation"; + + if(bank88&&s800){ + obj.FillHistogram(dirname,"tdiff_bank88_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-bank88->GetTimestamp()); + } + if(bank88&&gretina){ + obj.FillHistogram(dirname,"tdiff_bank88_gretina",3600,0,7200,bank88->GetTimestamp(),1000,-2000,2000,gretina->GetGretinaHit(0).Timestamp()-bank88->GetTimestamp()); + } + if(obj_sci&&s800){ + obj.FillHistogram(dirname,"tdiff_ddas_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-obj_sci->GetOBJHit(0).GetExternalTimestamp()*8); + } + if(s800&&gretina){ + obj.FillHistogram(dirname,"tdiff_s800_gretina",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-gretina->GetGretinaHit(0).Timestamp()); + } + if(obj_sci&&gretina){ + obj.FillHistogram(dirname,"tdiff_gretina_ddas",3600,0,7200,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8/1e8,1000,-2000,2000,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8-gretina->GetGretinaHit(0).Timestamp()); + } + if(s800 && s800->GetTrigger().GetRegistr() <100 && s800->GetTrigger().GetRegistr()>0){ + TString dirname = Form("DAQ_Correlation_trigger_%d",s800->GetTrigger().GetRegistr()); + if(bank88&&s800){ + obj.FillHistogram(dirname,"tdiff_bank88_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-bank88->GetTimestamp()); + } + if(bank88&&gretina){ + obj.FillHistogram(dirname,"tdiff_bank88_gretina",3600,0,7200,bank88->GetTimestamp(),1000,-2000,2000,gretina->GetGretinaHit(0).Timestamp()-bank88->GetTimestamp()); + } + if(obj_sci&&s800){ + obj.FillHistogram(dirname,"tdiff_ddas_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-obj_sci->GetOBJHit(0).GetExternalTimestamp()*8); + } + if(s800&&gretina){ + obj.FillHistogram(dirname,"tdiff_s800_gretina",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-gretina->GetGretinaHit(0).Timestamp()); + } + if(obj_sci&&gretina){ + obj.FillHistogram(dirname,"tdiff_gretina_ddas",3600,0,7200,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8/1e8,1000,-2000,2000,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8-gretina->GetGretinaHit(0).Timestamp()); + } + } +} + + + +/* + +------------------------------ +GRETINA +------------------------------ + +*/ + + +bool HandleGretinaGated(TRuntimeObjects &obj, GCutG *outgoing) { + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TBank88 *bank88 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname; + std::string histname; + + if(outgoing) + dirname = Form("gretina_%s",outgoing->GetName()); + else + dirname = "gretina"; +//std::cout << "Gate name: " << time_energy->GetName() << std::endl ; + + //histname = Form("gretina_%s",time->GetName()); + + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + + obj.FillHistogram(dirname,"DetNumber_vs_Timestamp", + 80,0,80,hit.GetCrystalId(), + 3600,0,3600,s800->Timestamp()*1e-8); + +if(hit.GetPad()==0){ + histname="position_good_Decomp"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg());} +/* + for(unsigned int j=i+1;jSize();j++) { + TGretinaHit hit2 = gretina->GetGretinaHit(j); + + histname ="timediff_hit_hit2"; + obj.FillHistogram(histname,7200,0,7200,hit.GetTime()*1e-8,7200,0,1000,hit2.GetTime()*1e-8); + + //std::cout << "hit1:" << hit.GetTime()*1e-8 << "hit2:" << hit2.GetTime()*1e-8 << std::endl ; + + +//histname = "CoreEnergy_Doppler_gg"; +// obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetDoppler(GValue::Value("BETA")), +// 2000,0,4000,hit2.GetDoppler(GValue::Value("BETA"))); +//histname = "CoreEnergy_Doppler_gg"; +// obj.FillHistogram(dirname,histname,2000,0,4000,hit2.GetDoppler(GValue::Value("BETA")), +// 2000,0,4000,hit.GetDoppler(GValue::Value("BETA"))); + + } +*/ + + + double time_diff = s800->Timestamp()-hit.GetTime() ; + double energy = hit.GetCoreEnergy(); + unsigned int reg = s800->GetReg(); + int hole = HoleQMap[hit.GetHoleNumber()]; + + + + +// obj.FillHistogram(dirname,"IC_dE_vs_OBJC", +// 400,1100,1500,s800->GetCorrTOF_OBJTAC(), +// 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + obj.FillHistogram(dirname,"IC_dE_vs_OBJCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "Gretina_S800_time"; + obj.FillHistogram(dirname,histname,1200,-600,600,time_diff, + 2000,0,4000,hit.GetCoreEnergy()); + + histname = "Gretina_S800_CoreEnergy"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + histname = "Pad"; + obj.FillHistogram(dirname,histname,361,-1,360,hit.GetPad()); +/* +if(hole!=0){ + histname = Form("Gretina_CoreEnergy_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + for(int j=0;j<4;j++){ + histname = Form("Cores_charge_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(dirname,histname,4,0,4,j,16000,0,64000,hit.GetCoreCharge(j)); +} + +} +*/ + +/* + if(bank88) { + histname = Form("Gretina_Bank88_TD"); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + +if(reg&2){ +histname = Form("Gretina_Bank88_TD_Reg2"); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + +histname = Form("Gretina_Bank88_TD_Reg2_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + + } + +if(reg&1){ +histname = Form("Gretina_Bank88_TD_Reg1_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + } + +} + +if(bank88 && s800){ + +if(reg&2){ +histname = Form("S800_Bank88_TD-Energy_Reg2"); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-s800->Timestamp(), + 5000,0,10000,hit.GetCoreEnergy());} + +if(reg&1){ +histname = Form("S800_Bank88_TD-Energy_Reg1"); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-s800->Timestamp(), + 5000,0,10000,hit.GetCoreEnergy()); +}} +*/ + +if(outgoing){ + +if(outgoing->IsInside(s800->GetCorrTOF_OBJTAC(), +s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY()))){ + +//if(outgoing->IsInside(s800->GetCorrTOF_RF_MESY(), +//s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY()))){ + + + histname = "Gretina_S800_CoreEnergy_wCut"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + +/* + obj.FillHistogram(dirname,"IC_dE_vs_RfCorrE1_wCut", + 6000,16000,22000,s800->GetCorrTOF_RF_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); +*/ + + + obj.FillHistogram(dirname,"IC_dE_vs_CorrOBJTAC_wCut", + 2000,0,2000,s800->GetCorrTOF_OBJTAC(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + +histname = "Gretina_S800_CoreEnergy_Doppler"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetDoppler(GValue::Value("BETA"))); + + + obj.FillHistogram(dirname,"summary_Doppler",10000,0,10000,hit.GetDoppler(GValue::Value("BETA")), + 200,0,200,hit.GetCrystalId()); + + } //gate (real) + + +if(outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), +s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY()))){ + + + obj.FillHistogram(dirname,"IC_dE_vs_OBJCorrE1_Mesy_wCut", + 8000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + +histname = "Gretina_S800_CoreEnergy_Doppler_wMesyCut"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetDoppler(GValue::Value("BETA"))); + + histname = "CRDC1_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC1_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + +} + + +if(outgoing->IsInside(time_diff,hit.GetCoreEnergy())){ + + histname = "Gretina_S800_CoreEnergy_wCut_fakedtime"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + histname = "Gretina_S800_time_wfaketimecut"; + obj.FillHistogram(dirname,histname,1200,-600,600,time_diff, + 2000,0,4000,hit.GetCoreEnergy()); + + + if(s800->GetScint().GetEUp()>1400 && s800->GetScint().GetEUp()<1850){ + histname = "Gretina_S800_CoreEnergy_wCut_fakedtime_and_energy"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + } + + } //gate (faked time gate) + + } //outgoing + +//if(time_energy->IsInside(hit.GetCoreEnergy(),time_diff)){ + +//if(time_diff>260 && time_diff<300){ + +if(s800 && gretina){ + obj.FillHistogram(dirname,"E1Up_Singles_inGretina",2000,0,2000,s800->GetScint().GetEUp()) ; +} + + +} + return true; +} + + +void MonitorOBJScintillator_DDAS(TRuntimeObjects &obj){ + TOBJ *obj_sci = obj.GetDetector(); + if(obj_sci){ + std::string dirname = "OBJSci"; + for(size_t x = 0; xSize();x++){ + auto objhit = obj_sci->GetOBJHit(x); + obj.FillHistogram(dirname,"Energy_of_OBJSci",1000,0,40000,objhit.GetEnergy()); + if(objhit.GetPileup()){ + obj.FillHistogram(dirname,"Energy_of_OBJSci_Pileup",1000,0,40000,objhit.GetEnergy()); + }else{ + obj.FillHistogram(dirname,"Energy_of_OBJSci_noPileup",1000,0,40000,objhit.GetEnergy()); + } + + } + } +} + +void MonitorCrdcs(TRuntimeObjects& obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "CRDC_Det"; + auto crdc1 = s800->GetCrdc(0); + auto crdc2 = s800->GetCrdc(1); + Double_t crdc1_x = crdc1.GetDispersiveX(); + Double_t crdc1_y = crdc1.GetNonDispersiveY(); + Double_t crdc2_x = crdc2.GetDispersiveX(); + Double_t crdc2_y = crdc2.GetNonDispersiveY(); + + obj.FillHistogram(dirname,"Crdc1_xy",800,-400,400,crdc1_x,800,-400,400,crdc1_y); + obj.FillHistogram(dirname,"Crdc2_xy",800,-400,400,crdc2_x,800,-400,400,crdc2_y); + + obj.FillHistogram(dirname,"Crdc1_time_ts",3600,0,3600,s800->Timestamp()/1e8,500,-2000,2000,crdc1.GetTime()); + obj.FillHistogram(dirname,"Crdc2_time_ts",3600,0,3600,s800->Timestamp()/1e8,500,-2000,2000,crdc2.GetTime()); +} + + +void MonitorICs(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "ION_Chamber"; + auto ic = s800->GetIonChamber(); + for(int x = 0; xGetCrdc(0); + obj.FillHistogram(dirname,"ICEnergy_crdc1x",800,-400,400,crdc1.GetDispersiveX(),1000,0,4000,ic.GetSum()); + obj.FillHistogram(dirname,"ICAVEnergy_crdc1x",800,-400,400,crdc1.GetDispersiveX(),1000,0,4000,ic.GetAve()); + obj.FillHistogram(dirname,"ICEnergy_crdc1y",800,-400,400,crdc1.GetNonDispersiveY(),1000,0,4000,ic.GetSum()); + obj.FillHistogram(dirname,"ICAVEnergy_crdc1y",800,-400,400,crdc1.GetNonDispersiveY(),1000,0,4000,ic.GetAve()); +} + +void OutgoingPID(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "OUT_PID"; + auto ic = s800->GetIonChamber(); + auto crdc1 = s800->GetCrdc(0); + obj.FillHistogram(dirname,"TOF-dE",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + obj.FillHistogram(dirname,"dE-Crdc1x",800,-400,400,crdc1.GetDispersiveX(),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + + auto obj_sci = obj.GetDetector(); + if(!obj_sci) return; + if(tmppidcuts.at(0)->IsInside(s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),obj_sci->GetOBJHit(0).GetEnergy())){ + obj.FillHistogram(dirname,"TOF-dE-gated-by-sci",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + } +} + +void IncomingPID(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + if(!s800 || !obj_sci) return; + + std::string dirname = "INC_PID"; + for(size_t x = 0; xSize();x++) + obj.FillHistogram(dirname,"TOF-dE-Sci",4000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),10000,0,40000,obj_sci->GetOBJHit(x).GetEnergy()); + obj.FillHistogram(dirname,"TOF-dE-PIN",4000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),1000,0,4000,s800->GetPinE()); + + obj.FillHistogram(dirname,"TOF-dE-Sci-raw",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + obj.FillHistogram(dirname,"TOF-dE-PIN-raw",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); + + if(tmppidcuts.at(0)->IsInside(s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),obj_sci->GetOBJHit(0).GetEnergy())){ + obj.FillHistogram(dirname,"TOF-dE-PIN-raw-gated",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); + } + +} + +void MonitorTOF(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "TOF_Packet"; + auto tof = s800->GetTof(); + obj.FillHistogram(dirname,"OBJ_TAC",4000,-2000,2000,tof.GetTacOBJ()); + obj.FillHistogram(dirname,"XFP_TAC",4000,-2000,2000,tof.GetTacXFP()); + obj.FillHistogram(dirname,"OBJ-XFP",4000,-2000,2000,tof.GetTacOBJ()-tof.GetTacXFP()); + obj.FillHistogram(dirname,"OBJ_vs_XFP",1000,-2000,2000,tof.GetTacOBJ(),1000,-2000,2000,tof.GetTacXFP()); + + auto mtof = s800->GetMTof(); + for(int x = 0; x < mtof.XfpSize(); x++) + for(int y = 0; y < mtof.E1UpSize();y++){ + obj.FillHistogram(dirname,"XFP-E1_Mesy",1000,-10000,10000,s800->GetRawXF_MESY(x)-s800->GetRawE1_MESY(y)); + obj.FillHistogram(dirname,"XFP-E1_Mesy_vs_AFP",3000,-4000,8000,s800->GetCorrTOF_XFP_MESY(x*y+y),1000,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"XFP-E1_Mesy_vs_XFP",3000,-4000,8000,s800->GetCorrTOF_XFP_MESY(x*y+y),1000,-400,400,s800->GetXFP()); + } + + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.E1UpSize();y++){ + obj.FillHistogram(dirname,"OBJ-E1_Mesy",1000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawE1_MESY(y)); + obj.FillHistogram(dirname,"OBJ-E1_Mesy_vs_AFP",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(x*y+y),1000,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"OBJ-E1_Mesy_vs_XFP",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(x*y+y),1000,-400,400,s800->GetXFP()); + } + + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.XfpSize();y++){ + obj.FillHistogram(dirname,"XFP-OBJ_Mesy",1000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y)); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_AFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),100,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_BFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),100,-0.1,0.1,s800->GetBFP()); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_XFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),1000,-400,400,s800->GetXFP()); + } + obj.FillHistogram(dirname,"XFP_vs_OBJ_MESY",2000,27000,31000,mtof.GetCorrelatedObj(),2000,28000,36000,mtof.GetCorrelatedXfp()); + +} + +void CountOBJ(TRuntimeObjects &obj){ + if(pidcuts.size()==0) return; + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + if(!s800) return; + if(!obj_sci) return; + auto mtof = s800->GetMTof(); + if(tofcuts.size()==1 && !(tofcuts.at(0)->IsInside(mtof.GetCorrelatedObj(),mtof.GetCorrelatedXfp()))) return; + + std::string dirname="Count_OBJ"; + std::string dirname2="Check_Mdis"; + auto ic = s800->GetIonChamber(); + auto crdc1 = s800->GetCrdc(0); + double tof = s800->GetCorrTOF_OBJ_MESY(0); + double dE = ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY()); + obj.FillHistogram(dirname,"tof-dE",3000,-4000,8000,tof,4000,0,4000,dE); + for(size_t x = 0; xIsInside(tof,dE)){ + histname = Form("tof-dE_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,3000,-4000,8000,tof,4000,0,4000,dE); + histname = Form("CRDC1_x_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname2,histname,800,-400,400,crdc1.GetDispersiveX()); + dirname2 = "INC_PID"; + histname = Form("TOF_dE_Sci_Raw_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + histname = Form("TOF_dE_Pin_Raw_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); + } + + } + if(!obj_sci) return; + for(size_t y = 0; y < pidcuts.size(); y++){ + + std::string histname; + if(pidcuts.at(y)->IsInside(tof,dE)){ + histname = Form("Energy_if_OBJSci_%s",pidcuts.at(y)->GetName()); + for(size_t x = 0; xSize();x++) + obj.FillHistogram(dirname,histname,1000,0,40000,obj_sci->GetOBJHit(x).GetEnergy()); + } + } + +} + +void MonitorPin(TRuntimeObjects &obj){ + + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "PIN"; + obj.FillHistogram(dirname,"Pin_energy",4000,0,4000,s800->GetPinE()); +} + +void LoadGates(TRuntimeObjects &obj){ + TList *gates = &(obj.GetGates()); + if(!gates||gates->GetSize()==0) return; + + if(gates_loaded!=gates->GetSize()){ + TIter iter(gates); + while(TObject *obj = iter.Next()){ + GCutG *gate = (GCutG*)obj; + std::string tag = gate->GetTag(); + std::cout<<"tag : "<(); + TBank88 *bank88 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + + + LoadGates(obj); + CheckDAQCorrelation(obj); + + MonitorOBJScintillator_DDAS(obj); + MonitorCrdcs(obj); + MonitorICs(obj); + MonitorTOF(obj); + MonitorPin(obj); + + OutgoingPID(obj); + IncomingPID(obj); + CountOBJ(obj); + + + return; + + TList *gates = &(obj.GetGates()); + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + + + if(gates_loaded!=gates->GetSize()) { + TIter iter(gates); + while(TObject *obj = iter.Next()) { + GCutG *gate = (GCutG*)obj; + std::string tag = gate->GetTag(); + if(!tag.compare("time_energy")) { +// time_energy_cuts.push_back(gate); + } + else if(!tag.compare("outgoing")) { + outgoing_cuts.push_back(gate); + } + else if(!tag.compare("incoming")) { + incoming_cuts.push_back(gate); + } + // else if(!tag.compare("additional")){ + // additional_cuts.push_back(gate); + //} + gates_loaded++; + } + } + + +///////////////////////// + + + std::string histname = ""; + std::string dirname = ""; + + unsigned int reg = s800->GetReg(); + +//if(bank88) { +// for(unsigned int x=0;xSize();x++) { + // TMode3Hit &hit = (TMode3Hit&)bank88->GetHit(x); + // std::string histname = Form("bank88_%i",hit.GetChannel()); + //obj.FillHistogram(histname,16000,0,64000,hit.Charge()); + // } + if(s800&&bank88) { + // std::string histname = "S800_Bank88_timestamp_difference"; + obj.FillHistogram("S800_Bank88_timestamp_difference",800,-400,400,bank88->Timestamp()-s800->Timestamp());} + +if(!s800 && bank88){ + obj.FillHistogram("S800_Bank88_timestamp_difference",400,-400,400,110);} + +if(!bank88 && s800){ + obj.FillHistogram("S800_Bank88_timestamp_difference",400,-400,400,100);} + +if(!bank88 && !s800){ + obj.FillHistogram("S800_Bank88_timestamp_difference",400,-400,400,120);} + + +if(s800 && bank88){ + + histname = "S800_Bank88_timestamp_difference_vs_bank88time"; + obj.FillHistogram(histname,7200,0,7200,bank88->Timestamp()*1e-8,400,-400,400,bank88->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_timestamp_difference_vs_s800time"; + obj.FillHistogram(histname,7200,0,7200,s800->Timestamp()*1e-8,400,-400,400,bank88->Timestamp()-s800->Timestamp()); + } +// } + +if(s800){ + //obj.FillHistogram("E1Up_s800",2000,0,2000,s800->GetScint().GetEUp()) ; +} + +/* + if(!gretina) + return; + + if(gretina) { + double sumsegener = 0 ; + for(int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + + + int hole = HoleQMap[hit.GetHoleNumber()]; + obj.FillHistogram("summary",2000,0,2000,hit.GetCoreEnergy(), + 200,0,200,hit.GetCrystalId()); + obj.FillHistogram("sum",4000,0,4000,hit.GetCoreEnergy()); + + histname="position"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); +*/ + +/* +dirname = "Summary_Segments"; +double previous = 0 ; + + + for(int z=0;z500){ + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg());}} + +} + + +if(hit.GetPad()==0){ + histname="position_good_Decomp"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + + + //histname="position_good_Decomp_with_CC_gate_bt_1000keV"; + //if(hit.GetCoreEnergy()>1000){ + //obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + //360,0,360,hit.GetPhiDeg());} + + //histname="position_good_Decomp_with_CC_gate_bt_500keV"; + //if(hit.GetCoreEnergy()>500){ + //obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + //360,0,360,hit.GetPhiDeg());} + + //histname="position_good_Decomp_with_CC_gate_lt_500keV"; + //if(hit.GetCoreEnergy()<500){ + //obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + //360,0,360,hit.GetPhiDeg());} +} + + +if(hole!=0){ + dirname = Form("Det%i",hole); + histname = Form("Gretina_X_Y_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,720,-360,360,hit.GetX(), + 720,-360,360,hit.GetY()); + + for(int j=0;j<4;j++){ + histname = Form("Cores_charge_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(dirname,histname,4,0,4,j,16000,0,64000,hit.GetCoreCharge(j)); +} + + + histname = Form("Gretina_GetPad_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,360,0,360,hit.GetPad()); + + histname = Form("Gretina_Position_Det%02i",hole); + obj.FillHistogram(dirname,histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + + + +*/ + +/* +if(hole!=0){ + dirname = Form("Det%i",hole); + + if(bank88) { + +if(reg&2){ + histname = Form("Gretina_Bank88_TD_Reg2_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + histname = Form("Gretina_Bank88_TDvsBank88TS_Reg2_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(histname,7200,0,7200,bank88->Timestamp()*1e-8,700,-400,1000,bank88->Timestamp()-hit.GetTime()); + } + +if(reg&1){ + histname = Form("Gretina_Bank88_TD_Reg1_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + histname = Form("Gretina_Bank88_TDvsBank88TS_Reg1_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(histname,7200,0,7200,bank88->Timestamp()*1e-8,700,-400,1000,bank88->Timestamp()-hit.GetTime()); + }} + + if(s800) { + + //if(s800->GetScint().GetEUp()>1560 && s800->GetScint().GetEUp()<1750){ + + //histname = "Gretina_S800_coincidence_gateon_1332keV"; + //obj.FillHistogram(histname,2000,0,4000,hit.GetCoreEnergy());} + + histname = Form("Gretina_S800_TD_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + //obj.FillHistogram("E1_Up_coincidence_with_Gretina",2000,0,2000,s800->GetScint().GetEUp()); + + + }} + + if(bank88) { + histname = Form("Gretina_Bank88_TD"); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + +if(reg&2){ +histname = Form("Gretina_Bank88_TD_Reg2"); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + } + +if(reg&1){ +histname = Form("Gretina_Bank88_TD_Reg1"); + obj.FillHistogram(histname,600,-600,600,bank88->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + } + +} + + if(s800 && bank88){ + std::string histname = "GretinaEnergy_Bank88-S800_timestamp_difference"; + obj.FillHistogram(histname,400,-400,400,bank88->Timestamp()-s800->Timestamp(), 2000,0,4000,hit.GetCoreEnergy());} + + } + } +*/ + +///////////////////////// + + + +// Outgoing beam with additional cuts + +int incoming_passed=-1; +int outgoing_passed=-1; + + + for(unsigned int x=0;x0)) { + passed = IncomingBeam(obj,outgoing_cuts.at(x)); + HandleGretinaGated(obj,outgoing_cuts.at(x)); + } + if(x!=0 && passed) { + outgoing_passed = x; + break; + } +} +// int incoming_passed=-1; + //int incoming2_passed=-1; +// int outgoing_passed=-1; +// int break_condition=-1; + +//int time_passed=-1; + + + + + for(size_t j=0;jGetSize()) + list->Sort(); +} + + diff --git a/histos/MakeHistos_Gretina_tests_Mode2.cxx b/histos/MakeHistos_Gretina_tests_Mode2.cxx new file mode 100644 index 00000000..e0d5595a --- /dev/null +++ b/histos/MakeHistos_Gretina_tests_Mode2.cxx @@ -0,0 +1,420 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TFastScint.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" + + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 19 +#define Q10 6 +#define Q11 9 +//#define Q12 20 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank88 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + std::string histname = ""; + std::string dirname = ""; + + if(s800) { + obj.FillHistogram("E1Up_Singles",2000,0,2000,s800->GetScint().GetEUp()) ; + + + +// histname = "S800_S800_timestamp_difference"; +// obj.FillHistogram(histname,400,-400,400,hit2.Timestamp()-hit.Timestamp()); + + + } + + + + if(bank29) { + for(unsigned int x=0; xSize(); x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + std::string histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(histname,16000,0,64000,hit.Charge()); + } + if(s800) { + std::string histname = "S800_Bank88_timestamp_difference"; + obj.FillHistogram(histname,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_timestamp_difference_vs_bank29time"; + obj.FillHistogram(histname,7200,0,7200,bank29->Timestamp()*1e-8,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_timestamp_difference_vs_s800time"; + obj.FillHistogram(histname,7200,0,7200,s800->Timestamp()*1e-8,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + //obj.FillHistogram("E1_Down",1000,0,4000),s800-> GetScint().GetEDown()) ; + } + } + if(!gretina) + return; + + if(gretina) { + + // gretina->CleanHits(); + //double sumsegener = 0 ; + for(unsigned int i=0; iSize(); i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + //hit.Print(); + //hit.TrimSegments(0); + //hit.Print(); + + int hole = HoleQMap[hit.GetHoleNumber()]; + obj.FillHistogram("summary",10000,0,10000,hit.GetCoreEnergy(), + 200,0,200,hit.GetCrystalId()); + obj.FillHistogram(Form("quad%02i",hit.GetCrystalId()),10000,0,10000,hit.GetCoreEnergy()); + + int quad = HoleQMap[hit.GetHoleNumber()]; + int p = (hit.GetCrystalId() % 4) +1; + + obj.FillHistogram(Form("q%02i_p%i",quad,p),10000,0,10000,hit.GetCoreEnergy()); + + if(quad==10 && p == 1){ + obj.FillHistogram("q10p1_cc1",10000,0,100000,hit.GetCoreCharge(0)); + obj.FillHistogram("q10p1_cc2",10000,0,100000,hit.GetCoreCharge(1)); + obj.FillHistogram("q10p1_cc3",10000,0,100000,hit.GetCoreCharge(2)); + obj.FillHistogram("q10p1_cc4",10000,0,100000,hit.GetCoreCharge(3)); + } + + obj.FillHistogram("sum",10000,0,10000,hit.GetCoreEnergy()); + + histname="position"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + + dirname = "GretSummCoreCharge"; + histname = Form("Q%iCoreCharge",HoleQMap[hit.GetCrystalId()/4]); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+0., + 64000,0,64000,((double)hit.GetCoreCharge(0))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+1., + 64000,0,64000,((double)hit.GetCoreCharge(1))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+2., + 64000,0,64000,((double)hit.GetCoreCharge(2))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+3., + 64000,0,64000,((double)hit.GetCoreCharge(3))); + + + +//double previous = 0 ; + +//hit.TrimSegments(0); + for(int z=0; z500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + } + } + +//outside of loop +//histname = Form("GretinaSummaryX%02i",hit.GetCrystalId()); +//dirname = "Summary_Segments_outside_loop"; +// obj.FillHistogram(dirname,histname,40,0,40,hit.GetSegmentId(), +//2000,0,4000,hit.GetSegmentEng(isegid)); + +//histname = Form("Gretina_SegIDenergy_X%02i",hit.GetCrystalId()); +// obj.FillHistogram(dirname,histname,2000,0,4000,sumsegener); + + +// for(unsigned int k=i+1;kSize();k++) { +//TGretinaHit hit2 = gretina->GetGretinaHit(z); +//histname = Form("Segment_Correlations_X%02i",hit.GetCrystalId()); +// obj.FillHistogram(histname,40,0,40,hit.GetSegmentId(z), +// 40,0,40,hit2.GetSegmentId(z));} + + + //double segone = hit.GetSegmentEng(z) ; +// double totalseg = totalseg+segone ; + +//histname = Form("GretinaSummaryX%02i_summed",hit.GetCrystalId()); + // obj.FillHistogram(histname,2000,0,4000,totalseg); + + + + if(hit.GetPad()==0) { + histname="position_good_Decomp"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + + + histname="position_good_Decomp_with_CC_gate_bt_1000keV"; + if(hit.GetCoreEnergy()>1000) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + histname="position_good_Decomp_with_CC_gate_bt_500keV"; + if(hit.GetCoreEnergy()>500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + histname="position_good_Decomp_with_CC_gate_lt_500keV"; + if(hit.GetCoreEnergy()<500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + } + + + + // histname="Id_hole"; + // obj.FillHistogram(histname,100,0,100,hit.GetCrystalId(), + // 20,0,20,hole);} + + //histname="Theta_id"; + //obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + //200,0,200,hit.GetCrystalId()); + + //histname="phi_id"; + //obj.FillHistogram(histname,360,0,360,hit.GetPhiDeg(), + //200,0,200,hit.GetCrystalId()); + + + if(hole!=0) { + dirname = Form("Det%i",hole); + histname = Form("Gretina_X_Y_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,720,-360,360,hit.GetX(), + 720,-360,360,hit.GetY()); + + histname = Form("Gretina_X_Y_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,720,-360,360,hit.GetX(), + 720,-360,360,hit.GetY()); + +//if(bank29){ +//histname = Form("Gretina_EnergyTime_Cry%02i_Det%02i",hit.GetCrystalId(),hole); +//obj.FillHistogram(dirname,histname,7200,0,7200,bank29->Timestamp()*1e-8, +// 10000,0,10000,hit.GetCoreEnergy());} + + for(int j=0; j<4; j++) { + histname = Form("Cores_charge_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(dirname,histname,4,0,4,j,16000,0,64000,hit.GetCoreCharge(j)); + } + + +// Baseline not implemented yet + /* + for(int j=0;j<4;j++){ + histname = Form("Gretina_Baseline_Det%02i_Digi%i",hole,j); + obj.FillHistogram(dirname,histname,32000,0,32000,hit.GetCoreCharge(j), + 32000,0,32000,hit.GetBaseline());} + */ + + +// histname = Form("Gretina_CoreEnergy_CryNum%02i_Det%02i",hit.GetCrystalNumber(),hole); +// obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetCoreEnergy()); + +//histname = Form("Gretina_CoreEnergy_CryNum%02i_Hole%02i",hit.GetCrystalNumber(),hit.GetHoleNumber()); + // obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetCoreEnergy()); + +//histname = Form("Gretina_Theta_Id_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + // obj.FillHistogram(dirname,histname,360,0,360,hit.GetThetaDeg(), + // 200,0,200,hit.GetCrystalId()); + +//histname = Form("Gretina_Phi_Id_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + // obj.FillHistogram(dirname,histname,360,0,360,hit.GetPhiDeg(), + // 200,0,200,hit.GetCrystalId()); + + histname = Form("Gretina_GetPad_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,360,-1,141,hit.GetPad()); + + histname = Form("Gretina_Position_Det%02i",hole); + obj.FillHistogram(dirname,histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + + + //double radius=((hit.GetX())^2+(hit.GetY())^2)^0.5 ; + + // histname="z-r"; + // obj.FillHistogram(histname,360,0,360,hit.GetZ(), + // 360,0,360,radius); + + if(bank29) { + histname = "Gretina_Bank88_timediff_energy"; + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + histname = "Gretina_Bank88_timediff_vs_bank29time"; + obj.FillHistogram(histname,7200,0,7200,bank29->Timestamp()*1e-8,700,-400,1000,bank29->Timestamp()-hit.GetTime()); + + + histname = "Bank29_Charge"; + obj.FillHistogram(histname,2000,-10000,10000,bank29->GetCharge()); + + + } + + if(s800) { + + if(s800->GetScint().GetEUp()>1560 && s800->GetScint().GetEUp()<1750) { + + histname = "Gretina_S800_coincidence_gateon_1332keV"; + obj.FillHistogram(histname,2000,0,4000,hit.GetCoreEnergy()); + } + + histname = "Gretina_S800_time"; + obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + // obj.FillHistogram("E1_Down_coincidence_with_Gretina",2000,0,2000,s800->GetScint().GetEDown()); + obj.FillHistogram("E1_Up_coincidence_with_Gretina",2000,0,2000,s800->GetScint().GetEUp()); + //histname = "Gretina_t0_S800_time"; + //obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetT0(), + //2000,0,4000,hit.GetCoreEnergy()); + + } + + if(s800 && bank29) { + std::string histname = "GretinaEnergy_Bank88-S800_timestamp_difference"; + obj.FillHistogram(histname,400,-400,400,bank29->Timestamp()-s800->Timestamp(), 2000,0,4000,hit.GetCoreEnergy()); + } + + } + } + + + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistos_Gretina_tests_Mode2_v2.cxx b/histos/MakeHistos_Gretina_tests_Mode2_v2.cxx new file mode 100644 index 00000000..d7a4ffee --- /dev/null +++ b/histos/MakeHistos_Gretina_tests_Mode2_v2.cxx @@ -0,0 +1,401 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TFastScint.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" + + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 19 +#define Q10 6 +#define Q11 9 +//#define Q12 20 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank88 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + std::string histname = ""; + std::string dirname = ""; + + if(s800) { + obj.FillHistogram("E1Up_Singles",2000,0,2000,s800->GetScint().GetEUp()) ; + + + +// histname = "S800_S800_timestamp_difference"; +// obj.FillHistogram(histname,400,-400,400,hit2.Timestamp()-hit.Timestamp()); + + + } + + + + if(bank29) { + for(unsigned int x=0; xSize(); x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + std::string histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(histname,16000,0,64000,hit.Charge()); + } + if(s800) { + std::string histname = "S800_Bank88_timestamp_difference"; + obj.FillHistogram(histname,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_timestamp_difference_vs_bank29time"; + obj.FillHistogram(histname,7200,0,7200,bank29->Timestamp()*1e-8,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_timestamp_difference_vs_s800time"; + obj.FillHistogram(histname,7200,0,7200,s800->Timestamp()*1e-8,400,-400,400,bank29->Timestamp()-s800->Timestamp()); + + //obj.FillHistogram("E1_Down",1000,0,4000),s800-> GetScint().GetEDown()) ; + } + } + if(!gretina) + return; + + if(gretina) { + + // gretina->CleanHits(); + //double sumsegener = 0 ; + static long tstart = -10; + for(unsigned int i=0; iSize(); i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + if(tstart<=0) tstart = hit.Timestamp(); + //hit.Print(); + //hit.TrimSegments(0); + //hit.Print(); + + int hole = HoleQMap[hit.GetHoleNumber()]; + obj.FillHistogram("summary",10000,0,10000,hit.GetCoreEnergy(), + 200,0,200,hit.GetCrystalId()); + obj.FillHistogram(Form("quad%02i",hit.GetCrystalId()),10000,0,10000,hit.GetCoreEnergy()); + + int quad = HoleQMap[hit.GetHoleNumber()]; + int p = (hit.GetCrystalId() % 4) +1; + + obj.FillHistogram(Form("q%02i_p%i",quad,p),10000,0,10000,hit.GetCoreEnergy()); + long tdiff = (long) (hit.Timestamp() - tstart); + long mod = 1e8; + long tdiff1 = tdiff % mod; + if(quad ==1 || quad == 10) + obj.FillHistogram(Form("q%02i_p%i_et_nomod",quad,p),10000,0,10000,hit.GetCoreEnergy(),3600,0,3600,tdiff/1e8*60.); + if(quad ==1 || quad == 10) + obj.FillHistogram(Form("q%02i_p%i_et",quad,p),10000,0,10000,hit.GetCoreEnergy(),1000,0,1e8,tdiff1); + mod = long(1e8 / 30. ); + long tdiff2 = tdiff % mod; + obj.FillHistogram(Form("q%02i_p%i_et2",quad,p),10000,0,10000,hit.GetCoreEnergy(),50,0,1e7,tdiff2); + + obj.FillHistogram("sum",10000,0,10000,hit.GetCoreEnergy()); + + histname="position"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + + dirname = "GretSummCoreCharge"; + histname = Form("Q%iCoreCharge",HoleQMap[hit.GetCrystalId()/4]); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+0., + 64000,0,64000,((double)hit.GetCoreCharge(0))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+1., + 64000,0,64000,((double)hit.GetCoreCharge(1))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+2., + 64000,0,64000,((double)hit.GetCoreCharge(2))); + obj.FillHistogram(dirname,histname, + 16,0,16,4*hit.GetCrystalNumber()+3., + 64000,0,64000,((double)hit.GetCoreCharge(3))); + + + + dirname = "Summary_Segments"; +//double previous = 0 ; + +//hit.TrimSegments(0); + for(int z=0; z500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + } + } + +//outside of loop +//histname = Form("GretinaSummaryX%02i",hit.GetCrystalId()); +//dirname = "Summary_Segments_outside_loop"; +// obj.FillHistogram(dirname,histname,40,0,40,hit.GetSegmentId(), +//2000,0,4000,hit.GetSegmentEng(isegid)); + +//histname = Form("Gretina_SegIDenergy_X%02i",hit.GetCrystalId()); +// obj.FillHistogram(dirname,histname,2000,0,4000,sumsegener); + + +// for(unsigned int k=i+1;kSize();k++) { +//TGretinaHit hit2 = gretina->GetGretinaHit(z); +//histname = Form("Segment_Correlations_X%02i",hit.GetCrystalId()); +// obj.FillHistogram(histname,40,0,40,hit.GetSegmentId(z), +// 40,0,40,hit2.GetSegmentId(z));} + + + //double segone = hit.GetSegmentEng(z) ; +// double totalseg = totalseg+segone ; + +//histname = Form("GretinaSummaryX%02i_summed",hit.GetCrystalId()); + // obj.FillHistogram(histname,2000,0,4000,totalseg); + + + + if(hit.GetPad()==0) { + histname="position_good_Decomp"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + + + histname="position_good_Decomp_with_CC_gate_bt_1000keV"; + if(hit.GetCoreEnergy()>1000) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + histname="position_good_Decomp_with_CC_gate_bt_500keV"; + if(hit.GetCoreEnergy()>500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + histname="position_good_Decomp_with_CC_gate_lt_500keV"; + if(hit.GetCoreEnergy()<500) { + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + } + + + + // histname="Id_hole"; + // obj.FillHistogram(histname,100,0,100,hit.GetCrystalId(), + // 20,0,20,hole);} + + //histname="Theta_id"; + //obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + //200,0,200,hit.GetCrystalId()); + + //histname="phi_id"; + //obj.FillHistogram(histname,360,0,360,hit.GetPhiDeg(), + //200,0,200,hit.GetCrystalId()); + + + if(hole!=0) { + dirname = Form("Det%i",hole); + histname = Form("Gretina_X_Y_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,720,-360,360,hit.GetX(), + 720,-360,360,hit.GetY()); + + histname = Form("Gretina_X_Y_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,720,-360,360,hit.GetX(), + 720,-360,360,hit.GetY()); + +//if(bank29){ +//histname = Form("Gretina_EnergyTime_Cry%02i_Det%02i",hit.GetCrystalId(),hole); +//obj.FillHistogram(dirname,histname,7200,0,7200,bank29->Timestamp()*1e-8, +// 10000,0,10000,hit.GetCoreEnergy());} + + for(int j=0; j<4; j++) { + histname = Form("Cores_charge_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(dirname,histname,4,0,4,j,16000,0,64000,hit.GetCoreCharge(j)); + } + + +// Baseline not implemented yet + /* + for(int j=0;j<4;j++){ + histname = Form("Gretina_Baseline_Det%02i_Digi%i",hole,j); + obj.FillHistogram(dirname,histname,32000,0,32000,hit.GetCoreCharge(j), + 32000,0,32000,hit.GetBaseline());} + */ + + +// histname = Form("Gretina_CoreEnergy_CryNum%02i_Det%02i",hit.GetCrystalNumber(),hole); +// obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetCoreEnergy()); + +//histname = Form("Gretina_CoreEnergy_CryNum%02i_Hole%02i",hit.GetCrystalNumber(),hit.GetHoleNumber()); + // obj.FillHistogram(dirname,histname,4000,0,4000,hit.GetCoreEnergy()); + +//histname = Form("Gretina_Theta_Id_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + // obj.FillHistogram(dirname,histname,360,0,360,hit.GetThetaDeg(), + // 200,0,200,hit.GetCrystalId()); + +//histname = Form("Gretina_Phi_Id_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + // obj.FillHistogram(dirname,histname,360,0,360,hit.GetPhiDeg(), + // 200,0,200,hit.GetCrystalId()); + + histname = Form("Gretina_GetPad_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,360,-1,141,hit.GetPad()); + + histname = Form("Gretina_Position_Det%02i",hole); + obj.FillHistogram(dirname,histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + + + + //double radius=((hit.GetX())^2+(hit.GetY())^2)^0.5 ; + + // histname="z-r"; + // obj.FillHistogram(histname,360,0,360,hit.GetZ(), + // 360,0,360,radius); + + if(bank29) { + histname = "Gretina_Bank88_timediff_energy"; + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + histname = "Gretina_Bank88_timediff_vs_bank29time"; + obj.FillHistogram(histname,7200,0,7200,bank29->Timestamp()*1e-8,700,-400,1000,bank29->Timestamp()-hit.GetTime()); + + + histname = "Bank29_Charge"; + obj.FillHistogram(histname,2000,-10000,10000,bank29->GetCharge()); + + obj.FillHistogram(Form("q%02i_p%i_timestamp",quad,p),7200,0,7200,bank29->Timestamp()*1e-8,10000,0,10000,hit.GetCoreEnergy()); + + } + + if(s800) { + + if(s800->GetScint().GetEUp()>1560 && s800->GetScint().GetEUp()<1750) { + + histname = "Gretina_S800_coincidence_gateon_1332keV"; + obj.FillHistogram(histname,2000,0,4000,hit.GetCoreEnergy()); + } + + histname = "Gretina_S800_time"; + obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + + // obj.FillHistogram("E1_Down_coincidence_with_Gretina",2000,0,2000,s800->GetScint().GetEDown()); + obj.FillHistogram("E1_Up_coincidence_with_Gretina",2000,0,2000,s800->GetScint().GetEUp()); + //histname = "Gretina_t0_S800_time"; + //obj.FillHistogram(histname,1200,-600,600,s800->Timestamp()-hit.GetT0(), + //2000,0,4000,hit.GetCoreEnergy()); + + } + + if(s800 && bank29) { + std::string histname = "GretinaEnergy_Bank88-S800_timestamp_difference"; + obj.FillHistogram(histname,400,-400,400,bank29->Timestamp()-s800->Timestamp(), 2000,0,4000,hit.GetCoreEnergy()); + } + + } + } + + + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistos_Mode3.cxx b/histos/MakeHistos_Mode3.cxx new file mode 100644 index 00000000..782679a4 --- /dev/null +++ b/histos/MakeHistos_Mode3.cxx @@ -0,0 +1,206 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TMode3.h" +#include "TBank88.h" +#include "GValue.h" + + +#include "TChannel.h" +#include "GValue.h" + + +//#define Q1 15 +//#define Q2 7 +//#define Q3 8 +//#define Q4 16 +//#define Q5 9 +//#define Q6 14 +//#define Q7 17 +//#define Q8 6 +//#define Q9 19 + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 19 +#define Q10 6 +#define Q11 9 +#define Q12 20 + + + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; + HoleQMap[Q12] = 12; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + //TGretina *gretina = obj.GetDetector(); + TMode3 *mode3 = obj.GetDetector(); + //TBank88 *bank29 = obj.GetDetector(); + TList *list = &(obj.GetObjects()); + + int numobj = list->GetSize(); + if(!mode3) + return; + + for(unsigned int x=0;xSize();x++) { + TMode3Hit hit = mode3->GetMode3Hit(x); + int hole = HoleQMap[hit.GetHole()]; + std::string dirname = Form("SummaryAll"); + std::string histname = Form("Q%i_detmap",hole); ////;channel;Charge/128.",hole); + std::string histname2 = Form("Q%i_detmap_led_2D",hole); ////;channel;Charge/128.",hole); + obj.FillHistogram(dirname,histname, + 160,0,160,hit.GetAbsSegId(), + 8000,0,64000,hit.Charge()); // int division done in the mode3hit class. + +// was + // 8000,0,32000,hit.Charge()); // int division done in the mode3hit class. + + //obj.FillHistogram(dirname,histname2, + // 160,0,160,hit.GetAbsSegId(), + // 1e6,1000,2000,hit.GetLed()/(1e9)); // previously 1e12 + + + //histname2 = Form("Q%i_detmap_led",hole); ////;channel;Charge/128.",hole); + //obj.FillHistogram(dirname,histname2, + // 20,0,20,hit.GetCrystal()*4 + hit.GetVME(), +// 8000,0,32000,hit.GetLed()); + + if(hit.GetChannel()%9==0) { + dirname = Form("SummaryCore"); + histname = Form("Q%i_cores",hole); ////;channel;Charge/128.",hole); + obj.FillHistogram(dirname,histname, + 20,0,20,hit.GetCrystal()*4 + hit.GetVME(), + 16000,0,64000,hit.Charge()); + + // histname2 = Form("Q%i_cores_led",hole); ////;channel;Charge/128.",hole); + // obj.FillHistogram(dirname,histname2, + // 20,0,20,hit.GetCrystal()*4 + hit.GetVME(), + // 2500,100000,200000,hit.GetLed()); + + histname2 = Form("Q%i_cores_led_2D",hole); ////;channel;Charge/128.",hole); + //obj.FillHistogram(dirname,histname2, + // 0.0000002,0,1000,hit.GetLed()/(1e12), + // 20,0,20,hit.GetCrystal()*4 + hit.GetVME()); + + // histname2 = Form("Q%i_cores_led_1D",hole); ////;channel;Charge/128.",hole); + // obj.FillHistogram(dirname,histname2, + // 200,34800,54800,hit.GetLed()/(1e7),64000,0,64000,hit.Charge()); + + //std::cout << "LED: " << hit.GetLed()/(1e12) << std::endl ; + + //obj.FillHistogram("DT1", + // 10000,0,10000,hit.GetDt1()); + + //obj.FillHistogram("DT2", + // 10000,0,10000,hit.GetDt2()); + } + + + if(TChannel::Size()) { + histname = Form("Q%i_cal",hole); ////;channel;Charge/128.",hole); + obj.FillHistogram(dirname,histname, + 160,0,160,hit.GetAbsSegId(), + 5000,0,10000,hit.GetEnergy()); + if(hit.GetChannel()%9==0) { + histname = Form("Q%i_cores",hole); ////;channel;Charge/128.",hole); + obj.FillHistogram(histname, + 20,0,20,hit.GetCrystal()*4 + hit.GetVME(), + 10000,0,10000,hit.GetEnergy()); + + + //if(hit.GetVME()==2) { //2.5 MeV channel + // if(hit.GetDt1()>0) { + // histname = Form("Q%i_2MeV_Energy_vs_d1",hole); ////;channel;Charge/128.",hole); + // obj.FillHistogram(dirname,histname, + // 2000,0,2000,hit.GetEnergy(), + +/* 2000,0,2000,hit.GetDt1());}} + if(hit.GetVME()==1) { //check1 + if(hit.GetDt1()>0) { + histname = Form("Q%i_check1_Energy_vs_d1",hole); ////;channel;Charge/128.",hole); + obj.FillHistogram(dirname,histname, + 2000,0,2000,hit.GetEnergy(), + 2000,0,2000,hit.GetDt1());}} + + if(hit.GetVME()==3) { //check2 + if(hit.GetDt1()>0) { + histname = Form("Q%i_check2_Energy_vs_d1",hole); ////;channel;Charge/128.",hole); + obj.FillHistogram(dirname,histname, + 2000,0,2000,hit.GetEnergy(), + 2000,0,2000,hit.GetDt1());}} + + if(hit.GetVME()==4) { //check3 + if(hit.GetDt1()>0) { + histname = Form("Q%i_check3_Energy_vs_d1",hole); ////;channel;Charge/128.",hole); + obj.FillHistogram(dirname,histname, + 2000,0,2000,hit.GetEnergy(), + 2000,0,2000,hit.GetDt1());}} +*/ + + //} + // if(hit.GetDt2()>0) { + // histname = Form("Q%i_2MeV_Energy_vs_d2",hole); ////;channel;Charge/128.",hole); + // obj.FillHistogram(dirname,histname, + // 2000,0,2000,hit.GetEnergy(), + // 2000,0,2000,hit.GetDt2()); + // } + //} + + + } + + } + } + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistos_e17001.cxx b/histos/MakeHistos_e17001.cxx new file mode 100644 index 00000000..cf546b58 --- /dev/null +++ b/histos/MakeHistos_e17001.cxx @@ -0,0 +1,413 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TOBJ.h" +#include "TFastScint.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" +#include "TChain.h" + +std::vector incoming_cuts ; +std::vector outgoing_cuts ; +std::vector tofcuts ; +std::vector pidcuts; +std::vector tmppidcuts; +int gates_loaded=0; + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 9 +#define Q10 6 +#define Q11 19 +//#define Q12 20 + +#define BETA .36 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + +void CheckDAQCorrelation(TRuntimeObjects& obj){ + + TGretina *gretina = obj.GetDetector(); + TBank88 *bank88 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + + std::string dirname = "DAQ_Correlation"; + + // Check tdiff between different DAQsys + if(bank88&&s800){ + obj.FillHistogram(dirname,"tdiff_bank88_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-bank88->GetTimestamp()); + } + if(bank88&&gretina){ + obj.FillHistogram(dirname,"tdiff_bank88_gretina",3600,0,7200,bank88->GetTimestamp(),1000,-2000,2000,gretina->GetGretinaHit(0).Timestamp()-bank88->GetTimestamp()); + } + if(obj_sci&&s800){ + obj.FillHistogram(dirname,"tdiff_ddas_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-obj_sci->GetOBJHit(0).GetExternalTimestamp()*8); + } + if(s800&&gretina){ + obj.FillHistogram(dirname,"tdiff_s800_gretina",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-gretina->GetGretinaHit(0).Timestamp()); + } + if(obj_sci&&gretina){ + obj.FillHistogram(dirname,"tdiff_gretina_ddas",3600,0,7200,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8/1e8,1000,-2000,2000,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8-gretina->GetGretinaHit(0).Timestamp()); + } + + // Check tdiff between differnent DAQ sys with different triggers + if(s800 && s800->GetTrigger().GetRegistr() <100 && s800->GetTrigger().GetRegistr()>0){ + TString dirname = Form("DAQ_Correlation_trigger_%d",s800->GetTrigger().GetRegistr()); + if(bank88&&s800){ + obj.FillHistogram(dirname,"tdiff_bank88_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-bank88->GetTimestamp()); + } + if(bank88&&gretina){ + obj.FillHistogram(dirname,"tdiff_bank88_gretina",3600,0,7200,bank88->GetTimestamp(),1000,-2000,2000,gretina->GetGretinaHit(0).Timestamp()-bank88->GetTimestamp()); + } + if(obj_sci&&s800){ + obj.FillHistogram(dirname,"tdiff_ddas_s800",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-obj_sci->GetOBJHit(0).GetExternalTimestamp()*8); + } + if(s800&&gretina){ + obj.FillHistogram(dirname,"tdiff_s800_gretina",3600,0,7200,s800->GetTimestamp()/1e8,1000,-2000,2000,s800->GetTimestamp()-gretina->GetGretinaHit(0).Timestamp()); + } + if(obj_sci&&gretina){ + obj.FillHistogram(dirname,"tdiff_gretina_ddas",3600,0,7200,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8/1e8,1000,-2000,2000,obj_sci->GetOBJHit(0).GetExternalTimestamp()*8-gretina->GetGretinaHit(0).Timestamp()); + } + } +} + + + +/* + +------------------------------ +GRETINA +------------------------------ + +*/ + + +void MonitorOBJScintillator_DDAS(TRuntimeObjects &obj){ + TOBJ *obj_sci = obj.GetDetector(); + if(obj_sci){ + std::string dirname = "OBJSci"; + for(size_t x = 0; xSize();x++){ + auto objhit = obj_sci->GetOBJHit(x); + obj.FillHistogram(dirname,"Energy_of_OBJSci",1000,0,40000,objhit.GetEnergy()); + if(objhit.GetPileup()){ + obj.FillHistogram(dirname,"Energy_of_OBJSci_Pileup",1000,0,40000,objhit.GetEnergy()); + }else{ + obj.FillHistogram(dirname,"Energy_of_OBJSci_noPileup",1000,0,40000,objhit.GetEnergy()); + } + + } + } + +} + +void MonitorCrdcs(TRuntimeObjects& obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "CRDC_Det"; + auto crdc1 = s800->GetCrdc(0); + auto crdc2 = s800->GetCrdc(1); + Double_t crdc1_x = crdc1.GetDispersiveX(); + Double_t crdc1_y = crdc1.GetNonDispersiveY(); + Double_t crdc2_x = crdc2.GetDispersiveX(); + Double_t crdc2_y = crdc2.GetNonDispersiveY(); + + obj.FillHistogram(dirname,"Crdc1_xy",800,-400,400,crdc1_x,800,-400,400,crdc1_y); + obj.FillHistogram(dirname,"Crdc2_xy",800,-400,400,crdc2_x,800,-400,400,crdc2_y); + + obj.FillHistogram(dirname,"Crdc1_time_ts",3600,0,7200,s800->Timestamp()/1e8,500,-2000,5000,crdc1.GetTime()); + obj.FillHistogram(dirname,"Crdc2_time_ts",3600,0,7200,s800->Timestamp()/1e8,500,-2000,5000,crdc2.GetTime()); + obj.FillHistogram(dirname,"Crdc1_anode_ts",3600,0,7200,s800->Timestamp()/1e8,500,-2000,5000,crdc1.GetAnode()); + obj.FillHistogram(dirname,"Crdc2_anode_ts",3600,0,7200,s800->Timestamp()/1e8,500,-2000,5000,crdc2.GetAnode()); + obj.FillHistogram(dirname,"Crdc1_anode_time",500,-2000,5000,crdc1.GetAnode(),500,-2000,5000,crdc1.GetTime()); + obj.FillHistogram(dirname,"Crdc2_anode_time",500,-2000,5000,crdc2.GetAnode(),500,-2000,5000,crdc2.GetTime()); + + obj.FillHistogram(dirname,"E1_ts",3600,0,7200,s800->Timestamp()/1e8,1000,0,70000,s800->GetMTof().GetCorrelatedE1Up()); + + if(s800 && s800->GetTrigger().GetRegistr() <100 && s800->GetTrigger().GetRegistr()>0){ + TString histname = Form("crdc1_anode_time_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),500,-2000,5000,crdc1.GetAnode(),500,-2000,5000,crdc1.GetTime()); + histname = Form("crdc2_anode_time_%d",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname.Data(),500,-2000,5000,crdc2.GetAnode(),500,-2000,5000,crdc2.GetTime()); + } + +} + + +void MonitorICs(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "ION_Chamber"; + auto ic = s800->GetIonChamber(); + for(int x = 0; xGetCrdc(0); + obj.FillHistogram(dirname,"ICEnergy_crdc1x",800,-400,400,crdc1.GetDispersiveX(),1000,0,4000,ic.GetSum()); + obj.FillHistogram(dirname,"ICAVEnergy_crdc1x",800,-400,400,crdc1.GetDispersiveX(),1000,0,4000,ic.GetAve()); + obj.FillHistogram(dirname,"ICEnergy_crdc1y",800,-400,400,crdc1.GetNonDispersiveY(),1000,0,4000,ic.GetSum()); + obj.FillHistogram(dirname,"ICAVEnergy_crdc1y",800,-400,400,crdc1.GetNonDispersiveY(),1000,0,4000,ic.GetAve()); + obj.FillHistogram(dirname,"ICAVEnergy_ts",3600,0,7200,s800->Timestamp()/1e8,1000,0,4000,ic.GetAve()); +} + +void OutgoingPID(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "OUT_PID"; + auto ic = s800->GetIonChamber(); + auto crdc1 = s800->GetCrdc(0); + obj.FillHistogram(dirname,"TOF-dE",2000,-2000,0,s800->GetCorrTOF_OBJ_MESY(0),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + obj.FillHistogram(dirname,"dE-Crdc1x",800,-400,400,crdc1.GetDispersiveX(),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + + /* + auto obj_sci = obj.GetDetector(); + if(!obj_sci) return; + if(tmppidcuts.at(0)->IsInside(s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),obj_sci->GetOBJHit(0).GetEnergy())){ + obj.FillHistogram(dirname,"TOF-dE-gated-by-sci",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),4000,0,4000,ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY())); + } + */ +} + +void IncomingPID(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + if(!s800 || !obj_sci) return; + + std::string dirname = "INC_PID"; + for(size_t x = 0; xSize();x++) + obj.FillHistogram(dirname,"TOF-dE-Sci",4000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),10000,0,40000,obj_sci->GetOBJHit(x).GetEnergy()); + obj.FillHistogram(dirname,"TOF-dE-PIN",4000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(0),1000,0,4000,s800->GetPinE()); + + obj.FillHistogram(dirname,"TOF-dE-Sci-raw",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + obj.FillHistogram(dirname,"TOF-Obj-Rf-dE-Sci-raw",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetMRf(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + obj.FillHistogram(dirname,"TOF-xfp-Rf-dE-Sci-raw",4000,-10000,10000,s800->GetRawXF_MESY(0)-s800->GetMRf(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + obj.FillHistogram(dirname,"TOF-dE-PIN-raw",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); +/* + if(tmppidcuts.at(0)->IsInside(s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),obj_sci->GetOBJHit(0).GetEnergy())){ + obj.FillHistogram(dirname,"TOF-dE-PIN-raw-gated",4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); + } +*/ +} + +void MonitorTOF(TRuntimeObjects &obj){ + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "TOF_Packet"; + auto tof = s800->GetTof(); + obj.FillHistogram(dirname,"OBJ_TAC",4000,-2000,2000,tof.GetTacOBJ()); + obj.FillHistogram(dirname,"XFP_TAC",4000,-2000,2000,tof.GetTacXFP()); + obj.FillHistogram(dirname,"OBJ-XFP",4000,-2000,2000,tof.GetTacOBJ()-tof.GetTacXFP()); + obj.FillHistogram(dirname,"OBJ_vs_XFP",1000,-2000,2000,tof.GetTacOBJ(),1000,-2000,2000,tof.GetTacXFP()); + + auto mtof = s800->GetMTof(); + for(int x = 0; x < mtof.XfpSize(); x++) + for(int y = 0; y < mtof.E1UpSize();y++){ + obj.FillHistogram(dirname,"XFP-E1_Mesy",1000,-10000,10000,s800->GetRawXF_MESY(x)-s800->GetRawE1_MESY(y)); + obj.FillHistogram(dirname,"XFP-E1_Mesy_vs_AFP",3000,-4000,8000,s800->GetCorrTOF_XFP_MESY(x*y+y),1000,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"XFP-E1_Mesy_vs_XFP",3000,-4000,8000,s800->GetCorrTOF_XFP_MESY(x*y+y),1000,-400,400,s800->GetXFP()); + } + + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.E1UpSize();y++){ + obj.FillHistogram(dirname,"OBJ-E1_Mesy",1000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawE1_MESY(y)); + obj.FillHistogram(dirname,"OBJ-E1_Mesy_vs_AFP",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(x*y+y),1000,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"OBJ-E1_Mesy_vs_XFP",2000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(x*y+y),1000,-400,400,s800->GetXFP()); + } + + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.XfpSize();y++){ + obj.FillHistogram(dirname,"XFP-OBJ_Mesy",1000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y)); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_AFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),100,-0.1,0.1,s800->GetAFP()); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_BFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),100,-0.1,0.1,s800->GetBFP()); + obj.FillHistogram(dirname,"XFP-OBJ_Mesy_vs_XFP",2000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y),1000,-400,400,s800->GetXFP()); + } + obj.FillHistogram(dirname,"XFP_vs_OBJ_MESY",2000,27000,31000,mtof.GetCorrelatedObj(),2000,28000,36000,mtof.GetCorrelatedXfp()); + + + if(s800 && s800->GetTrigger().GetRegistr() <100 && s800->GetTrigger().GetRegistr()>0){ + TString histname = Form("XFP-OBJ_%d",s800->GetTrigger().GetRegistr()); + for(int x = 0; x < mtof.ObjSize(); x++) + for(int y = 0; y < mtof.XfpSize();y++){ + obj.FillHistogram(dirname,histname.Data(),1000,-10000,10000,s800->GetRawOBJ_MESY(x)-s800->GetRawXF_MESY(y)); + } + } +} + +void CountOBJ(TRuntimeObjects &obj){ + if(pidcuts.size()==0) return; + TS800 *s800 = obj.GetDetector(); + TOBJ *obj_sci = obj.GetDetector(); + if(!s800) return; + auto ic = s800->GetIonChamber(); + auto crdc1 = s800->GetCrdc(0); + double tof = s800->GetCorrTOF_OBJ_MESY(0); + double dE = ic.GetdE(crdc1.GetDispersiveX(),crdc1.GetNonDispersiveY()); + std::string dirname="Count_OBJ"; + for(size_t x = 0; xIsInside(tof,dE)){ + histname = Form("tof-dE_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,3000,-4000,8000,tof,4000,0,4000,dE); + } + } + if(!obj_sci) return; + auto mtof = s800->GetMTof(); + if(tofcuts.size()==1 && !(tofcuts.at(0)->IsInside(mtof.GetCorrelatedObj(),mtof.GetCorrelatedXfp()))) return; + + obj.FillHistogram(dirname,"tof-dE",3000,-4000,8000,tof,4000,0,4000,dE); + + std::string dirname2="Check_Mdis"; + for(size_t x = 0; xIsInside(tof,dE)){ + histname = Form("CRDC1_x_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname2,histname,800,-400,400,crdc1.GetDispersiveX()); + dirname2 = "INC_PID"; + histname = Form("TOF_dE_Sci_Raw_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,40000,obj_sci->GetOBJHit(0).GetEnergy()); + histname = Form("TOF_dE_Pin_Raw_%s",pidcuts.at(x)->GetName()); + obj.FillHistogram(dirname,histname,4000,-10000,10000,s800->GetRawOBJ_MESY(0)-s800->GetRawXF_MESY(0),1000,0,4000,s800->GetPinE()); + } + + } + if(!obj_sci) return; + for(size_t y = 0; y < pidcuts.size(); y++){ + + std::string histname; + if(pidcuts.at(y)->IsInside(tof,dE)){ + histname = Form("Energy_of_OBJSci_%s",pidcuts.at(y)->GetName()); + for(size_t x = 0; xSize();x++){ + double tdiff = s800->GetTimestamp()-obj_sci->GetOBJHit(x).GetExternalTimestamp()*8; + if(tdiff>20&&tdiff<60) + obj.FillHistogram(dirname,histname,1000,0,40000,obj_sci->GetOBJHit(x).GetEnergy()); + } + } + } + +} + +void MonitorPin(TRuntimeObjects &obj){ + + TS800 *s800 = obj.GetDetector(); + if(!s800) return; + + std::string dirname = "PIN"; + obj.FillHistogram(dirname,"Pin_energy",4000,0,4000,s800->GetPinE()); +} + +void LoadGates(TRuntimeObjects &obj){ + TList *gates = &(obj.GetGates()); + if(!gates||gates->GetSize()==0) return; + + if(gates_loaded!=gates->GetSize()){ + TIter iter(gates); + while(TObject *obj = iter.Next()){ + GCutG *gate = (GCutG*)obj; + std::string tag = gate->GetTag(); + std::cout<<"tag : "<(); + if(s800) + obj.FillHistogram("triggers",10,0,10,s800->GetTrigger().GetRegistr()); + + + return; + + +///////////////////////// + +} diff --git a/histos/MakeHistos_mode3.cxx b/histos/MakeHistos_mode3.cxx deleted file mode 100644 index 093a8590..00000000 --- a/histos/MakeHistos_mode3.cxx +++ /dev/null @@ -1,140 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TMode3.h" -#include "TBank29.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - - -//#define Q1 15 -//#define Q2 7 -//#define Q3 8 -//#define Q4 16 -//#define Q5 9 -//#define Q6 14 -//#define Q7 17 -//#define Q8 6 -//#define Q9 19 - -//quads moved July 2016. -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 //actually at lbl -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - - - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -bool map_inited=false; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - //TGretina *gretina = obj.GetDetector(); - TMode3 *mode3 = obj.GetDetector(); - //TBank29 *bank29 = obj.GetDetector(); - TList *list = &(obj.GetObjects()); - - int numobj = list->GetSize(); - if(!mode3) - return; - - for(unsigned int x=0;xSize();x++) { - TMode3Hit hit = mode3->GetMode3Hit(x); - int hole = HoleQMap[hit.GetHole()]; - std::string dirname = Form("SummaryAll"); - std::string histname = Form("Q%i_detmap",hole); ////;channel;Charge/128.",hole); - obj.FillHistogram(dirname,histname, - 160,0,160,hit.GetAbsSegId(), - 4000,0,32000,hit.Charge()); // int division done in the mode3hit class. - - if(hit.GetChannel()%9==0) { - dirname = Form("SummaryCore"); - histname = Form("Q%i_cores",hole); ////;channel;Charge/128.",hole); - obj.FillHistogram(dirname,histname, - 20,0,20,hit.GetCrystal()*4 + hit.GetVME(), - 4000,0,32000,hit.Charge()); - } - - - if(TChannel::Size()) { - histname = Form("Q%i_cal",hole); ////;channel;Charge/128.",hole); - obj.FillHistogram(dirname,histname, - 160,0,160,hit.GetAbsSegId(), - 4000,0,4000,hit.GetEnergy()); - if(hit.GetChannel()%9==0) { - histname = Form("Q%i_cores",hole); ////;channel;Charge/128.",hole); - obj.FillHistogram(histname, - 20,0,20,hit.GetCrystal()*4 + hit.GetVME(), - 4000,0,4000,hit.GetEnergy()); - //if(hit.GetVME()==2) { //2.5 MeV channel - // if(hit.GetDt1()>0) { - // histname = Form("Q%i_2MeV_Energy_vs_d1",hole); ////;channel;Charge/128.",hole); - // obj.FillHistogram(dirname,histname, - // 2000,0,2000,hit.GetEnergy(), - // 2000,0,2000,hit.GetDt1()); - // } - // if(hit.GetDt2()>0) { - // histname = Form("Q%i_2MeV_Energy_vs_d2",hole); ////;channel;Charge/128.",hole); - // obj.FillHistogram(dirname,histname, - // 2000,0,2000,hit.GetEnergy(), - // 2000,0,2000,hit.GetDt2()); - // } - //} - - - } - - } - } - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistos_test_lee.cxx b/histos/MakeHistos_test_lee.cxx new file mode 100644 index 00000000..cba9f6ad --- /dev/null +++ b/histos/MakeHistos_test_lee.cxx @@ -0,0 +1,780 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TFastScint.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" +#include "TChain.h" + +std::vector incoming_cuts = {0}; +std::vector outgoing_cuts = {0}; +std::vector time_energy_cuts = {0}; +int gates_loaded=0; + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 9 +#define Q10 6 +#define Q11 19 +//#define Q12 20 + +#define BETA .39 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + +/* + +------------------------------ +INCOMING (to be done if XFP used) +------------------------------ + +*/ + + +bool IncomingBeam(TRuntimeObjects& obj,GCutG *outgoing) { + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge())) + return false; + } + + std::string dirname; + if(outgoing) + dirname = Form("incoming_%s",outgoing->GetName()); + else + dirname = "incoming"; + + std::string histname; + //TMTof &mtof = s800->GetMTof(); + unsigned int reg = s800->GetReg(); + + histname = "OBJ_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()); + histname = "XFP_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacXFP()); + + histname = "OBJ_TAC-XFP_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + + histname = "OBJ_TAC_XFP_TAC_2D"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJTAC(),4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); + + if(reg&1) { + histname = "OBJ_TAC-XFP_TAC_Reg1"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + } + + + if(reg&2) { + histname = "OBJ_TAC-XFP_TAC_Reg2"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + } + + /* + histname = "Obj_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTOF_ObjE1()); + histname = "Obj_Rf"; + obj.FillHistogram(dirname,histname,8000,-3200,32000,s800->GetMTOF_ObjRf()); + histname = "Xfp_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTOF_XfpE1()); + histname = "Rf_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,64000,s800->GetMTOF_RfE1()); + + histname = "obj_rf_2d"; + obj.FillHistogram(dirname,histname,1600,-8000,0,s800->GetMTOF_ObjE1(), + 1600,-24000,-16000,s800->GetMTOF_RfE1()); + */ + + //histname = "obj_xfp_2d"; + //obj.FillHistogram(dirname,histname,800,0,64000,s800->GetMTOF_ObjE1(), + // 800,0,64000,s800->GetMTOF_XfpE1()); + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0; j<16; j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname,histname,20,0,20,j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname,histname,20,0,20,s800->GetTrigger().GetRegistr()); + + return true; +} + +/* + +------------------------------ +OUTGOING +------------------------------ + +*/ + +bool OutgoingBeam(TRuntimeObjects& obj,GCutG *incoming) { + TS800 *s800 = obj.GetDetector(); + + double objtime1 = s800->GetTof().GetOBJ(); + double xfptime1 = s800->GetTof().GetXFP(); + //double yfp1 = s800->GetYFP(0) ; + //double ic_sum = s800->GetIonChamber().GetAve(); + +// double obj_corr = s800->GetCorrTOF_OBJ(); +// double ic_sum = s800->GetIonChamber().GetAve(); + + if(!s800) + return false; + + std::string dirname; + if(incoming) + dirname = Form("outgoing_%s",incoming->GetName()); + else + dirname = "outgoing"; + +// if(incoming) { +// if(!incoming->IsInside(s800->GetMTOF_ObjE1(),s800->GetMTOF_RfE1())) +// return false; +// } + + + std::string histname; + TIonChamber ion = s800->GetIonChamber(); + histname = "ion_summary"; + for(int i=0; iGetEventCounter()); + +// histname = "Event_Counter_vs_Timestamp"; +// obj.FillHistogram(dirname,histname,7200,0,7200,s800->GetTimestamp()*1e-8,1e+7,0,1e+7,s800->GetEventCounter()); + + + histname = "IC_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 1000,0,2000,s800->GetCorrTOF_OBJTAC(), + 1000,0,2000,s800->GetIonChamber().GetAve()); + + obj.FillHistogram(dirname,"IC_dE_vs_OBJC", + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + double crdc1 = s800->GetCrdc(0).GetDispersiveX(); + + histname = "IC_Sum"; + obj.FillHistogram(dirname,histname,1000,0,2000,s800->GetIonChamber().GetAve()); + + histname = "IC_dE"; + obj.FillHistogram(dirname,histname,1000,0,5000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "CRDC1_X_vs_ICdE_Corr"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX(), + 5000,0,5000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "CRDC1_Y_vs_Time"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetNonDispersiveY(), + 3600,0,3600,s800->Timestamp()*1e-8); + + histname = "CRDC1_Time_vs_Timestamp"; + obj.FillHistogram(dirname,histname,1000,-2000,2000,s800->GetCrdc(0).GetTime(),3600,0,3600,s800->Timestamp()*1e-8); + + + //histname = "CRDC1_Pad"; + //obj.FillHistogram(dirname,histname,256,0,256,s800->GetCrdc(0).GetPad()); + + + + + histname = "CRDC1_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); + + histname = "CRDC1_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + + histname = "CRDC2_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(1).GetNonDispersiveY()); + + obj.FillHistogram(dirname,"CRDC1", + 800,-400,400,s800->GetCrdc(0).GetDispersiveX(), + 4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + + obj.FillHistogram(dirname,"CRDC2", + 8000,-400,400,s800->GetCrdc(1).GetDispersiveX(), + 4000,-2000,2000,s800->GetCrdc(1).GetNonDispersiveY()); + + //histname = "OBJ"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetOBJ()); + + //histname = "OBJ_Mesy"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetRawOBJ_MESY()); + + int ObjSize = s800->GetMTof().ObjSize(); + int XfpSize = s800->GetMTof().XfpSize(); + int E1UpSize = s800->GetMTof().E1UpSize(); + + for(int i=0; iGetMTof().fObj.at(i)-s800->GetMTof().fE1Up.at(j)); + } + } + + for(int i=0; iGetMTof().fXfp.at(i)-s800->GetMTof().fE1Up.at(j)); + } + } + + histname = "OBJ_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedObjE1()); + + histname = "OBJ_Corrected"; + obj.FillHistogram(dirname,histname,1200,-60000,60000,s800->GetCorrTOF_OBJ_MESY()); + + histname = "OBJ_MESY_vs_Timestamp"; + obj.FillHistogram(dirname,histname,4000,-20000,20000,s800->GetMTof().GetCorrelatedObjE1(),3600,0,3600,s800->Timestamp()*1e-8); + + histname = "XFP_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + histname = "XFP_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + histname = "XFPE1-OBJE1_OBJCorr_Correlation"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY()); + + if(s800->Timestamp()*1e-8>400) { + histname = "XFPE1-OBJE1_OBJCorr_Correlation_withclosedslits"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY()); + } + + if(s800->Timestamp()*1e-8<400) { + histname = "XFPE1-OBJE1_OBJCorr_Correlation_withopenslits"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY()); + } + + histname = "XFP_MESY_vs_Timestamp"; + obj.FillHistogram(dirname,histname,4000,-20000,20000,s800->GetMTof().GetCorrelatedXfpE1(),3600,0,3600,s800->Timestamp()*1e-8); + + + obj.FillHistogram(dirname,"IC_dE_vs_OBJCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + obj.FillHistogram(dirname,"IC_dE_vs_XFPCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_XFP_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + histname = "AFP_vs_OBJC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-20000,20000,s800->GetCorrTOF_OBJ_MESY()); // check units of AFP + + histname = "XFP_vs_OBJC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-20000,20000,s800->GetCorrTOF_OBJ_MESY()); + + histname = "AFP_vs_XFPC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-20000,20000,s800->GetCorrTOF_XFP_MESY()); // check units of AFP + + histname = "XFP_vs_XFPC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-20000,20000,s800->GetCorrTOF_XFP_MESY()); + + histname = "E1_vs_OBJ"; + obj.FillHistogram(dirname,histname, + 6000,-30000,30000,s800->GetMTof().GetCorrelatedE1Up(), + 6000,-30000,30000,s800->GetMTof().GetCorrelatedObjE1()); + + + histname = "OBJ_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()); + + histname = "OBJ_TAC_Corr"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); + + histname = "OBJ_ToFE1_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTofE1_TAC()); + + //histname = "RF"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetRF()); + + histname = "OBJ_Corr"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJ()); + + histname = "XFP_TAC_ICdE"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_XFPTAC(),4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + histname = "Time_E1Up"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetScint().GetTimeUp()); + + histname = "AFP_vs_OBJTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); // check units of AFP + + histname = "XFP_vs_OBJTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); + + + histname = "AFP_vs_XFPTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); // check units of AFP + + histname = "XFP_vs_XFPTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); + + /* + histname = "AFP_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 1000,0,1000,obj_corr); // check units of AFP + + histname = "XFP_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(0), + 1000,0,1000,obj_corr); + */ + + + return true; +} + + + +/* + +------------------------------ +GRETINA +------------------------------ + +*/ + + +bool HandleGretinaGated(TRuntimeObjects &obj, GCutG *outgoing) { + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TBank88 *bank29 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname; + std::string histname; + + if(outgoing) + dirname = Form("gretina_%s",outgoing->GetName()); + else + dirname = "gretina"; +//std::cout << "Gate name: " << time_energy->GetName() << std::endl ; + + //histname = Form("gretina_%s",time->GetName()); + + for(unsigned int i=0; iSize(); i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + + obj.FillHistogram(dirname,"DetNumber_vs_Timestamp", + 80,0,80,hit.GetCrystalId(), + 3600,0,3600,s800->Timestamp()*1e-8); + + if(hit.GetPad()==0) { + histname="position_good_Decomp"; + obj.FillHistogram(histname,360,0,360,hit.GetThetaDeg(), + 360,0,360,hit.GetPhiDeg()); + } + /* + for(unsigned int j=i+1;jSize();j++) { + TGretinaHit hit2 = gretina->GetGretinaHit(j); + + histname ="timediff_hit_hit2"; + obj.FillHistogram(histname,7200,0,7200,hit.GetTime()*1e-8,7200,0,1000,hit2.GetTime()*1e-8); + + //std::cout << "hit1:" << hit.GetTime()*1e-8 << "hit2:" << hit2.GetTime()*1e-8 << std::endl ; + + + //histname = "CoreEnergy_Doppler_gg"; + // obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetDoppler(GValue::Value("BETA")), + // 2000,0,4000,hit2.GetDoppler(GValue::Value("BETA"))); + //histname = "CoreEnergy_Doppler_gg"; + // obj.FillHistogram(dirname,histname,2000,0,4000,hit2.GetDoppler(GValue::Value("BETA")), + // 2000,0,4000,hit.GetDoppler(GValue::Value("BETA"))); + + } + */ + + + double time_diff = s800->Timestamp()-hit.GetTime() ; + double energy = hit.GetCoreEnergy(); + unsigned int reg = s800->GetReg(); + int hole = HoleQMap[hit.GetHoleNumber()]; + + + + +// obj.FillHistogram(dirname,"IC_dE_vs_OBJC", +// 400,1100,1500,s800->GetCorrTOF_OBJTAC(), +// 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + obj.FillHistogram(dirname,"IC_dE_vs_OBJCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "Gretina_S800_time"; + obj.FillHistogram(dirname,histname,1200,-600,600,time_diff, + 2000,0,4000,hit.GetCoreEnergy()); + + histname = "Gretina_S800_CoreEnergy"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + histname = "Pad"; + obj.FillHistogram(dirname,histname,361,-1,360,hit.GetPad()); + /* + if(hole!=0){ + histname = Form("Gretina_CoreEnergy_Cry%02i_Det%02i",hit.GetCrystalId(),hole); + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + for(int j=0;j<4;j++){ + histname = Form("Cores_charge_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(dirname,histname,4,0,4,j,16000,0,64000,hit.GetCoreCharge(j)); + } + + } + */ + + /* + if(bank29) { + histname = Form("Gretina_Bank88_TD"); + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + + if(reg&2){ + histname = Form("Gretina_Bank88_TD_Reg2"); + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + + histname = Form("Gretina_Bank88_TD_Reg2_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + + } + + if(reg&1){ + histname = Form("Gretina_Bank88_TD_Reg1_Cry%02i",hit.GetCrystalId()); + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-hit.GetTime(), + 5000,0,10000,hit.GetCoreEnergy()); + } + + } + + if(bank29 && s800){ + + if(reg&2){ + histname = Form("S800_Bank88_TD-Energy_Reg2"); + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-s800->Timestamp(), + 5000,0,10000,hit.GetCoreEnergy());} + + if(reg&1){ + histname = Form("S800_Bank88_TD-Energy_Reg1"); + obj.FillHistogram(histname,600,-600,600,bank29->Timestamp()-s800->Timestamp(), + 5000,0,10000,hit.GetCoreEnergy()); + }} + */ + + if(outgoing) { + + if(outgoing->IsInside(s800->GetCorrTOF_OBJTAC(), + s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY()))) { + +//if(outgoing->IsInside(s800->GetCorrTOF_RF_MESY(), +//s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY()))){ + + + histname = "Gretina_S800_CoreEnergy_wCut"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + /* + obj.FillHistogram(dirname,"IC_dE_vs_RfCorrE1_wCut", + 6000,16000,22000,s800->GetCorrTOF_RF_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + */ + + + obj.FillHistogram(dirname,"IC_dE_vs_CorrOBJTAC_wCut", + 2000,0,2000,s800->GetCorrTOF_OBJTAC(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + histname = "Gretina_S800_CoreEnergy_Doppler"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetDoppler(GValue::Value("BETA"))); + + + obj.FillHistogram(dirname,"summary_Doppler",10000,0,10000,hit.GetDoppler(GValue::Value("BETA")), + 200,0,200,hit.GetCrystalId()); + + } //gate (real) + + + if(outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY()))) { + + + obj.FillHistogram(dirname,"IC_dE_vs_OBJCorrE1_Mesy_wCut", + 8000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "Gretina_S800_CoreEnergy_Doppler_wMesyCut"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetDoppler(GValue::Value("BETA"))); + + histname = "CRDC1_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC1_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + + } + + + if(outgoing->IsInside(time_diff,hit.GetCoreEnergy())) { + + histname = "Gretina_S800_CoreEnergy_wCut_fakedtime"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + histname = "Gretina_S800_time_wfaketimecut"; + obj.FillHistogram(dirname,histname,1200,-600,600,time_diff, + 2000,0,4000,hit.GetCoreEnergy()); + + + if(s800->GetScint().GetEUp()>1400 && s800->GetScint().GetEUp()<1850) { + histname = "Gretina_S800_CoreEnergy_wCut_fakedtime_and_energy"; + obj.FillHistogram(dirname,histname,2000,0,4000,hit.GetCoreEnergy()); + + } + + } //gate (faked time gate) + + } //outgoing + +//if(time_energy->IsInside(hit.GetCoreEnergy(),time_diff)){ + +//if(time_diff>260 && time_diff<300){ + + if(s800 && gretina) { + obj.FillHistogram(dirname,"E1Up_Singles_inGretina",2000,0,2000,s800->GetScint().GetEUp()) ; + } + + + } + return true; +} + + + +//////////////////////////// +/* + +--------------------------------------- +Histograms are made. Gates are loaded. +--------------------------------------- + +*/ +//////////////////////////// + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + + + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank88 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + TList *gate_list = obj.GetGatesPtr(); + if(gate_list->GetSize() > 0){ + } + + //*************** s800 *********************// + if(s800) { + + float x0 = s800->GetXFP(0); + float x1 = s800->GetXFP(1); + float y0 = s800->GetYFP(0); + float y1 = s800->GetYFP(1); + float afp = s800->GetAFP(); + + if( !(std::isnan(x0) || std::isnan(x1) || std::isnan(y0) || std::isnan(y1) ) ) { + std::string dirname = "outgoing"; + obj.FillHistogram(dirname,"crdc1_pos",1000,-1000,1000,x0,200,-100,100,y0); + obj.FillHistogram(dirname,"crdc2_pos",1000,-1000,1000,x1,200,-100,100,y1); + + obj.FillHistogram(dirname,"crdc1_x_distri",1000,-1000,1000,x0); + obj.FillHistogram(dirname,"crdc1_y_distri",200,-100,100,y0); + obj.FillHistogram(dirname,"crdc2_x_distri",1000,-1000,1000,x1); + obj.FillHistogram(dirname,"crdc2_y_distri",200,-100,100,y1); + + float x_slope = (x1-x0)/100.; + float y_slope = (y1-y0)/100.; + + for(int i = 0; i<100; i++) { + obj.FillHistogram(dirname,"trace_x",100,-50,50,i+1-50,1000,-1000,1000,x0+x_slope*(i+1)); + obj.FillHistogram(dirname,"trace_y",100,-50,50,i+1-50,1000,-1000,1000,y0+y_slope*(i+1)); + } + + // pid tof-de + + float tof_obj_tac = s800->GetCorrTOF_OBJTAC(); + float dE = s800->GetIonChamber().GetdE(x0,y0); + float tof_obj_mesy = s800->GetCorrTOF_OBJ_MESY(0); // 0 1st hit + if (!( std::isnan(dE)) ) { + obj.FillHistogram(dirname,"dE",1000,0,2000,dE); + if(!std::isnan(tof_obj_tac)){ + obj.FillHistogram(dirname,"pid_tof_obj_tac_dE",500,1000,1500,tof_obj_tac,1000,200,1200,dE); + obj.FillHistogram(dirname,"tof_obj_tac",1000,-3000,3000,tof_obj_tac); + obj.FillHistogram(dirname,"tof_obj_tac_crdc1x_2d",1000,-1000,1000,x0,1000,-3000,3000,tof_obj_tac); + obj.FillHistogram(dirname,"tof_obj_tac_afp_2d",1000,-1,1,afp,1000,-3000,3000,tof_obj_tac); + } + if( ! (std::isnan(tof_obj_mesy))){ + obj.FillHistogram(dirname,"PID_tof_obj_mesy_dE",500,-2500,-1500,tof_obj_mesy,1000,200,1200,dE); + obj.FillHistogram(dirname,"tof_obj_mesy",1000,-3000,3000,tof_obj_mesy); + obj.FillHistogram(dirname,"tof_obj_mesy_crdc1x_2d",1000,-1000,1000,x0,2000,-4000,4000,tof_obj_mesy); + obj.FillHistogram(dirname,"tof_obj_mesy_afp_2d",1000,-1,1,afp,2000,-4000,4000,tof_obj_mesy); + } + } + + + } + + } + //******************* S800 *************************// + + //******************* Gretina **********************// + + if(gretina){ + std::string dirname = "gretina" ; + std::string histname; + + for (size_t i = 0 ; iSize(); i++){ + TGretinaHit hit = gretina->GetGretinaHit(i); + int cry_id = hit.GetCrystalId(); + int hole_num = hit.GetHoleNumber(); + dirname = "gretina_energy"; + // cry_id vs energy, check the CC calibration + obj.FillHistogram(dirname,"core_cryid_2d",4000,0,4000,hit.GetCoreEnergy(),128,0,128,cry_id); + // check pad distribution, too many pad hits larger than 0 indicates problem + obj.FillHistogram(dirname,"cry_id_pad",128,0,128,cry_id,210,-10,200,hit.GetPad()); + if(hit.GetPad()!=0) continue; + histname = TString::Format("cyrstal_segenergy_Q%02d_x%02d",HoleQMap[hole_num],cry_id); + std::string histname_geo,histname_time; + histname_geo = TString::Format("cry_xy_Q%02d_x%02d",HoleQMap[hole_num],cry_id); + histname_time = TString::Format("cry_tdiff_Q%02d_x%02d",HoleQMap[hole_num],cry_id); + + if(s800) { + // for some reason, the Toffset is not correctly set, so we only rely one timestamp difference + //obj.FillHistogram("gretia_time","gretina_s800_tdiff",2000,-1000,1000,hit.GetTFit()+hit.GetTime()-s800->Timestamp(),128,0,128,cry_id); + obj.FillHistogram("gretia_time","gretina_s800_tdiff_ts",2000,-1000,1000,hit.GetTime()-s800->Timestamp(),128,0,128,cry_id); + } + + + for ( int j = 0; j < hit.NumberOfInteractions(); j++){ + // Check segment energy calibration for each xtal + dirname = "gretina_energy"; + //obj.FillHistogram(dirname,histname,40,0,40,hit.GetSegmentId(j),4000,0,4000,hit.GetSegmentEner(j)); + obj.FillHistogram(dirname,histname,40,0,40,hit.GetSegmentId(j),4000,0,4000,hit.GetIntPreampEng(j)); + double phi = hit.GetIntPosition(j).Phi()*TMath::RadToDeg(); + if(phi < 0) phi += 360; + // check the hit pattern, one way to check whether decomp works well + dirname = "gretina_geo"; + obj.FillHistogram(dirname,"hit_pattern",360,0,360,hit.GetIntPosition(j).Theta()*TMath::RadToDeg(),360,0,360,phi); + obj.FillHistogram(dirname,histname_geo,200,-500,500,hit.GetIntPosition(j).X(),200,-500,500,hit.GetIntPosition(j).Y()); + + } + } + } + + //******************* Gretina **********************// + + //******************* Bank 29 **********************// + if(bank29 && s800) { + static bool tflag = true; + Long64_t ts_start = 0; + if(tflag){ + tflag = false; + ts_start = bank29->Timestamp(); + } + std::string dirname = "bank29"; + obj.FillHistogram(dirname,"bank29_s800_tdiff",1000,-1000,1000,bank29->Timestamp()-s800->Timestamp()); + obj.FillHistogram(dirname,"bank29_s800_tdiff_runtime",1000,0,5000,(bank29->Timestamp()-ts_start)/1e8, 1000,-1000,1000,bank29->Timestamp()-s800->Timestamp()); + } + //***************** Bank 29 **********************// + +} diff --git a/histos/MakeHistos_test_lee_mode3.cxx b/histos/MakeHistos_test_lee_mode3.cxx new file mode 100644 index 00000000..c684dc1e --- /dev/null +++ b/histos/MakeHistos_test_lee_mode3.cxx @@ -0,0 +1,444 @@ +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TBank88.h" +#include "TS800.h" +#include "TFastScint.h" + +#include "TChannel.h" +#include "GValue.h" +#include "GCutG.h" +#include "TChain.h" + +std::vector incoming_cuts = {0}; +std::vector outgoing_cuts = {0}; +std::vector time_energy_cuts = {0}; +int gates_loaded=0; + +//quads as of June 2019. +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 17 +#define Q9 9 +#define Q10 6 +#define Q11 19 +//#define Q12 20 + +#define BETA .39 + +std::map HoleQMap; +std::map LayerMap; + +bool map_inited=false; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + HoleQMap[Q11] = 11; +// HoleQMap[Q12] = 12; + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; +} + +/* + +------------------------------ +INCOMING (to be done if XFP used) +------------------------------ + +*/ + + +bool IncomingBeam(TRuntimeObjects& obj,GCutG *outgoing) { + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(outgoing) { + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge())) + return false; + } + + std::string dirname; + if(outgoing) + dirname = Form("incoming_%s",outgoing->GetName()); + else + dirname = "incoming"; + + std::string histname; + //TMTof &mtof = s800->GetMTof(); + unsigned int reg = s800->GetReg(); + + histname = "OBJ_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()); + histname = "XFP_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacXFP()); + + histname = "OBJ_TAC-XFP_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + + histname = "OBJ_TAC_XFP_TAC_2D"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJTAC(),4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); + + if(reg&1) { + histname = "OBJ_TAC-XFP_TAC_Reg1"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + } + + + if(reg&2) { + histname = "OBJ_TAC-XFP_TAC_Reg2"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()-s800->GetTof().GetTacXFP()); + } + + /* + histname = "Obj_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTOF_ObjE1()); + histname = "Obj_Rf"; + obj.FillHistogram(dirname,histname,8000,-3200,32000,s800->GetMTOF_ObjRf()); + histname = "Xfp_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTOF_XfpE1()); + histname = "Rf_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,64000,s800->GetMTOF_RfE1()); + + histname = "obj_rf_2d"; + obj.FillHistogram(dirname,histname,1600,-8000,0,s800->GetMTOF_ObjE1(), + 1600,-24000,-16000,s800->GetMTOF_RfE1()); + */ + + //histname = "obj_xfp_2d"; + //obj.FillHistogram(dirname,histname,800,0,64000,s800->GetMTOF_ObjE1(), + // 800,0,64000,s800->GetMTOF_XfpE1()); + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0; j<16; j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname,histname,20,0,20,j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname,histname,20,0,20,s800->GetTrigger().GetRegistr()); + + return true; +} + +/* + +------------------------------ +OUTGOING +------------------------------ + +*/ + +bool OutgoingBeam(TRuntimeObjects& obj,GCutG *incoming) { + TS800 *s800 = obj.GetDetector(); + + double objtime1 = s800->GetTof().GetOBJ(); + double xfptime1 = s800->GetTof().GetXFP(); + //double yfp1 = s800->GetYFP(0) ; + //double ic_sum = s800->GetIonChamber().GetAve(); + +// double obj_corr = s800->GetCorrTOF_OBJ(); +// double ic_sum = s800->GetIonChamber().GetAve(); + + if(!s800) + return false; + + std::string dirname; + if(incoming) + dirname = Form("outgoing_%s",incoming->GetName()); + else + dirname = "outgoing"; + +// if(incoming) { +// if(!incoming->IsInside(s800->GetMTOF_ObjE1(),s800->GetMTOF_RfE1())) +// return false; +// } + + + std::string histname; + TIonChamber ion = s800->GetIonChamber(); + histname = "ion_summary"; + for(int i=0; iGetEventCounter()); + +// histname = "Event_Counter_vs_Timestamp"; +// obj.FillHistogram(dirname,histname,7200,0,7200,s800->GetTimestamp()*1e-8,1e+7,0,1e+7,s800->GetEventCounter()); + + + histname = "IC_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 1000,0,2000,s800->GetCorrTOF_OBJTAC(), + 1000,0,2000,s800->GetIonChamber().GetAve()); + + obj.FillHistogram(dirname,"IC_dE_vs_OBJC", + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + double crdc1 = s800->GetCrdc(0).GetDispersiveX(); + + histname = "IC_Sum"; + obj.FillHistogram(dirname,histname,1000,0,2000,s800->GetIonChamber().GetAve()); + + histname = "IC_dE"; + obj.FillHistogram(dirname,histname,1000,0,5000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "CRDC1_X_vs_ICdE_Corr"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX(), + 5000,0,5000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + histname = "CRDC1_Y_vs_Time"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetNonDispersiveY(), + 3600,0,3600,s800->Timestamp()*1e-8); + + histname = "CRDC1_Time_vs_Timestamp"; + obj.FillHistogram(dirname,histname,1000,-2000,2000,s800->GetCrdc(0).GetTime(),3600,0,3600,s800->Timestamp()*1e-8); + + + //histname = "CRDC1_Pad"; + //obj.FillHistogram(dirname,histname,256,0,256,s800->GetCrdc(0).GetPad()); + + + + + histname = "CRDC1_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); + + histname = "CRDC1_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + + histname = "CRDC2_Y"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCrdc(1).GetNonDispersiveY()); + + obj.FillHistogram(dirname,"CRDC1", + 800,-400,400,s800->GetCrdc(0).GetDispersiveX(), + 4000,-2000,2000,s800->GetCrdc(0).GetNonDispersiveY()); + + obj.FillHistogram(dirname,"CRDC2", + 8000,-400,400,s800->GetCrdc(1).GetDispersiveX(), + 4000,-2000,2000,s800->GetCrdc(1).GetNonDispersiveY()); + + //histname = "OBJ"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetOBJ()); + + //histname = "OBJ_Mesy"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetRawOBJ_MESY()); + + int ObjSize = s800->GetMTof().ObjSize(); + int XfpSize = s800->GetMTof().XfpSize(); + int E1UpSize = s800->GetMTof().E1UpSize(); + + for(int i=0; iGetMTof().fObj.at(i)-s800->GetMTof().fE1Up.at(j)); + } + } + + for(int i=0; iGetMTof().fXfp.at(i)-s800->GetMTof().fE1Up.at(j)); + } + } + + histname = "OBJ_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedObjE1()); + + histname = "OBJ_Corrected"; + obj.FillHistogram(dirname,histname,1200,-60000,60000,s800->GetCorrTOF_OBJ_MESY()); + + histname = "OBJ_MESY_vs_Timestamp"; + obj.FillHistogram(dirname,histname,4000,-20000,20000,s800->GetMTof().GetCorrelatedObjE1(),3600,0,3600,s800->Timestamp()*1e-8); + + histname = "XFP_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + histname = "XFP_function"; + obj.FillHistogram(dirname,histname,8000,-40000,40000,s800->GetMTof().GetCorrelatedXfpE1()); + + histname = "XFPE1-OBJE1_OBJCorr_Correlation"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY()); + + if(s800->Timestamp()*1e-8>400) { + histname = "XFPE1-OBJE1_OBJCorr_Correlation_withclosedslits"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY()); + } + + if(s800->Timestamp()*1e-8<400) { + histname = "XFPE1-OBJE1_OBJCorr_Correlation_withopenslits"; + obj.FillHistogram(dirname,histname,600,3600,4200,s800->GetMTof().GetCorrelatedXfpE1()-s800->GetMTof().GetCorrelatedObjE1(),4000,-4000,0,s800->GetCorrTOF_OBJ_MESY()); + } + + histname = "XFP_MESY_vs_Timestamp"; + obj.FillHistogram(dirname,histname,4000,-20000,20000,s800->GetMTof().GetCorrelatedXfpE1(),3600,0,3600,s800->Timestamp()*1e-8); + + + obj.FillHistogram(dirname,"IC_dE_vs_OBJCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_OBJ_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + obj.FillHistogram(dirname,"IC_dE_vs_XFPCorrE1", + 8000,-4000,4000,s800->GetCorrTOF_XFP_MESY(), + 4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + histname = "AFP_vs_OBJC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-20000,20000,s800->GetCorrTOF_OBJ_MESY()); // check units of AFP + + histname = "XFP_vs_OBJC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-20000,20000,s800->GetCorrTOF_OBJ_MESY()); + + histname = "AFP_vs_XFPC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-20000,20000,s800->GetCorrTOF_XFP_MESY()); // check units of AFP + + histname = "XFP_vs_XFPC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-20000,20000,s800->GetCorrTOF_XFP_MESY()); + + histname = "E1_vs_OBJ"; + obj.FillHistogram(dirname,histname, + 6000,-30000,30000,s800->GetMTof().GetCorrelatedE1Up(), + 6000,-30000,30000,s800->GetMTof().GetCorrelatedObjE1()); + + + histname = "OBJ_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetTacOBJ()); + + histname = "OBJ_TAC_Corr"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); + + histname = "OBJ_ToFE1_TAC"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTofE1_TAC()); + + //histname = "RF"; + //obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetTof().GetRF()); + + histname = "OBJ_Corr"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_OBJ()); + + histname = "XFP_TAC_ICdE"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetCorrTOF_XFPTAC(),4000,0,4000,s800->GetIonChamber().GetdE(s800->GetCrdc(0).GetDispersiveX(),s800->GetCrdc(0).GetNonDispersiveY())); + + + histname = "Time_E1Up"; + obj.FillHistogram(dirname,histname,4000,-2000,2000,s800->GetScint().GetTimeUp()); + + histname = "AFP_vs_OBJTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); // check units of AFP + + histname = "XFP_vs_OBJTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-2000,2000,s800->GetCorrTOF_OBJTAC()); + + + histname = "AFP_vs_XFPTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); // check units of AFP + + histname = "XFP_vs_XFPTOF_Corr_TAC"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(), + 4000,-2000,2000,s800->GetCorrTOF_XFPTAC()); + + /* + histname = "AFP_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 1000,-0.5,0.5,s800->GetAFP(), + 1000,0,1000,obj_corr); // check units of AFP + + histname = "XFP_vs_OBJTOF"; + obj.FillHistogram(dirname,histname, + 600,-300,300,s800->GetXFP(0), + 1000,0,1000,obj_corr); + */ + + + return true; +} + + + +/* + +------------------------------ +GRETINA +------------------------------ + +*/ + +extern "C" +void MakeHistograms(TRuntimeObjects &obj) { + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TBank88 *bank29 = obj.GetDetector(); + TMode3 *mode3 = obj.GetDetector(); + + + std::string dirname; + std::string histname; + + + dirname = "mode3"; + //histname = Form("gretina_%s",time->GetName()); + if(mode3) + for( size_t i = 0; i< mode3->Size();i++){ + TMode3Hit hit = (mode3->GetMode3Hit(i)); + int cry_id = hit.GetCrystalId(); + histname = Form("cry_e0_%02d",cry_id); + int seg_id = hit.GetSegmentId(); + obj.FillHistogram(dirname,histname,40,0,40,seg_id,4000,0,16000,hit.Charge()); + } + +} diff --git a/histos/MakeSegaJanusHistos.cxx b/histos/MakeSegaJanusHistos.cxx deleted file mode 100644 index a122ec30..00000000 --- a/histos/MakeSegaJanusHistos.cxx +++ /dev/null @@ -1,903 +0,0 @@ -#include "TRuntimeObjects.h" - -#include -#include -#include -#include -#include - -#include "TFile.h" -#include "TH1.h" -#include "TH2.h" -#include "TMath.h" -#include "TObject.h" -#include "TRandom.h" - -#include "GValue.h" -#include "TJanus.h" -#include "TNSCLScalers.h" -#include "TReaction.h" -#include "TSega.h" -#include "TSRIM.h" - -TCutG* pid_low = NULL; -TCutG* pid_high = NULL; -TCutG* time_energy = NULL; - -void LoadGates(TRuntimeObjects& obj){ - if(!pid_low){ - pid_low = obj.GetCut("pid_low"); - if(!pid_low){ - std::cout << "Warning: could not find cut \"pid_low\"" << std::endl; - } - } - - if(!pid_high){ - pid_high = obj.GetCut("pid_high"); - if(!pid_high){ - std::cout << "Warning: could not find cut \"pid_high\"" << std::endl; - } - } - - if(!time_energy){ - time_energy = obj.GetCut("time_energy"); - if(!time_energy){ - std::cout << "Warning: could not find cut \"time_energy\"" << std::endl; - } - } -} - -double get_beta(double betamax, double kr_angle_rad, bool energy_loss=false) { - // Factors of 1e3 are because TNucleus and TReaction use MeV, while TSRIM uses keV. - - static auto kr = std::make_shared("78Kr"); - static auto pb = std::make_shared("208Pb"); - static TSRIM srim("kr78_in_pb208"); - - double thickness = (1.0 / 11342.0) * 1e4; // (1 mg/cm^2) / (11342 mg/cm^3) * (10^4 um/cm) - - double pre_collision_energy_MeV = kr->GetEnergyFromBeta(betamax); - if(energy_loss) { - pre_collision_energy_MeV = srim.GetAdjustedEnergy(pre_collision_energy_MeV*1e3, thickness/2)/1e3; - } - - TReaction reac(kr, pb, kr, pb, pre_collision_energy_MeV); - - double post_collision_energy_MeV = reac.GetTLab(kr_angle_rad, 2); - - if(energy_loss) { - double distance_travelled = (thickness/2)/std::abs(std::cos(kr_angle_rad)); - post_collision_energy_MeV = srim.GetAdjustedEnergy(post_collision_energy_MeV*1e3, distance_travelled)/1e3; - } - - double beta = kr->GetBetaFromEnergy(post_collision_energy_MeV); - return beta; -} - -void MakeJanusHistograms(TRuntimeObjects& obj, TJanus& janus); -void MakeSegaHistograms(TRuntimeObjects& obj, TSega& sega); -void MakeCoincidenceHistograms(TRuntimeObjects& obj, TSega& sega, TJanus& janus); -void MakeScalerHistograms(TRuntimeObjects& obj, TNSCLScalers& scalers); -void MakeTimestampDiffs(TRuntimeObjects& obj, TSega* sega, TJanus* janus); - -// Returns the timestamp in nanoseconds since the start of the first production run. -// Minimum value: 0 -// Maximum value: 2.141e14 (End of Pb-208 target runs) -// Total seconds: ~214100 seconds - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - LoadGates(obj); - - TSega* sega = obj.GetDetector(); - TJanus* janus = obj.GetDetector(); - TNSCLScalers* scalers = obj.GetDetector(); - - - if(janus){ - MakeJanusHistograms(obj, *janus); - } - if(sega){ - MakeSegaHistograms(obj, *sega); - } - if(sega && janus){ - MakeCoincidenceHistograms(obj, *sega, *janus); - } - if(scalers){ - MakeScalerHistograms(obj, *scalers); - } - - MakeTimestampDiffs(obj, sega, janus); -} - -void MakeJanusHistograms(TRuntimeObjects& obj, TJanus& janus) { - for(auto& chan : janus.GetAllChannels()){ - obj.FillHistogram("janus","channel", - 128, 0, 128, chan.GetFrontChannel()); - if(chan.Charge() >= 0) { - obj.FillHistogram("janus","channel_charge", - 128, 0, 128, chan.GetFrontChannel(), - 6000, -4, 6000, chan.Charge()); - obj.FillHistogram("janus","channel_energy", - 128, 0, 128, chan.GetFrontChannel(), - 4000, 0, 400e3, chan.GetEnergy()); - } - if(chan.Time() >= 0) { - obj.FillHistogram("janus","channel_time", - 128, 0, 128, chan.GetFrontChannel(), - 6000, 0, 6000, chan.Time()); - } - } - - // int num_adc = 0; - // int num_tdc = 0; - // for(auto& chan : janus.GetAllChannels()) { - // if(chan.Charge() > -1) { - // num_adc++; - // } - // if(chan.Time() > -1) { - // num_tdc++; - // } - // } - // obj.FillHistogram("janus","total_adc_tdc", - // 128, 0, 128, num_adc, - // 128, 0, 128, num_tdc); - - obj.FillHistogram("janus", "total_bytes", - 2000, 0, 2000, janus.TotalBytes()); - - // for(auto& chan_adc : janus.GetAllChannels()) { - // for(auto& chan_tdc : janus.GetAllChannels()) { - // if((chan_tdc.Time() > 150 || chan_tdc.GetTDCOverflowBit()) && - // (chan_adc.Charge() > 150 || chan_adc.GetADCOverflowBit())) { - // obj.FillHistogram("janus","validadc_validtdc", - // 128, 0, 128, chan_adc.GetFrontChannel(), - // 128, 0, 128, chan_tdc.GetFrontChannel()); - // } - - // if( chan_tdc.Time()>=0 && chan_adc.Charge()>=0) { - // obj.FillHistogram("janus","presentadc_presenttdc", - // 128, 0, 128, chan_adc.GetFrontChannel(), - // 128, 0, 128, chan_tdc.GetFrontChannel()); - // obj.FillHistogram("janus",Form("presentadc_presenttdc_size%04d", janus.TotalBytes()), - // 128, 0, 128, chan_adc.GetFrontChannel(), - // 128, 0, 128, chan_tdc.GetFrontChannel()); - // } - // } - // } - - // for(auto& chan : janus.GetAllChannels()) { - // if((chan.Time() > 150 || chan.GetTDCOverflowBit()) && - // chan.Charge() >= 0) { - // obj.FillHistogram("janus","channel_charge_validtdc", - // 150, -5, 145, chan.GetFrontChannel(), - // 9000, -500, 8500, chan.Charge() + 4096*chan.GetADCOverflowBit()); - // } - // } - - - obj.FillHistogram("janus","num_hits", - 256, 0, 256, janus.Size()); - - for(auto& hit : janus.GetAllHits()){ - obj.FillHistogram("janus","hit_channel", - 128, 0, 128, hit.GetFrontChannel()); - obj.FillHistogram("janus","hit_channel", - 128, 0, 128, hit.GetBackChannel()); - - obj.FillHistogram("janus","hit_channel_charge", - 128, 0, 128, hit.GetFrontChannel(), - 6000, -4, 6000, hit.Charge()); - obj.FillHistogram("janus","hit_channel_charge", - 128, 0, 128, hit.GetBackChannel(), - 6000, -4, 6000, hit.GetBackHit().Charge()); - - if(hit.GetADCOverflowBit()) { - obj.FillHistogram("janus","hit_channel_charge_overflow", - 128, 0, 128, hit.GetFrontChannel(), - 6000, -4, 6000, hit.Charge()); - } else { - obj.FillHistogram("janus","hit_channel_charge_nonoverflow", - 128, 0, 128, hit.GetFrontChannel(), - 6000, -4, 6000, hit.Charge()); - } - - obj.FillHistogram("janus","hit_channel_energy", - 128, 0, 128, hit.GetFrontChannel(), - 4000, 0, 400e3, hit.GetEnergy()); - obj.FillHistogram("janus","hit_channel_energy", - 128, 0, 128, hit.GetBackChannel(), - 4000, 0, 400e3, hit.GetBackHit().GetEnergy()); - - obj.FillHistogram("janus","hit_channel_time", - 128, 0, 128, hit.GetFrontChannel(), - 6000, 0, 6000, hit.Time()); - obj.FillHistogram("janus","hit_channel_time", - 128, 0, 128, hit.GetBackChannel(), - 6000, 0, 6000, hit.GetBackHit().Time()); - - obj.FillHistogram("janus",Form("hit_det%d_ringnum",hit.GetDetnum()), - 24, 1, 25, hit.GetRing()); - obj.FillHistogram("janus",Form("hit_det%d_sectornum",hit.GetDetnum()), - 32, 1, 33, hit.GetSector()); - } - - for(unsigned int i=0; iIsInside(hit.GetFrontChannel(), hit.Charge())) { - static TReaction reac("78Kr","208Pb","78Kr","208Pb",3.9*78); - // Convert from 208Pb angle to 78Kr angle - double theta_78kr = reac.ConvertThetaLab(theta, 3, 2); - obj.FillHistogram("janus","theta78Kr_recon", - 180, 0, 180, theta_78kr * TMath::RadToDeg()); - } - - obj.FillHistogram("janus",Form("janus_Sector%02i_v_ring_det%02i",hit.GetSector(),hit_detnum), - 40,0,40,hit.GetRing(), - 6000,0,6000,hit.Charge()); - - obj.FillHistogram("janus", "theta_v_energy", - 180,0,180,theta_deg, - 4000,0,400e3,hit.GetEnergy()); - - obj.FillHistogram("janus","theta_v_charge", - 180,0,180,theta_deg, - 6000,0,6000,hit.Charge()); - - obj.FillHistogram("janus",Form("ring_v_energy_det%02i",hit_detnum), - 30,0,30,hit.GetRing(), - 4000,0,400e3,hit.GetEnergy()); - - obj.FillHistogram("janus",Form("phi_v_energy_det%02i",hit_detnum), - 360,-180,180,hit.GetPosition().Phi()*TMath::RadToDeg(), - 4000,0,400e3,hit.GetEnergy()); - - obj.FillHistogram("janus",Form("sector_v_energy_det%02i",hit_detnum), - 32,0,32,hit.GetSector(), - 4000,0,400e3,hit.GetEnergy()); - - } -} - - -void MakeSegaHistograms(TRuntimeObjects& obj, TSega& sega) { - obj.FillHistogram("sega","num_hits", - 256,0,256,sega.Size()); - - long cc_timestamp = -1; - long segment_timestamp = -1; - for(unsigned int i=0; i0 && segment_timestamp>0){ - obj.FillHistogram("sega","segment_core_tdiff", - 1000, -5000, 5000, cc_timestamp - segment_timestamp); - } -} - -void Make78KrPlots(TRuntimeObjects& obj, TSegaHit& s_hit, TJanusHit& j_hit) { - double energy = s_hit.GetEnergy(); - TVector3 particle_position = j_hit.GetPosition(); - double time_diff = s_hit.Timestamp() - j_hit.Timestamp(); - double beta = GValue::Value("beta"); - - obj.FillHistogram("kr78","energy_notimegate", - 8000, 0, 4000, energy); - obj.FillHistogram("kr78","energy_summary_notimegate", - 18, 1, 19, s_hit.GetDetnum(), - 8000, 0, 4000, energy); - obj.FillHistogram("kr78","DCenergy_beamaxis_notimegate", - 8000, 0, 4000, s_hit.GetDoppler(beta)); - obj.FillHistogram("kr78","DCenergy_notimegate", - 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position)); - - - - if(time_energy->IsInside(energy, time_diff)){ - // Doppler corrected energies, using janus - double dc_energy = s_hit.GetDoppler(beta, particle_position); - - if(dc_energy > 440 && dc_energy < 465) { - obj.FillHistogram("kr78","janus_channel_time_455keV_coinc", - 128, 0, 128, j_hit.GetFrontChannel(), - 6000, 0, 6000, j_hit.Time()); - obj.FillHistogram("kr78","janus_channel_time_455keV_coinc", - 128, 0, 128, j_hit.GetBackChannel(), - 6500, -500, 6000, j_hit.GetBackHit().Time()); - } - - obj.FillHistogram("kr78","energy", - 4000, 0, 4000, s_hit.GetEnergy()); - obj.FillHistogram("kr78","DCenergy", - 4000, 0, 4000, dc_energy); - - double theta_deg = s_hit.GetPosition().Angle(particle_position) * (180/3.1415926); - obj.FillHistogram("kr78","energy_angle", - 2000, 0, 2000, s_hit.GetEnergy(), - 180, 0, 180, theta_deg); - obj.FillHistogram("kr78","DCenergy_angle", - 2000, 0, 2000, dc_energy, - 180, 0, 180, theta_deg); - - - obj.FillHistogram("kr78",Form("energy_angle_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, energy, - 180, 0, 180, theta_deg); - obj.FillHistogram("kr78",Form("DCenergy_angle_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, dc_energy, - 180, 0, 180, theta_deg); - - - double kr_theta = particle_position.Theta(); - //double kr_theta_deg = kr_theta * (180/3.1415926); - - // Angle-dependent beta - { - double betamax = GValue::Value("betamax"); - - obj.FillHistogram("kr78",Form("DCenergy_angle_varybeta_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, s_hit.GetDoppler(get_beta(betamax,kr_theta), particle_position), - 180, 0, 180, theta_deg); - - obj.FillHistogram("kr78",Form("DCenergy_angle_varybeta_Ecorr_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, s_hit.GetDoppler(get_beta(betamax,kr_theta,true), particle_position), - 180, 0, 180, theta_deg); - - // phi_deg varies -180 to 180 - double phi_deg = particle_position.Phi() * TMath::RadToDeg(); - int quadrant; - if(phi_deg < -90) { - quadrant = 3; - } else if (phi_deg >= -90 && phi_deg < 0) { - quadrant = 4; - } else if (phi_deg >= 0 && phi_deg < 90) { - quadrant = 1; - } else { - quadrant = 2; - } - obj.FillHistogram("kr78",Form("DCenergy_angle_varybeta_Ecorr_ring%02d_quad%d", j_hit.GetRing(), quadrant), - 2000, 0, 2000, s_hit.GetDoppler(get_beta(betamax,kr_theta,true), particle_position), - 180, 0, 180, theta_deg); - - // //Scan along betamax - // for(int betamax_i = 0; betamax_i<150; betamax_i++) { - // double betamax = 0.0 + betamax_i*((0.15-0.00)/150); - // obj.FillHistogram("kr78","DCenergy_varybeta_betascan", - // 150, 0.0, 0.15, betamax, - // 8000, 0, 4000, s_hit.GetDoppler(get_beta(betamax, kr_theta), particle_position)); - // obj.FillHistogram("kr78","DCenergy_varybeta_betascan_Ecorr", - // 150, 0.0, 0.15, betamax, - // 8000, 0, 4000, s_hit.GetDoppler(get_beta(betamax, kr_theta,true), particle_position)); - // } - } - - - // // Scan along beta - // for(int beta_i = 0; beta_i<150; beta_i++) { - // double beta = 0.0 + beta_i*((0.15-0.00)/150); - - // obj.FillHistogram("kr78","beamaxis_betascan", - // 150, 0.0, 0.15, beta, - // 8000, 0, 4000, s_hit.GetDoppler(beta)); - - // obj.FillHistogram("kr78","betascan", - // 150, 0.0, 0.15, beta, - // 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position)); - // } - - // // Scan along z - // for(int z=-20; z<20; z++) { - // TVector3 offset(0,0,z); - // obj.FillHistogram("kr78","DCenergy_zscan", - // 40, -20, 20, z, - // 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position, offset)); - // } - } -} - -void Make78KrPlots_Reconstructed(TRuntimeObjects& obj, TSegaHit& s_hit, TJanusHit& j_hit) { - TVector3 particle_position = j_hit.GetConjugateDirection(); - double time_diff = s_hit.Timestamp() - j_hit.Timestamp(); - double beta = GValue::Value("beta_reconstructed"); - double energy = s_hit.GetEnergy(); - double dc_energy = s_hit.GetDoppler(beta, particle_position); - - obj.FillHistogram("kr78_recon","energy_notimegate", - 8000, 0, 4000, energy); - obj.FillHistogram("kr78_recon","energy_summary_notimegate", - 18, 1, 19, s_hit.GetDetnum(), - 8000, 0, 4000, energy); - obj.FillHistogram("kr78_recon","DCenergy_beamaxis_notimegate", - 8000, 0, 4000, s_hit.GetDoppler(beta)); - obj.FillHistogram("kr78_recon","DCenergy_notimegate", - 8000, 0, 4000, dc_energy); - - - - if(time_energy->IsInside(energy, time_diff)){ - // Doppler corrected energies, using janus - obj.FillHistogram("kr78_recon","energy", - 4000, 0, 4000, energy); - obj.FillHistogram("kr78_recon","DCenergy", - 4000, 0, 4000, dc_energy); - - double theta_deg = s_hit.GetPosition().Angle(particle_position) * (180/3.14159); - obj.FillHistogram("kr78_recon","energy_angle", - 2000, 0, 2000, energy, - 180, 0, 180, theta_deg); - obj.FillHistogram("kr78_recon","DCenergy_angle", - 2000, 0, 2000, dc_energy, - 180, 0, 180, theta_deg); - - obj.FillHistogram("kr78_recon",Form("energy_angle_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, energy, - 180, 0, 180, theta_deg); - obj.FillHistogram("kr78_recon",Form("DCenergy_angle_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, dc_energy, - 180, 0, 180, theta_deg); - - double kr_theta = particle_position.Theta(); - double kr_theta_deg = kr_theta * (180/3.1415926); - - // Angle-dependent beta - { - double betamax = GValue::Value("betamax"); - obj.FillHistogram("kr78_recon",Form("DCenergy_angle_varybeta_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, s_hit.GetDoppler(get_beta(betamax, kr_theta), particle_position), - 180, 0, 180, theta_deg); - - obj.FillHistogram("kr78_recon",Form("DCenergy_angle_varybeta_Ecorr_ring%02d", j_hit.GetRing()), - 2000, 0, 2000, s_hit.GetDoppler(get_beta(betamax, kr_theta,true), particle_position), - 180, 0, 180, theta_deg); - - // phi_deg varies -180 to 180 - double phi_deg = particle_position.Phi() * TMath::RadToDeg(); - int quadrant; - if(phi_deg < -90) { - quadrant = 3; - } else if (phi_deg >= -90 && phi_deg < 0) { - quadrant = 4; - } else if (phi_deg >= 0 && phi_deg < 90) { - quadrant = 1; - } else { - quadrant = 2; - } - obj.FillHistogram("kr78_recon",Form("DCenergy_angle_varybeta_Ecorr_ring%02d_quad%d", j_hit.GetRing(), quadrant), - 2000, 0, 2000, s_hit.GetDoppler(get_beta(betamax, kr_theta,true), particle_position), - 180, 0, 180, theta_deg); - - } - - // //Scan along betamax - // for(int betamax_i = 0; betamax_i<150; betamax_i++) { - // double betamax = 0.0 + betamax_i*((0.15-0.00)/150); - // obj.FillHistogram("kr78_recon","DCenergy_varybeta_betascan", - // 150, 0.0, 0.15, betamax, - // 8000, 0, 4000, s_hit.GetDoppler(get_beta(betamax, kr_theta), particle_position)); - // obj.FillHistogram("kr78_recon","DCenergy_varybeta_betascan_Ecorr", - // 150, 0.0, 0.15, betamax, - // 8000, 0, 4000, s_hit.GetDoppler(get_beta(betamax, kr_theta,true), particle_position)); - // } - - // // Scan along beta - // for(int beta_i = 0; beta_i<150; beta_i++) { - // double beta = 0.0 + beta_i*((0.15-0.00)/150); - // obj.FillHistogram("kr78_recon","beamaxis_betascan", - // 150, 0.0, 0.15, beta, - // 8000, 0, 4000, s_hit.GetDoppler(beta)); - - // obj.FillHistogram("kr78_recon","betascan", - // 150, 0.0, 0.15, beta, - // 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position)); - // } - - // // Scan along z - // for(int z=-20; z<20; z++) { - // TVector3 offset(0,0,z); - // obj.FillHistogram("kr78_recon","DCenergy_zscan", - // 40, -20, 20, z, - // 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position, offset)); - // } - - if(75 > kr_theta_deg || 105 < kr_theta_deg) { - // DC energies ignoring area around 90 degrees - obj.FillHistogram("kr78_recon","energy_notnear90", - 4000, 0, 4000, energy); - obj.FillHistogram("kr78_recon","DCenergy_notnear90", - 4000, 0, 4000, dc_energy); - - double theta_deg = s_hit.GetPosition().Angle(particle_position) * (180/3.14159); - obj.FillHistogram("kr78_recon","energy_angle_notnear90", - 2000, 0, 2000, energy, - 180, 0, 180, theta_deg); - obj.FillHistogram("kr78_recon","DCenergy_angle_notnear90", - 2000, 0, 2000, dc_energy, - 180, 0, 180, theta_deg); - - - // //Scan along betamax - // for(int betamax_i = 0; betamax_i<150; betamax_i++) { - // double betamax = 0.0 + betamax_i*((0.15-0.00)/150); - // obj.FillHistogram("kr78_recon","DCenergy_varybeta_betascan_notnear90", - // 150, 0.0, 0.15, betamax, - // 8000, 0, 4000, s_hit.GetDoppler(get_beta(betamax, kr_theta), particle_position)); - // obj.FillHistogram("kr78_recon","DCenergy_varybeta_betascan_Ecorr_notnear90", - // 150, 0.0, 0.15, betamax, - // 8000, 0, 4000, s_hit.GetDoppler(get_beta(betamax, kr_theta, true), particle_position)); - // } - - // // Scan along z - // for(int z=-20; z<20; z++) { - // TVector3 offset(0,0,z); - // obj.FillHistogram("kr78_recon","DCenergy_zscan_notnear90", - // 40, -20, 20, z, - // 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position, offset)); - // } - } - } -} - -void Make208PbPlots(TRuntimeObjects& obj, TSegaHit& s_hit, TJanusHit& j_hit) { - double energy = s_hit.GetEnergy(); - TVector3 particle_position = j_hit.GetPosition(); - double time_diff = s_hit.Timestamp() - j_hit.Timestamp(); - - obj.FillHistogram("pb208","energy_notimegate", - 8000, 0, 4000, energy); - obj.FillHistogram("pb208","energy_summary_notimegate", - 18, 1, 19, s_hit.GetDetnum(), - 8000, 0, 4000, energy); - obj.FillHistogram("pb208","DCenergy_beamaxis_notimegate", - 8000, 0, 4000, s_hit.GetDoppler(GValue::Value("beta"))); - obj.FillHistogram("pb208","DCenergy_notimegate", - 8000, 0, 4000, s_hit.GetDoppler(GValue::Value("beta"), particle_position)); - - if(time_energy->IsInside(energy, time_diff)){ - // Doppler corrected energies, using janus - double dc_energy = s_hit.GetDoppler(GValue::Value("beta"), particle_position); - - obj.FillHistogram("pb208","energy", - 4000, 0, 4000, s_hit.GetEnergy()); - obj.FillHistogram("pb208","DCenergy", - 4000, 0, 4000, dc_energy); - - double theta_deg = s_hit.GetPosition().Angle(particle_position); - obj.FillHistogram("pb208","energy_angle", - 2000, 0, 2000, s_hit.GetEnergy(), - 180, 0, 180, theta_deg); - obj.FillHistogram("pb208","DCenergy_angle", - 2000, 0, 2000, dc_energy, - 180, 0, 180, theta_deg); - - - // // Scan along beta - // for(int beta_i = 0; beta_i<150; beta_i++) { - // double beta = 0.0 + beta_i*((0.15-0.00)/150); - - // obj.FillHistogram("pb208","beamaxis_betascan", - // 150, 0.0, 0.15, beta, - // 8000, 0, 4000, s_hit.GetDoppler(beta)); - - // obj.FillHistogram("pb208","betascan", - // 150, 0.0, 0.15, beta, - // 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position)); - // } - - // // Scan along z - // for(int z=-20; z<20; z++) { - // double beta = GValue::Value("beta"); - // TVector3 offset(0,0,z); - // obj.FillHistogram("pb208","DCenergy_zscan", - // 40, -20, 20, z, - // 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position, offset)); - // } - } -} - -void MakeUpstream78KrPlots(TRuntimeObjects& obj, TSegaHit& s_hit, TJanusHit& j_hit, std::string cutname) { - obj.FillHistogram("upstream", "time_energy", - 4000, 0, 4000, s_hit.GetEnergy(), - 1000, -5000, 5000, s_hit.Timestamp() - j_hit.Timestamp()); - - double beta_nominal = GValue::Value("beta_upstream"); - TVector3 particle_position = j_hit.GetPosition(); - double energy = s_hit.GetEnergy(); - double time_diff = s_hit.Timestamp() - j_hit.Timestamp(); - double kr_theta = particle_position.Theta(); - - obj.FillHistogram("upstream", Form("gamma_energy_%s_notimegate",cutname.c_str()), - 4000, 0, 4000, s_hit.GetEnergy()); - - obj.FillHistogram("upstream", Form("gamma_energyDC_%s_notimegate", cutname.c_str()), - 4000, 0, 4000, s_hit.GetDoppler(beta_nominal, particle_position)); - - if(time_energy->IsInside(energy, time_diff)) { - - obj.FillHistogram("upstream", Form("energy_%s",cutname.c_str()), - 4000, 0, 4000, s_hit.GetEnergy()); - - double dc_energy = s_hit.GetDoppler(beta_nominal, particle_position); - obj.FillHistogram("upstream", Form("DCenergy_%s", cutname.c_str()), - 4000, 0, 4000, dc_energy); - - - double theta_deg = s_hit.GetPosition().Angle(particle_position) * (180/3.1415926); - obj.FillHistogram("upstream","energy_angle", - 2000, 0, 2000, s_hit.GetEnergy(), - 180, 0, 180, theta_deg); - obj.FillHistogram("upstream","DCenergy_angle", - 2000, 0, 2000, dc_energy, - 180, 0, 180, theta_deg); - - - obj.FillHistogram("upstream",Form("janus_pos_%s", cutname.c_str()), - 100, -4, 4, j_hit.GetPosition().X(), - 100, -4, 4, j_hit.GetPosition().Y()); - - obj.FillHistogram("upstream",Form("janus_ringnum_%s", cutname.c_str()), - 40, -5, 35, j_hit.GetRing()); - - obj.FillHistogram("upstream",Form("janus_sectornum_%s", cutname.c_str()), - 40, -5, 35, j_hit.GetSector()); - - // Scan along beta - for(int beta_i = 0; beta_i<150; beta_i++) { - double beta = 0.0 + beta_i*((0.15-0.00)/150); - - obj.FillHistogram("upstream",Form("betascan_%s",cutname.c_str()), - 150, 0.0, 0.15, beta, - 8000, 0, 4000, s_hit.GetDoppler(beta, particle_position)); - } - - double betamax = GValue::Value("betamax"); - obj.FillHistogram("upstream", Form("gamma_energyDC_angledep_%s", cutname.c_str()), - 4000, 0, 4000, s_hit.GetDoppler(get_beta(betamax, kr_theta,true), particle_position)); - } -} - -void MakeTimeDependentHistograms(TRuntimeObjects& obj, TSega& sega, TJanus& janus) { - for(unsigned int i=0; iIsInside(j_hit.GetFrontChannel(), j_hit.Charge()); - for(unsigned int i=0; iIsInside(s_hit.GetEnergy(), - s_hit.Timestamp() - j_hit.Timestamp())){ - int detnum = s_hit.GetDetnum(); - double timestamp = s_hit.Timestamp(); - double beta = GValue::Value("beta"); - TVector3 particle_pos = j_hit.GetPosition(); - - double dc_energy = s_hit.GetDoppler(beta, particle_pos); - obj.FillHistogram("traceheight",Form("DCenergy_det%02d_time",detnum), - 214100/60, 0, 2.141e14, timestamp, - 1000, 0, 2000, dc_energy); - - double dc_traceheight = s_hit.GetTraceHeightDoppler(beta, particle_pos); - obj.FillHistogram("traceheight",Form("DCtraceheight_det%02d_timestamp",detnum), - 214100/60, 0, 2.141e14, timestamp, - 3100, -100, 3000, dc_traceheight); - } - } - } - } -} - -void MakeCoincidenceHistograms(TRuntimeObjects& obj, TSega& sega, TJanus& janus) { - bool has_455keV = false; - - for(unsigned int i=0; i425 && hit.GetEnergy()<485){ - has_455keV = true; - } - obj.FillHistogram("coinc","sega_energy_janus_tdiff", - 4000, 0, 4000, hit.GetEnergy(), - 1000, -5000, 5000, hit.Timestamp() - janus.Timestamp()); - } - - - for(unsigned int i=0; iIsInside(j_hit.GetFrontChannel(), j_hit.Charge()); - bool in_pid_high = pid_high->IsInside(j_hit.GetFrontChannel(), j_hit.Charge()); - - bool in_upstream_pid_low = j_hit.GetDetnum() == 0 && !(j_hit.Charge() > 3600 || j_hit.GetADCOverflowBit()); - bool in_upstream_pid_high = j_hit.GetDetnum() == 0 && (j_hit.Charge() > 3600 || j_hit.GetADCOverflowBit()); - - - for(unsigned int i=0; iTimestamp() - janus->Timestamp()); - - for(unsigned int i=0; iSize(); i++){ - TSegaHit& hit = sega->GetSegaHit(i); - obj.FillHistogram("tdiff","sega_detnum_janus_tdiff", - 16, 1, 17, hit.GetDetnum(), - 1000, -5000, 5000, hit.Timestamp() - janus->Timestamp()); - } - } - - long crate1_ts = -1; - long crate2_ts = -1; - long crate3_ts = -1; - long analog_ts = -1; - std::map source_ids; - - if(janus){ - analog_ts = janus->Timestamp(); - source_ids[4] = analog_ts; - } - if(sega){ - for(unsigned int i=0; iSize(); i++){ - TSegaHit& hit = sega->GetSegaHit(i); - if(hit.GetCrate()==1){ - crate1_ts = hit.Timestamp(); - } else if(hit.GetCrate()==2){ - crate2_ts = hit.Timestamp(); - } else if(hit.GetCrate()==3){ - crate3_ts = hit.Timestamp(); - } - - source_ids[hit.GetCrate()] = hit.Timestamp(); - } - } - - for(auto& item : source_ids) { - obj.FillHistogram("tdiff","timestamp_sourceid", - 2.141e14/60e9, 0, 2.141e14, item.second, - 4, 1, 5, item.first); - } - - - if(crate1_ts!=-1 && crate2_ts!=-1){ - obj.FillHistogram("tdiff","crate1_crate2", - 600, -3000, 3000, crate2_ts - crate1_ts); - } - if(crate1_ts!=-1 && crate3_ts!=-1){ - obj.FillHistogram("tdiff", "crate1_crate3", - 600, -3000, 3000, crate3_ts - crate1_ts); - } - if(crate2_ts!=-1 && crate3_ts!=-1){ - obj.FillHistogram("tdiff", "crate2_crate3", - 600, -3000, 3000, crate3_ts - crate2_ts); - } - if(analog_ts!=-1 && crate1_ts!=-1){ - obj.FillHistogram("tdiff", "analog_crate1", - 600, -3000, 3000, analog_ts - crate1_ts); - } - if(analog_ts!=-1 && crate2_ts!=-1){ - obj.FillHistogram("tdiff", "analog_crate2", - 600, -3000, 3000, analog_ts - crate2_ts); - } - if(analog_ts!=-1 && crate3_ts!=-1){ - obj.FillHistogram("tdiff", "analog_crate3", - 600, -3000, 3000, analog_ts - crate3_ts); - } -} - -void MakeScalerHistograms(TRuntimeObjects& obj, TNSCLScalers& scalers) { - if(scalers.GetSourceID() == 4) { - for(unsigned int i=0; i -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - - InitMap(); - // TGretina *gretina = obj.GetDetector(); - //TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - std::string histname = ""; - std::string dirname = ""; - - - if(s800){ - - double ic_sum = s800->GetIonChamber().GetAve(); - - // std::cout << "Dispersive X value: " << s800->GetCrdc(0).GetDispersiveX() << std::endl; - // std::cout << "NonDispersive Y value: " << s800->GetCrdc(0).GetNonDispersiveY() << std::endl; - - obj.FillHistogram("s800","CRDC1Y",10000,-5000,5000,s800->GetCrdc(0).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC2Y",10000,-5000,5000,s800->GetCrdc(1).GetNonDispersiveY()); - obj.FillHistogram("s800","CRDC1X",800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - obj.FillHistogram("s800","CRDC2X",800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - dirname = "MaskCal_gated"; - if(ic_sum > 200){ - histname = "CRDC1_Gated"; - obj.FillHistogram(dirname,histname, - 520,-10,250,s800->GetCrdc(0).GetDispersiveX(), - 500,0,4000,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2_Gated"; - obj.FillHistogram(dirname,histname, - 520,-10,250,s800->GetCrdc(1).GetDispersiveX(), - 500,0,4000,s800->GetCrdc(1).GetNonDispersiveY()); - - histname = "CRDC1_Cal_Gated"; - obj.FillHistogram(dirname,histname, - 800,-400,400,s800->GetCrdc(0).GetDispersiveX(), - 3000,-200,200,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2_Cal_Gated"; - obj.FillHistogram(dirname,histname, - 800,-400,400,s800->GetCrdc(1).GetDispersiveX(), - 3000,-200,200,s800->GetCrdc(1).GetNonDispersiveY()); - } - - histname = "IC_Energy"; - obj.FillHistogram(histname,1000,-100,4000,ic_sum); - - dirname = "MaskCal"; - histname = "CRDC1"; - obj.FillHistogram(dirname,histname, - 520,-10,250,s800->GetCrdc(0).GetDispersiveX(), - 500,0,4000,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2"; - obj.FillHistogram(dirname,histname, - 520,-10,250,s800->GetCrdc(1).GetDispersiveX(), - 500,0,4000,s800->GetCrdc(1).GetNonDispersiveY()); - - histname = "CRDC1_Cal"; - obj.FillHistogram(dirname,histname, - 520,-400,400,s800->GetCrdc(0).GetDispersiveX(), - 3000,-200,200,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2_Cal"; - obj.FillHistogram(dirname,histname, - 800,-400,400,s800->GetCrdc(1).GetDispersiveX(), - 3000,-200,200,s800->GetCrdc(1).GetNonDispersiveY()); - - dirname = "GetYOffset"; - histname = "CRDC1_Y_vs_S800Timestamp"; - obj.FillHistogram(dirname,histname, - 10000,0,6000,s800->GetTimestamp()/1e8, - 800,-400,400,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2_Y_vs_S800Timestamp"; - obj.FillHistogram(dirname,histname, - 10000,0,6000,s800->GetTimestamp()/1e8, - 800,-400,400,s800->GetCrdc(1).GetNonDispersiveY()); - - histname = "CRDC1_Y_vs_S800Timestamp_UnCal"; - obj.FillHistogram(dirname,histname, - 10000,0,6000,s800->GetTimestamp()/1e8, - 800,-4000,4000,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2_Y_vs_S800Timestamp_UnCal"; - obj.FillHistogram(dirname,histname, - 10000,0,6000,s800->GetTimestamp()/1e8, - 800,-4000,4000,s800->GetCrdc(1).GetNonDispersiveY()); - - dirname = "InverseMap"; - - histname = "S800_YTA"; - obj.FillHistogram(dirname,histname, - 1000,-50,50,s800->GetYta()); - - histname = "S800_DTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetDta()); - - histname = "ATA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta()); - - histname = "BTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetBta()); - - histname = "ATA_vs_BTA"; - obj.FillHistogram(dirname,histname, - 1000,-0.2,0.2,s800->GetAta(), - 1000,-0.2,0.2,s800->GetBta()); - - - } - - -} diff --git a/histos/MyMakeHistos.cxx.bak b/histos/MyMakeHistos.cxx.bak new file mode 100644 index 00000000..84aaa4ce --- /dev/null +++ b/histos/MyMakeHistos.cxx.bak @@ -0,0 +1,761 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank88.h" +#include "TS800.h" +#include "TFastScint.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +//#define Q1 15 +//#define Q2 7 +//#define Q3 8 +//#define Q4 16 +//#define Q5 9 +//#define Q6 14 +//#define Q7 17 +//#define Q8 6 +//#define Q9 19 + +//#define Q1 15 +//#define Q2 7 +//#define Q3 11 +//#define Q4 1 +//#define Q5 22 +//#define Q6 14 +//#define Q7 12 +//#define Q8 6 +//#define Q9 21 + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 16 +#define Q5 8 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 17 +#define Q10 9 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +//hole_list="15 7 11 16 8 14 12 6 17 9"; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + HoleQMap[Q10] = 10; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +std::vector incoming_cuts = {0}; +std::vector outgoing_cuts = {0}; + +//std::vector gretina_cuts = {0}; +GCutG *gg_timing_gate=0; + +int gates_loaded=0; + +long first_time = -1; + +GCutG *test = 0; + +//for(unsigned int j=0;j(); + if(!s800) + return false; + + std::string dirname; + if(incoming) + dirname = Form("outgoing_%s",incoming->GetName()); + else + dirname = "outgoing"; + + + if(incoming) { + if(!s800->GetMTof().ObjSize() || !s800->GetMTof().XfpSize()) + return false; + bool found = false; + for(int x=0;xGetMTof().ObjSize();x++) { + for(int y=0;xGetMTof().XfpSize();x++) { + if(incoming->IsInside(s800->GetMTof().fObj[x],s800->GetMTof().fXfp[y])) { + found = true; + //std::cout << incoming->GetName() << "\tpassed." << std::endl; + } + } + } + //if(!incoming->IsInside(s800->GetMTof().fObj[0],s800->GetMTof().fXfp[0])) + if(!found) + return false; + } + + std::string histname; + + TIonChamber ion = s800->GetIonChamber(); + histname = "ion_summary"; + for(int i=0;iGetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); + + histname = "CRDC1_XY"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX(), + 800,-400,400,s800->GetCrdc(0).GetNonDispersiveY()); + + histname = "CRDC2_XY"; + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX(), + 800,-400,400,s800->GetCrdc(1).GetNonDispersiveY()); + + + for(int i=0;iGetMTof().fObj.size();i++) { + double value = s800->GetMTOF_ObjE1(i,0); + histname = Form("mesy_obj_e1_all_%i",s800->GetTrigger().GetRegistr());; + obj.FillHistogram(dirname,histname,8000,-16000,16000,value); + histname = Form("mesy_obj_e1_num_hit_%i",s800->GetTrigger().GetRegistr());; + obj.FillHistogram(dirname,histname,8000,-16000,16000,value, + 10,0,10,i); + } + + + + + TMTof &mtof = s800->GetMTof(); + + for(int i=0;iGetMTOF_RfE1(i))); //mtof.fE1Up.at(i)-mtof.fRf.at(i))); + } + if(iGetMTOF_ObjE1(i,false)));//mtof.fE1Up.at(i)-mtof.fObj.at(i)); + } + } + + histname = "time_x"; + obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), + 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + + + histname = "time_afp"; + obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), + 1000,-.1,.1,s800->GetAFP()); + + histname = "registr"; + obj.FillHistogram(dirname, histname, + 20, -5, 15, s800->GetTrigger().GetRegistr()); + + + + if(s800->GetTrigger().GetRegistr()&0x0002) { + histname = "time_charge_coinc"; + obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), + 5000,10000,40000,s800->GetIonChamber().Charge()); + } + histname = "time_charge"; + obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), + 10000,2000,42000,s800->GetIonChamber().Charge()); + + + + return true; +} + + +bool IncomingBeam(TRuntimeObjects& obj,GCutG *outgoing) { + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + if(outgoing) { + if(!outgoing->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge())) + return false; + } + + std::string dirname; + if(outgoing) + dirname = Form("incoming_%s",outgoing->GetName()); + else + dirname = "incoming"; + + std::string histname; + TMTof &mtof = s800->GetMTof(); + + + histname = "Obj"; + if(s800->GetMTof().ObjSize()) + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTof().fObj[0]); //OF_ObjE1()); + histname = "Obj_Rf"; + obj.FillHistogram(dirname,histname,8000,-3200,32000,s800->GetMTOF_ObjRf()); + histname = "Xfp"; + if(s800->GetMTof().XfpSize()) { + obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTof().fXfp[0]); //OF_XfpE1()); + histname = "Xfp_time"; + obj.FillHistogram(dirname,histname,360,0,3600,s800->Timestamp()/1e8, + 2000,-32000,32000,s800->GetMTof().fXfp[0]); //OF_XfpE1()); + } + histname = "Rf_E1"; + obj.FillHistogram(dirname,histname,8000,-32000,64000,s800->GetMTOF_RfE1()); + + histname = "obj_rf_2d"; + obj.FillHistogram(dirname,histname,1600,-8000,0,s800->GetMTOF_ObjE1(), + 1600,-24000,-16000,s800->GetMTOF_RfE1()); + + for(int x=0;xGetMTof().ObjSize();x++) { + for(int y=0;xGetMTof().XfpSize();x++) { + if(s800->GetMTof().ObjSize() && s800->GetMTof().XfpSize()) { + histname = "obj_xfp_2d"; + obj.FillHistogram(dirname,histname,6000,8000,14000,s800->GetMTof().fObj[x], + 8000,12000,20000,s800->GetMTof().fXfp[y]); + + if (s800->GetTrigger().GetRegistr()&0x0002) { + histname = "obj_xfp_2d_coinc"; + obj.FillHistogram(dirname,histname,6000,8000,14000,s800->GetMTof().fObj[x], + 8000,12000,20000,s800->GetMTof().fXfp[y]); + } + } + } + } + + + + //histname = "obj_xfp_2d"; + //obj.FillHistogram(dirname,histname,800,0,64000,s800->GetMTOF_ObjE1(), + // 800,0,64000,s800->GetMTOF_XfpE1()); + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname,histname,20,0,20,j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname,histname,20,0,20,s800->GetTrigger().GetRegistr()); + + return true; +} + + + +bool HandleGretina(TRuntimeObjects &obj,GCutG *outgoing=0) { + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + if(!gretina) + return false; + + //gretina->CleanHits(); /// remove pad !=0 and duplicate segments. + + std::string dirname = "gretina"; + std::string histname; + + for(unsigned int x=0;xSize();x++) { + TGretinaHit hit1 = gretina->GetGretinaHit(x); + histname="summary"; + obj.FillHistogram(dirname,histname,4000,0,4000,hit1.GetCoreEnergy(), + 120,0,120,hit1.GetCrystalId()); + histname="error_code"; + obj.FillHistogram(dirname,histname,4000,0,4000,hit1.GetCoreEnergy(), + 10,0,10,hit1.GetPad()); + histname="singles"; + obj.FillHistogram(dirname,histname,12000,0,6000,hit1.GetCoreEnergy()); + + if(s800 && (s800->GetReg()&0x0002)) { + histname="singles_coin"; + obj.FillHistogram(dirname,histname,12000,0,6000,hit1.GetCoreEnergy()); + } + + histname="position"; + obj.FillHistogram(dirname,histname,180,0,180,hit1.GetThetaDeg(), + 360,0,360,hit1.GetPhiDeg()); + if(first_time<0 && hit1.GetTime()>0) { + first_time = hit1.GetTime(); + } + if(first_time>0) { + histname="counts_vs_time"; + obj.FillHistogram(dirname,histname,2000,0,20000,(hit1.GetTime()-first_time)*1e-8, + 200,0,200,hit1.GetCrystalId()); + } + for(unsigned int y=x+1;ySize();y++) { + TGretinaHit hit2 = gretina->GetGretinaHit(y); + double energy,time; + //bool prompt = false; + if(hit1.GetCoreEnergy()>hit2.GetCoreEnergy()) { + energy = hit2.GetCoreEnergy(); + time = hit1.GetTime()-hit2.GetTime(); + } else { + energy = hit1.GetCoreEnergy(); + time = hit2.GetTime()-hit1.GetTime(); + } + //if(gg_timing_gate && gg_timing_gate->IsInside(time,energy)) + // prompt=true; + histname="gg_time"; + obj.FillHistogram(dirname,histname,2000,-1000,1000,time, + 2000,0,10000,energy); + //histname="gg_matrix"; + //obj.FillHistogram(dirname,histname,4000,0,8000,hit1.GetCoreEnergy(), + // 4000,0,8000,hit2.GetCoreEnergy()); + //histname="gg_matrix"; + //obj.FillHistogram(dirname,histname,4000,0,8000,hit2.GetCoreEnergy(), + // 4000,0,8000,hit1.GetCoreEnergy()); + //if(prompt) { + // histname="gg_matrix_clean"; + // obj.FillHistogram(dirname,histname,4000,0,8000,hit1.GetCoreEnergy(), + // 4000,0,8000,hit2.GetCoreEnergy()); + // histname="gg_matrix_clean"; + // obj.FillHistogram(dirname,histname,4000,0,8000,hit2.GetCoreEnergy(), + // 4000,0,8000,hit1.GetCoreEnergy()); + //} + } + + //for(int y=0;y36) + // continue; + // histname = Form("GretinaSummaryX%02i",hit.GetCrystalId()); + // obj.FillHistogram(dirname,histname,40,0,40,hit.GetSegmentId(y), + // 1000,0,4000,hit.GetSegmentEng(y)); + + // int layer = hit.GetSegmentId(y)/6; + // histname = Form("position_%s",LayerMap[layer].c_str()); + // double phi = hit.GetIntPosition(y).Phi(); + // if(phi<0) phi +=TMath::Pi()*2; + // if(hit.GetPad()==0) { + // obj.FillHistogram(dirname,histname, + // 628,0.0,6.28,phi, + // 314,0,3.14,hit.GetIntPosition(y).Theta()); + // } + //} + } + return true; +} + + +bool HandleLaBr(TRuntimeObjects &obj,GCutG *outgoing=0) { + + TFastScint *labr = obj.GetDetector(); + if(!labr) + return false; + + std::string dirname = "labr"; + std::string histname; + + for(unsigned int x=0;xSize();x++) { + if(labr->GetLaBrHit(x).GetChannel()==15) { + histname="chan_15"; + obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge()); + + histname="chan_15_time"; + obj.FillHistogram(dirname,histname,130,0,3600,labr->Timestamp()/(double)1e8, + 4000,0,4000,labr->GetLaBrHit(x).Charge()); + + histname="chan_15_time_energy"; + obj.FillHistogram(dirname,histname,16000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), + 4000,0,4000,labr->GetLaBrHit(x).Charge()); + } + TGretina *gretina = obj.GetDetector(); + if(gretina) { + std::string gdirname = "gretina"; + histname = "labr_gretina"; + for(int y=0;ySize();y++) { + obj.FillHistogram(gdirname,histname,4000,0,8000,gretina->GetGretinaHit(y).GetCoreEnergy(), + 4000,0,4000,labr->GetLaBrHit(x).GetEnergy()); + + + } + } + if(labr->GetLaBrHit(x).GetChannel()==0) { + histname="chan_0"; + obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge()); + + histname="chan_0_time"; + obj.FillHistogram(dirname,histname,130,0,3600,labr->Timestamp()/(double)1e8, + 4000,0,4000,labr->GetLaBrHit(x).Charge()); + + + } + + + histname="summary"; + obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + histname="summary_cal"; + obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).GetEnergy(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + + histname="summary_time"; + obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetLaBrHit(x).GetTime(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + + + //if(labr->GetRefTime() >100 && labr->GetLaBrHit(x).GetTime() >100 ) { + if(labr->GetRefTime() >100 && labr->GetLaBrHit(x).GetTime() >100 && labr->GetLaBrHit(x).Charge() >100 ) { + //if(labr->GetLaBrHit(x).Charge() >100 ) { + histname="summary_time_ref"; + obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + histname="energy_time_ref"; + obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), + 4000,0,4000,labr->GetLaBrHit(x).GetEnergy()); + + + } + } + + + return true; +} + + +bool HandleS800(TRuntimeObjects &obj,GCutG *outgoing=0) { + + TS800 *s800 = obj.GetDetector(); + if(!s800) + return false; + + std::string dirname = "s800"; + std::string histname; + + histname="e1_charge"; + obj.FillHistogram(dirname,histname,2000,0,2000,s800->GetScint().GetEUp()); + + histname="reg"; + obj.FillHistogram(dirname,histname,300,0,300,s800->GetTrigger().GetRegistr()); + + + TGretina *gretina = obj.GetDetector(); + if(gretina) { + std::string gdirname = "gretina"; + histname = "e1_gretina"; + for(int y=0;ySize();y++) { + obj.FillHistogram(gdirname,histname,4000,0,8000,gretina->GetGretinaHit(y).GetCoreEnergy(), + 2000,0,2000,s800->GetScint().GetEUp()); + + + } + } + + + return true; +} + + +bool HandleS800Gated(TRuntimeObjects &obj,GCutG *incoming=0, GCutG *outgoing=0) { + TS800 *s800 = obj.GetDetector(); + + if( !s800) + return false; + + std::string dirname = "s800_gated"; + std::string histname; + + histname = Form("CRDC1_X_%s_%s",incoming->GetName(),outgoing->GetName()); + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); + + histname = Form("CRDC2_X_%s_%s",incoming->GetName(),outgoing->GetName()); + obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); + + histname = Form("time_x_%s_%s",incoming->GetName(),outgoing->GetName()); + obj.FillHistogram(dirname,histname,2000,-6000,-3000,s800->GetMTOF_ObjE1(), + 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); + + + if(test && test->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge()) ) { + + } + return true; +} + +bool HandleGretinaGated(TRuntimeObjects &obj,GCutG *incoming=0, GCutG *outgoing=0) { + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname; //= "gretina"; + if(incoming) + dirname = Form("gretina_%s",incoming->GetName()); + else + dirname = "gretina"; + std::string histname; + + + //if(!outgoing || !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge())) + if(!outgoing || !outgoing->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge())) { + if(!outgoing) + std::cout << "no gate!" << std::endl; + return false; + } + //if(!incoming || !incoming->IsInside(s800->GetMTOF_ObjE1(),s800->GetMTOF_XfpE1())) + // return false; + + //histname = Form("gretina_%s_%s",incoming->GetName(),outgoing->GetName()); + histname = Form("gretina_%s_%s",incoming->GetName(),outgoing->GetName()); + + for(unsigned int x=0;xSize();x++) { + obj.FillHistogram(dirname,histname,2500,0,10000, + gretina->GetGretinaHit(x).GetDoppler(GValue::Value("BETA"))); + //for(unsigned int y=x+1;ySize();y++) { + //histname = Form("matrix_%s_%s",incoming->GetName(),outgoing->GetName()); + // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetGretinaHit(x).GetDoppler(GValue::Value("BETA")), + // 625,0,10000,gretina->GetGretinaHit(y).GetDoppler(GValue::Value("BETA"))); + // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetGretinaHit(y).GetDoppler(GValue::Value("BETA")), + // 625,0,10000,gretina->GetGretinaHit(x).GetDoppler(GValue::Value("BETA"))); + //} + } + + histname = Form("addback_%s_%s",incoming->GetName(),outgoing->GetName()); + for(unsigned int x=0;xAddbackSize();x++) { + obj.FillHistogram(dirname,histname,2500,0,10000, + gretina->GetAddbackHit(x).GetDoppler(GValue::Value("BETA"))); + //for(unsigned int y=x+1;yAddbackSize();y++) { + // histname = Form("addback_matrix_%s_%s",incoming->GetName(),outgoing->GetName()); + // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetAddbackHit(x).GetDoppler(GValue::Value("BETA")), + // 625,0,10000,gretina->GetAddbackHit(y).GetDoppler(GValue::Value("BETA"))); + // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetAddbackHit(y).GetDoppler(GValue::Value("BETA")), + // 625,0,10000,gretina->GetAddbackHit(x).GetDoppler(GValue::Value("BETA"))); + //} + } + + + double sum = 0; + for(unsigned int i=0; iSize(); i++) { + sum += gretina->GetGretinaHit(i).GetDoppler(GValue::Value("BETA")); + } + obj.FillHistogram(dirname, Form("calorimeter_%s_%s", incoming->GetName(), outgoing->GetName()), + 2500, 0, 10000, sum); + + double sum2 = 0; + for(unsigned int i=0; iAddbackSize(); i++) { + sum2 += gretina->GetAddbackHit(i).GetDoppler(GValue::Value("BETA")); + } + obj.FillHistogram(dirname, Form("abcalorimeter_%s_%s", incoming->GetName(), outgoing->GetName()), + 2500, 0, 10000, sum2); + + return true; +} + +bool HandleLaBrGated(TRuntimeObjects &obj,GCutG *incoming=0,GCutG *outgoing=0) { + + TFastScint *labr = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + if(!labr || !s800) + return false; + + std::string dirname = "labr"; + std::string histname; + + //if(!outgoing || !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge())) + if(!outgoing || !outgoing->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge())) + return false; + //if(!incoming || !incoming->IsInside(s800->GetMTOF_ObjE1(),s800->GetMTOF_XfpE1())) + // return false; + + for(unsigned int x=0;xSize();x++) { + histname = Form("summary_%s_%s",incoming->GetName(),outgoing->GetName()); + obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + histname = Form("summary_cal_%s_%s",incoming->GetName(),outgoing->GetName()); + obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).GetEnergy(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + + histname = Form("summary_time_%s_%s",incoming->GetName(),outgoing->GetName()); + obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetLaBrHit(x).GetTime(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + if(labr->GetRefTime() >100 && labr->GetLaBrHit(x).GetTime() >100 && labr->GetLaBrHit(x).Charge() >100 ) { + histname=Form("summary_time_ref_%s_%s",incoming->GetName(),outgoing->GetName()); + obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), + 32,0,32,labr->GetLaBrHit(x).GetChannel()); + } + } + + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + TBank88 *bank29 = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + TFastScint *labr = obj.GetDetector(); + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + + if(gates_loaded!=gates->GetSize()) { + TIter iter(gates); + while(TObject *obj = iter.Next()) { + GCutG *gate = (GCutG*)obj; + std::string tag = gate->GetTag(); + if(!tag.compare("incoming")) { + incoming_cuts.push_back(gate); + std::cout << "incoming: << " << gate->GetName() << std::endl; + } else if(!tag.compare("outgoing")) { + outgoing_cuts.push_back(gate); + std::cout << "outgoing: << " << gate->GetName() << std::endl; + } else if(!tag.compare("test")) { + //outgoing_cuts.push_back(gate); + test = gate; + std::cout << "outgoing: << " << gate->GetName() << std::endl; + } else if(!tag.compare("gretina")) { + std::string cutname = gate->GetName(); + if(!cutname.compare("timing")) { + gg_timing_gate=new GCutG(*gate); + //gg_timing_gate->Print(); + } + } else { + std::cout << "unknown: << " << gate->GetName() << std::endl; + } + gates_loaded++; + } + std::cout << "outgoing size: " << outgoing_cuts.size() << std::endl; + } + + std::string histname = ""; + std::string dirname = ""; + + if(bank29) { + dirname = "Bank88"; + for(unsigned int x=0;xSize();x++) { + TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); + dirname = "Bank88"; + histname = Form("bank29_%i",hit.GetChannel()); + obj.FillHistogram(dirname,histname, + 16000,0,64000,hit.Charge()); + } + if(s800) { + histname = "S800_Bank88_time"; + obj.FillHistogram(dirname,histname, + 200,-200,200,bank29->Timestamp()-s800->Timestamp()); + + histname = "S800_Bank88_runtime"; + obj.FillHistogram(dirname,histname, + 3600,0,3600,bank29->Timestamp()*1e-8, + 1000,-1000,1000,bank29->Timestamp()-s800->Timestamp()); + histname = Form("S800_Bank88_runtime_Reg%i",s800->GetTrigger().GetRegistr()); + obj.FillHistogram(dirname,histname, + 3600,0,3600,bank29->Timestamp()*1e-8, + 1000,-1000,1000,bank29->Timestamp()-s800->Timestamp()); + } + if(gretina) { + for(int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "Gretina_Bank88_time"; + obj.FillHistogram(dirname,histname, + 600,-600,600,bank29->Timestamp()-hit.Timestamp(), + 2000,0,4000,hit.GetCoreEnergy()); + histname = "Gretina_t0_Bank88_time"; + obj.FillHistogram(dirname,histname, + 600,-600,600,bank29->Timestamp()-hit.GetTime(), + 2000,0,4000,hit.GetCoreEnergy()); + } + } + if(labr) { + histname = "labr_Bank88_time"; + obj.FillHistogram(dirname,histname, + 600,-600,600,bank29->Timestamp()-labr->Timestamp()); + + } + } + + std::vector incoming_passed; + std::vector outgoing_passed; + + for(unsigned int x=0;x0)) { + passed = IncomingBeam(obj,outgoing_cuts.at(x)); + } + if(x!=0 && passed) { + outgoing_passed.push_back(x); + //break; + } + } + + + HandleGretina(obj); + HandleLaBr(obj); + HandleS800(obj); + + for(unsigned int i=0; iGetName() << std::endl; + //HandleGretinaGated(obj,0,outgoing_cuts.at(outgoing_passed.at(j))); + HandleLaBrGated(obj,incoming_cuts.at(incoming_passed.at(i)),outgoing_cuts.at(outgoing_passed.at(j))); + //HandleS800Gated(obj,0,outgoing_cuts.at(outgoing_passed.at(j))); + } + } + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/PolarHists.cxx b/histos/PolarHists.cxx deleted file mode 100644 index 529d5228..00000000 --- a/histos/PolarHists.cxx +++ /dev/null @@ -1,287 +0,0 @@ - - -#include "TRuntimeObjects.h" - - - -#include -#include - - - -#include - - - -#include -#include -#include -#include "TRandom.h" - - - -#include "TObject.h" -#include "TGretina.h" -#include "TBank29.h" - -#include "GValue.h" - -//std::map HoleQMap; -std::map LayerMap; - -void InitMap() { -// HoleQMap[Q1] = 1; -// HoleQMap[Q2] = 2; -// HoleQMap[Q3] = 3; -// HoleQMap[Q4] = 4; -// HoleQMap[Q5] = 5; -// HoleQMap[Q6] = 6; -// HoleQMap[Q7] = 7; -// HoleQMap[Q8] = 8; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; -} - -#define INTEGRATION 128.0 - - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -// - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - static int entry = 0; - - double BETA = GValue::Value("BETA"); - - if(bank29) { -// for(int x=0;xSize();x++) { -// TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); -// std::string histname = Form("bank29_%i",hit.GetChannel()); -// TH1 *hist = (TH1*)list->FindObject(histname.c_str()); -// if(!hist) { -// hist= new TH1F(histname.c_str(),histname.c_str(),16000,0,64000); -// list->Add(hist); -// } -// hist->Fill(hit.Charge()); -// } - } - - if(!gretina || gretina->Size()<1 ) { //|| gretina->Size()>(7*4)) { - entry++; - //printf("Here\n"); fflush(stdout); - return; - } - - static double first_time = ((double)gretina->Timestamp())/1e8; - - double gsum = 0.0; - int largesthit = -1; - double largesteng = -1.0; - for(unsigned int y=0;ySize();y++) { - TGretinaHit hit = gretina->GetGretinaHit(y); - //if(hit.NumberOfInteractions()<1 || hit.GetSegmentId(0)<1 || hit.GetPad()>0) - // continue; - - std::string histname; - gsum += hit.GetCoreEnergy(0); - if(hit.GetCoreEnergy(0)>largesteng) { - largesteng = hit.GetCoreEnergy(0); - largesthit = y; - } - for(unsigned int z=y+1;zSize();z++) { - TGretinaHit hit2 = gretina->GetGretinaHit(z); - //if(hit2.NumberOfInteractions()<1 || hit2.GetSegmentId(0)<1 || hit2.GetPad()>0) - // continue; - histname = "Gamma_Gamma"; - obj.FillHistogramSym(histname,2000,0,4000,hit.GetCoreEnergy(0), - 2000,0,4000,hit2.GetCoreEnergy(0)); - histname = "Gamma_Gamma_Time"; - obj.FillHistogram(histname,800,-400,400,hit2.GetTime()-hit.GetTime(), - 2000,0,4000,hit2.GetCoreEnergy(0)); - obj.FillHistogram(histname,800,-400,400,hit.GetTime()-hit2.GetTime(), - 2000,0,4000,hit.GetCoreEnergy(0)); - } - - histname = "Gretina_Energy_Time"; - obj.FillHistogram(histname,1000,0,4000,hit.GetCoreEnergy(0), - 5000,0,5000,gretina->Timestamp()/1e8-first_time); - - histname = Form("Gretina%03i_Energy_Time",hit.GetCrystalId()); - obj.FillHistogram(histname,1000,0,4000,hit.GetCoreEnergy(0), - 5000,0,5000,gretina->Timestamp()/1e8-first_time); - - histname = "Gretina_Energy_Entry"; - obj.FillHistogram(histname,1000,0,4000,hit.GetCoreEnergy(0), - 9000,0,9000000,entry); - entry++; - - - //histname = "GretinaDopplerBeta"; - //std::string histnamecal = "GretinaDopplerBetaCal"; - //double beta = 0.00; - //double betamax = 0.005; - //for(int z=0;z<100;z++) { - // beta += betamax/100.0; - //printf("GetDoppler%.02f() = %.02f\n",beta,hit.GetDoppler(beta)); - //hit.GetPosition().Print(); - // obj.FillHistogram(histname,8000,0,4000,hit.GetDoppler(beta), - // 101,0.00,betamax,beta); - // obj.FillHistogram(histnamecal,8000,0,4000,hit.GetDoppler(0,beta), - // 101,0.00,betamax,beta); - //} - - histname = "GretinaDopplerPhi"; - obj.FillHistogram(histname,628,0,6.28,hit.GetPhi(), - 8000,0,4000,hit.GetDoppler(BETA)); - - histname = "GretinaDopplerXId"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,4000,hit.GetDoppler(BETA)); - - histname = "GretinaDopplerXIdCal"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,4000,hit.GetDoppler(0,BETA)); - - histname = "GretinaEnergyXId"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,4000,hit.GetCoreEnergy()); - - histname = "GretinaEnergyXIdCal"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,4000,hit.GetCoreEnergy(0)); - - histname = "GretinaCarge0XIdCal"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,32000,hit.GetCoreCharge(0)); - histname = "GretinaCarge1XIdCal"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,32000,hit.GetCoreCharge(1)); - histname = "GretinaCarge2XIdCal"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,32000,hit.GetCoreCharge(2)); - histname = "GretinaCarge3XIdCal"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId(), - 8000,0,32000,hit.GetCoreCharge(3)); - - - - - - - - - - - - histname = "GretinaEnergyTheta"; - obj.FillHistogram(histname,314,0,3.14,hit.GetTheta(), - 4000,0,4000,hit.GetCoreEnergy(0)); - - histname = "Gretina_Theta_bySegment"; - obj.FillHistogram(histname,314,0,3.14,hit.GetSegmentPosition().Theta(), - 4000,0,4000,hit.GetCoreEnergy(0)); - - histname = "Gretina_Theta_byCrystal"; - obj.FillHistogram(histname,314,0,3.14,hit.GetCrystalPosition().Theta(), - 4000,0,4000,hit.GetCoreEnergy(0)); - - histname = "Gretina_Theta_byDecomp"; - obj.FillHistogram(histname,314,0,3.14,hit.GetPosition().Theta(), - 4000,0,4000,hit.GetCoreEnergy(0)); - - histname = Form("GretinaPosition"); - obj.FillHistogram(histname,628,0,6.28,hit.GetPhi(), - 314,0,3.14,hit.GetTheta()); - - histname = "GretinaEnergySum"; - obj.FillHistogram(histname,8000,0,4000,hit.GetCoreEnergy(0)); - - histname = "GretinaDopplerSum"; - obj.FillHistogram(histname,8000,0,4000,hit.GetDoppler(BETA)); - - histname = "CrystalId_hitpattern"; - obj.FillHistogram(histname,200,0,200,hit.GetCrystalId()); - - if(hit.NumberOfInteractions()<1 || hit.GetSegmentId(0)<1 || hit.GetPad()>0) - continue; - - std::string layer; - if(hit.GetSegmentId(0)<7) - layer = "_1_alpha"; - else if(hit.GetSegmentId(0)<13) - layer = "_2_beta"; - else if(hit.GetSegmentId(0)<19) - layer = "_3_gamma"; - else if(hit.GetSegmentId(0)<25) - layer = "_4_delta"; - else if(hit.GetSegmentId(0)<31) - layer = "_5_epsilon"; - else if(hit.GetSegmentId(0)<37) - layer = "_6_phi"; - else - layer = "_7_unknown"; - - histname = "Gretina_Theta_bySegment"; - histname.append(layer); - obj.FillHistogram(histname,314,0,3.14,hit.GetSegmentPosition().Theta(), - 4000,0,4000,hit.GetCoreEnergy(0)); - - histname = "Gretina_Theta_byCrystal"; - histname.append(layer); - obj.FillHistogram(histname,314,0,3.14,hit.GetCrystalPosition().Theta(), - 4000,0,4000,hit.GetCoreEnergy(0)); - - histname = "Gretina_Theta_byDecomp"; - histname.append(layer); - obj.FillHistogram(histname,314,0,3.14,hit.GetPosition().Theta(), - 4000,0,4000,hit.GetCoreEnergy(0)); - - histname = "GretinaOverview"; - obj.FillHistogram(histname,4000,0,4000,hit.GetCoreEnergy(0), - 60,20,80,hit.GetCrystalId()); - - - /* - histname = Form("GretinaSummaryX%02i",hit.GetCrystalId()); - for(int z=0;z1) { - std::string histname = "GCalorimeter"; - obj.FillHistogram(histname,16000,0,8000,gsum); - - TGretinaHit hit = gretina->GetGretinaHit(largesthit); - histname = "GCalorimeter_Theta"; - obj.FillHistogram(histname,314,0,3.14,hit.GetTheta(), - 8000,0,8000,gsum); - } - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/include/DDASBanks.h b/include/DDASBanks.h index b9ee2244..428b9a61 100644 --- a/include/DDASBanks.h +++ b/include/DDASBanks.h @@ -14,11 +14,53 @@ struct DDASHeader{ } __attribute__((packed)); struct DDAS_QDC_Sum { - unsigned int qdc_sum[4]; + unsigned int qdc_sum[8]; } __attribute__((packed)); struct DDAS_Energy_Sum { - unsigned int energy_sum[8]; + unsigned int energy_sum[4]; } __attribute__((packed)); + +struct DDASGEBHeader{ //only at the start of the event... + //unsigned int size; // Size of DDAS packet, inclusive, number of 16-bit words + long time1; // time ?? + unsigned int source_id1; // source id + unsigned int size; // Actually size1, to satisfy TDDASEvent's requirements + unsigned int frequency; // Actually barrier1, to satisfy TDDASEvent's requirements + unsigned int adc_bits; // Actually size2, to satisfy TDDASEvent's requirements + unsigned int type; + unsigned int revision; // Actually size3, to satisfy TDDASEvent's requirements + long time2; //duplicate of time1? + unsigned int source_id2; //duplicate of source id1? + unsigned int barrier2; //duplicate of barrier1? + unsigned int body_words; //inclusize! + unsigned int device; //device info here | revision | freq + unsigned int status; + unsigned int time_low; + unsigned int time_high_cfd; + unsigned int energy_tracelength; +// unsigned int ext_time_low; +// unsigned int ext_time_high; + + // void print() { + // printf("--------------------------------\n"); + // printf("time1:time2 %lu \t %lu \n",time1,time2); + // printf("sid1:sid2 0x%08x \t 0x%08x \n",source_id1,source_id2); + // printf("sz1:sz2:sz3 0x%08x \t 0x%08x \t 0x%08x \n",size1,size2,size3); + // printf("br1:br2 0x%08x \t 0x%08x \n",barrier1,barrier2); + // printf("type: 0x%08x\n",type); + // printf("body words: 0x%08x\n",body_words); + // printf("status: 0x%08x\n",status); + // printf("wd1:wd2 0x%08x \t 0x%08x \n",word1,word2); + // printf("wd3:wd4 0x%08x \t 0x%08x \n",word3,word4); + // printf("wd5:wd6 0x%08x \t 0x%08x \n",word5,word6); + // printf("--------------------------------\n"); + // } + +} __attribute__((__packed__)); + + + + #endif /* _DDASBANKS_H_ */ diff --git a/include/DDASDataFormat.h b/include/DDASDataFormat.h index 8aead06d..2f3ae292 100644 --- a/include/DDASDataFormat.h +++ b/include/DDASDataFormat.h @@ -25,25 +25,74 @@ #define BIT29TO16MASK 0x3FFF0000 // Bits 29 through 16 #define BIT28TO16MASK 0x1FFF0000 // Bits 28 through 16 +#include "DDASBanks.h" +template class TDDASEvent : public TObject { public: -#include "DDASBanks.h" - - TDDASEvent(const TSmartBuffer& buf); + TDDASEvent(TSmartBuffer& buf) + : qdc_sum(NULL), energy_sum(NULL), trace(NULL), + header(NULL), buf(buf) { + header = (HeaderType*)buf.GetData(); + buf.Advance(sizeof(HeaderType)); + + if(HasEnergySum()){ + energy_sum = (DDAS_Energy_Sum*)buf.GetData(); + buf.Advance(sizeof(DDAS_Energy_Sum)); + } + + if(HasQDCSum()){ + qdc_sum = (DDAS_QDC_Sum*)buf.GetData(); + buf.Advance(sizeof(DDAS_QDC_Sum)); + } + + if(HasExternalClk()){ + ext_time_low = (*((unsigned int*)buf.GetData())); + buf.Advance(sizeof(unsigned int)); + ext_time_high = (*((unsigned int*)buf.GetData())); + buf.Advance(sizeof(unsigned int)); + } + + if(GetTraceLength()){ + trace = (unsigned short*)buf.GetData(); + buf.Advance(GetTraceLength()*sizeof(unsigned short)); + } + } DDAS_QDC_Sum* qdc_sum; DDAS_Energy_Sum* energy_sum; unsigned short* trace; - bool HasQDCSum() const; - bool HasEnergySum() const; + bool HasEnergySum() const { + return (GetChannelHeaderLength() == 8 || + GetChannelHeaderLength() == 10|| + GetChannelHeaderLength() == 16|| + GetChannelHeaderLength() == 18); + } + + + bool HasQDCSum() const { + return (GetChannelHeaderLength() == 12 || + GetChannelHeaderLength() == 14 || + GetChannelHeaderLength() == 16 || + GetChannelHeaderLength() == 18); + } + + bool HasExternalClk() const { + return (GetChannelHeaderLength() == 6 || + GetChannelHeaderLength() == 10 || + GetChannelHeaderLength() == 14 || + GetChannelHeaderLength() == 18); + } + unsigned int GetSize() const { return header->size; } unsigned short GetFrequency() const { return header->frequency; } unsigned char GetADCBits() const { return header->adc_bits; } unsigned char GetRevision() const { return header->revision; } + unsigned int GetAddress() const { return (0x19000000+(header->status&0x00000fff)); } + int GetChannelID() const { return (header->status & CHANNELIDMASK) >> 0; } int GetSlotID() const { return (header->status & SLOTIDMASK) >> 4; } int GetCrateID() const { return (header->status & CRATEIDMASK) >> 8; } @@ -57,20 +106,49 @@ class TDDASEvent : public TObject { unsigned long GetTimestamp() const { return (((unsigned long)GetTimeHigh())<<32) + GetTimeLow(); } + + unsigned int GetExternalTimeLow() const { return ext_time_low; } + unsigned int GetExternalTimeHigh() const { return (ext_time_high & LOWER16BITMASK); } + unsigned long GetExternalTimestamp() const { + return (((unsigned long)GetExternalTimeHigh())<<32) + GetExternalTimeLow(); + } + + + + int GetCFDFailBit() const { return (header->time_high_cfd & BIT31MASK) >> 31; } int GetCFDTime() const { return (header->time_high_cfd & BIT30TO16MASK) >> 16; } +// int GetTimestampCFD() const { +// if(GetCFDFailBit()) { +// return GetTimestamp()*8; +// } else { +// GetTimestamp()*2 +((GetCFDTime()&0x40000000)>>30) + +// } +// } + + int GetEnergy() const { return (header->energy_tracelength & LOWER16BITMASK); } int GetTraceLength() const { return (header->energy_tracelength & UPPER16BITMASK) >> 16; } + friend std::ostream& operator<<(std::ostream& out, const TDDASEvent& event) { + out << "DDAS Channel: \n"; + return out; + } + private: - DDASHeader* header; + HeaderType* header; TSmartBuffer buf; + unsigned int ext_time_low; + unsigned int ext_time_high; + ClassDef(TDDASEvent, 0); }; -std::ostream& operator<<(std::ostream& out, const TDDASEvent& event); + + + #endif /* _DDASDATAFORMAT_H_ */ diff --git a/include/GCanvas.h b/include/GCanvas.h index 322224fd..141ddc6b 100644 --- a/include/GCanvas.h +++ b/include/GCanvas.h @@ -6,10 +6,14 @@ #include "TRootCanvas.h" //#include "TPeak.h" -#include "TH1.h" #include "TLine.h" +//#include "TBuffer.h" + +class TF1; +class TH1; +class GH1; +class GH2; -#include "GH2I.h" class GMarker : public TObject{ public: @@ -57,6 +61,7 @@ class GPopup : public TGTransientFrame { class GCanvas : public TCanvas { public: GCanvas(Bool_t build = kTRUE); + GCanvas(int cols, int rows,Bool_t build=kTRUE); GCanvas(const char* name, const char* title = "", Int_t form = 1); GCanvas(const char* name, const char* title, Int_t ww, Int_t wh); GCanvas(const char* name, Int_t ww, Int_t wh, Int_t winid); @@ -87,11 +92,13 @@ class GCanvas : public TCanvas { bool fGuiEnabled; + GH1 *gHist; + //bool fStatsDisplayed; bool fMarkerMode; std::vector fMarkers; std::vector fBackgroundMarkers; - kBackgroundSubtraction fBackgroundMode; + //kBackgroundSubtraction fBackgroundMode; void AddMarker(int,int,int dim=1); void RemoveMarker(Option_t *opt=""); void OrderMarkers(); @@ -138,15 +145,16 @@ class GCanvas : public TCanvas { //bool PeakFitQ(GMarker *m1=0,GMarker *m2=0); //static int fBGSubtraction_type; + // + //void Streamer(TBuffer*); private: Window_t fCanvasWindowID; TRootCanvas *fRootCanvas; bool control_key; - bool toggle_control() { control_key = !control_key; return control_key; } - ClassDef(GCanvas,2); + ClassDef(GCanvas,10); }; #endif diff --git a/include/GCutG.h b/include/GCutG.h index ca63b691..e49cb92c 100644 --- a/include/GCutG.h +++ b/include/GCutG.h @@ -9,7 +9,8 @@ class GCutG : public TCutG { public: GCutG() : TCutG() { } - GCutG(const TCutG &cutg) : TCutG(cutg) { } + GCutG(const TCutG &cutg) : TCutG(cutg) { + if(cutg.InheritsFrom(GCutG::Class())) fTag=((GCutG&)cutg).fTag; } GCutG(const char *name,Int_t n=0) : TCutG(name,n) { } GCutG(const char *name,Int_t n,const Float_t *x,const Float_t *y) : TCutG(name,n,x,y) { } GCutG(const char *name,Int_t n,const Double_t *x,const Double_t *y) : TCutG(name,n,x,y) { } @@ -18,7 +19,8 @@ class GCutG : public TCutG { virtual void Print(Option_t *opt="") const; - int SaveTo(const char *cutname="",const char* filename="",Option_t* option="update"); // *MENU* + int SaveTo(const char *cutname="",const char* filename="", + const char *tagname="",Option_t* option="update"); // *MENU* void SetGateMethod(const char* xclass,const char* xmethod, @@ -26,9 +28,14 @@ class GCutG : public TCutG { bool IsInside(TObject *objx,TObject *objy=0); Int_t IsInside(Double_t x,Double_t y) const { return TCutG::IsInside(x,y); } + + void SetTag(const char *tag) { fTag = tag; } + const char *GetTag() { return fTag.Data(); } private: + TString fTag; + TString fXGateClass; TString fYGateClass; TString fXGateMethod; diff --git a/include/GDoubleGaus.h b/include/GDoubleGaus.h new file mode 100644 index 00000000..55b16758 --- /dev/null +++ b/include/GDoubleGaus.h @@ -0,0 +1,99 @@ +#ifndef GDOUBLEGAUS_H +#define GDOUBLEGAUS_H + +#include + +#include +#include + +class GDoubleGaus : public TF1 { + public: + //GDoubleGaus(Double_t xlow,Double_t xhigh,int bg_order=1,Option_t *opt="gsc"); make this a thing. pcb. + + GDoubleGaus(Double_t cent1,Double_t cent2,Double_t xlow,Double_t xhigh,Option_t *opt="gsc"); + + GDoubleGaus(const GDoubleGaus&); + GDoubleGaus(); + virtual ~GDoubleGaus(); + + void Copy(TObject&) const; + void Print(Option_t *opt="") const; + void Clear(Option_t *opt=""); + + void InitNames(); + bool InitParams(TH1* fithist = 0,double cent1=0,double cent2=1); + bool Fit(TH1*,double c1,double c2,Option_t *opt=""); + void DrawResiduals(TH1*) const; + //void DrawResiduals(); // *MENU* + + TF1 *Background(Option_t *opt="TF1") { return &fBGFit; } + //void DrawBackground(Option_t* opt = "SAME") const; // *MENU* + + Double_t GetCentroid1() const { return GetParameter("centroid1"); } + Double_t GetCentroid1Err() const { return GetParError(GetParNumber("centroid1")); } + + Double_t GetCentroid2() const { return GetParameter("centroid2"); } + Double_t GetCentroid2Err() const { return GetParError(GetParNumber("centroid2")); } + + Double_t GetAreaTotal() const { return fAreaTotal; } + Double_t GetAreaTotalErr() const { return fDAreaTotal; } + + Double_t GetSumTotal() const { return fSumTotal; } + Double_t GetSumTotalErr() const { return fDSumTotal; } + + Double_t GetFWHM() const { return GetParameter("sigma")*2.3548;} + Double_t GetFWHMErr() const { return GetParError(GetParNumber("sigma"))*2.3548;} + + + + + protected: + void SetAreaTotal(Double_t a) { fAreaTotal = a; } + void SetAreaTotalErr(Double_t d_a) { fDAreaTotal = d_a; } + void SetSumTotal(Double_t a) { fSumTotal = a; } + void SetSumTotalErr(Double_t d_a) { fDSumTotal = d_a; } + void SetAreaTotal(Double_t a, Double_t dA) { SetAreaTotal(a); SetAreaTotalErr(dA);} + void SetChi2(Double_t chi2) { fChi2 = chi2; } + void SetNdf(Double_t Ndf) { fNdf = Ndf; } + + public: + //void CheckArea(); + //void CheckArea(Double_t int_low, Double_t int_high); + //static Bool_t CompareEnergy(const GDoubleGaus& lhs, const GDoubleGaus& rhs) {return lhs.GetCentroid() +#include + +class GGraph : public TGraphErrors { + public: + GGraph() : TGraphErrors() { } + GGraph(int n) : TGraphErrors(n) { } + GGraph(int n,float *x,float *y,float *dy=0,float *dx=0) + : TGraphErrors(n,x,y,dx,dy) { } + GGraph(int n,double *x,double *y,double *dy=0,double *dx=0) + : TGraphErrors(n,x,y,dx,dy) { } + GGraph(const GGraph &gr) : TGraphErrors((TGraphErrors&)gr) { } + GGraph(const TGraphErrors &gr) : TGraphErrors(gr) { } + GGraph(const TH1 *h) : TGraphErrors(h) { } + GGraph(const char *filename,const char *format="%lg %lg %lg %lg",Option_t *opt="") + : TGraphErrors(filename,format,opt) { } + + virtual ~GGraph() { } + + private: + + TRef parent; + + ClassDef(GGraph,1) +}; + +#endif + diff --git a/include/GGraph2D.h b/include/GGraph2D.h new file mode 100644 index 00000000..52bf775e --- /dev/null +++ b/include/GGraph2D.h @@ -0,0 +1,30 @@ +#ifndef __GGRAPH2D_H__ +#define __GGRAPH2D_H__ + +#include + +class GGraph; + +class GGraph2D : public TGraph2DErrors { + public: + GGraph2D() : TGraph2DErrors() { } + GGraph2D(int n,double *x,double *y,double *z,double *dz=0,double *dy=0,double *dx=0) + : TGraph2DErrors(n,x,y,z,dx,dy,dx) { } + GGraph2D(const char *name,const char *title, + int n,double *x,double *y,double *z,double *dz=0,double *dy=0,double *dx=0) + : TGraph2DErrors(n,x,y,z,dx,dy,dx) { this->SetNameTitle(name,title); } + + GGraph2D(const char *filename,Option_t *opt=""); + + + GGraph *ProjectionX(double low, double high,Option_t *opt="draw") const; + GGraph *ProjectionY(double low, double high,Option_t *opt="draw") const; + + private: + + + ClassDef(GGraph2D,1) +}; + +#endif + diff --git a/include/GH1.h b/include/GH1.h new file mode 100644 index 00000000..e0a9cb21 --- /dev/null +++ b/include/GH1.h @@ -0,0 +1,64 @@ +#ifndef __GH1_H__ +#define __GH1_H__ + +#include +#include + +class GH1D; + + + +class GH1 : public TH1 { + protected: + GH1() : TH1(), fProjectionAxis(kNoAxis) { } + GH1(const char *name,const char *title,int nbinsx,double xlow,double xhigh) : + TH1(name,title,nbinsx,xlow,xhigh),fProjectionAxis(kNoAxis) { } + GH1(const char *name,const char *title,int nbinsx,const double *xbins) : + TH1(name,title,nbinsx,xbins),fProjectionAxis(kNoAxis) { } + GH1(const char *name,const char *title,int nbinsx,const float *xbins) : + TH1(name,title,nbinsx,xbins),fProjectionAxis(kNoAxis) { } + + public: + virtual ~GH1() { } + + enum { kIsSummary = BIT(20) }; + + TH1 *GetNext() { return 0; } + TH1 *GetPrevious() { return 0; } + + //GH1D *Project(double low=sqrt(-1),double high=(sqrt(-1)); + //GH1D *Project(double low,double high,double bg_low,double bg_high,double scale=-1) { return 0; } + GH1D *Project(int low=0,int high=-1); + GH1D *Project(int low,int high,int bg_low,int bg_high,double scale=-1); + + TObject *GetHistParent() const { return fParent.GetObject(); } + void SetParent(TObject *obj) { fParent = obj; } + + void SetProjectionAxis(int axis) { fProjectionAxis = axis; } + int GetProjectionAxis() const { return fProjectionAxis; } + + virtual bool IsSummary() const { return TestBit(kIsSummary); } + + double FitEval(double *,double*); + TF1 *ConstructTF1() const; + bool WriteDatFile(const char *outFile); + + void Draw(Option_t *opt=""); + + void Calibrate(double offset,double gain,int axis=1); // *MENU* + + + + private: + TRef fParent; + int fProjectionAxis; //! + + protected: + virtual void SetSummary(bool flag=true) { SetBit(kIsSummary,flag); } + + friend class GH2; + + ClassDef(GH1,1) +}; + +#endif diff --git a/include/GH1D.h b/include/GH1D.h index 57af1b31..1966e993 100644 --- a/include/GH1D.h +++ b/include/GH1D.h @@ -1,90 +1,54 @@ -#ifndef GH1D_H -#define GH1D_H +#ifndef _GH1D_H +#define _GH1D_H + +#include +#include + +class GH1D : public GH1, public TArrayD { + public: + GH1D(); + GH1D(const char *name,const char *title,int nbinsx,double xlow,double xhigh); + GH1D(const char *name,const char *title,int nbinsx,const double *xbins); + GH1D(const char *name,const char *title,int nbinsx,const float *xbins); + explicit GH1D(const TVectorD &v); + GH1D(const GH1D &h1d); + GH1D(const TH1 &h1d); + GH1D& operator=(const GH1D &h1); + virtual ~GH1D() { } + + virtual void AddBinContent(int bin) { ++fArray[bin]; } + virtual void AddBinContent(int bin,double w) { fArray[bin]+=(double)w; } + + virtual void Copy(TObject &hnew) const; + virtual void Reset(Option_t *opt=""); + virtual void SetBinsLength(int n=-1); + + //Int_t Write(const char *name="",Int_t option=0,Int_t bufsize=0) const; + + + protected: + virtual double RetrieveBinContent(int bin) const { return fArray[bin]; } + virtual void UpdateBinContent(int bin,double content) { fArray[bin]=content; } -#include "TH1.h" -#include "TRef.h" - -#include "GH2I.h" - -class TF1; -class TClass; -class TMethodCall; - -class GPeak; - -class GH1D : public TH1D { -public: - GH1D() : TH1D(), parent(NULL), projection_axis(-1),fFillClass(0),fFillMethod(0) { } - GH1D(const TVectorD& v) - : TH1D(v), parent(NULL), projection_axis(-1),fFillClass(0),fFillMethod(0) { } - GH1D(const char* name, const char* title, Int_t nbinsx, const Float_t* xbins) - : TH1D(name, title, nbinsx, xbins), parent(NULL), projection_axis(-1),fFillClass(0),fFillMethod(0) { } - GH1D(const char* name, const char* title, Int_t nbinsx, const Double_t* xbins) - : TH1D(name, title, nbinsx, xbins), parent(NULL), projection_axis(-1),fFillClass(0),fFillMethod(0) { } - GH1D(const char* name, const char* title, Int_t nbinsx, Double_t xlow, Double_t xup) - : TH1D(name, title, nbinsx, xlow, xup), parent(NULL), projection_axis(-1),fFillClass(0),fFillMethod(0) { } - - GH1D(const TF1& function,Int_t nbinsx,Double_t xlow,Double_t xup); - - GH1D(const TH1& source); - //GH1D(const TH1 *source); - //virtual void SetOption(Option_t* option=" "); - - TObject* GetParent() const { return parent.GetObject(); } - void SetParent(TObject* obj) { parent = obj; } - - int GetProjectionAxis() const { return projection_axis; } - void SetProjectionAxis(int axis) { projection_axis = axis; } - - virtual Int_t Fill(const TObject* obj); - virtual Int_t Fill(double x) { return TH1D::Fill(x); } - virtual Int_t Fill(double x,double w) { return TH1D::Fill(x,w); } - virtual Int_t Fill(const char *name,double w) { return TH1D::Fill(name,w); } - - void Clear(Option_t* opt=""); - void Print(Option_t* opt="") const; - void Copy(TObject& obj) const; - void Draw(Option_t* opt=""); - TH1 *DrawCopy(Option_t *opt="") const; - TH1 *DrawNormalized(Option_t *opt="",Double_t norm=1) const; - - bool WriteDatFile(const char *outFile); - - GH1D* Project(int bins=-1); - - GH1D* GetPrevious(bool DrawEmpty=false) const; - GH1D* GetNext(bool DrawEmpty=false) const; - - GH1D* Project(double bin_low, double bin_high) const; - GH1D* Project_Background(double bin_low, double bin_high, - double bg_bin_low, double bg_bin_high, - kBackgroundSubtraction mode = kRegionBackground) const; - - void SetFillMethod(const char *classname,const char *methodname,const char* param=""); - //void SetGateMethod(const char *classname,const char *methodnamex,const char* paramx="", - // const char *methodnamey="",const char* paramy=""); - //void SetGateMethod(const char *classname,const char *methodnamex, - // const char *classname,const char *methodnamey, - // const char* paramx="",const char* paramy=""); + ClassDef(GH1D,4) + + public: + friend GH1D operator*(double c1, const GH1D &h1); + friend GH1D operator*(const GH1D &h1,double c1); + friend GH1D operator*(const GH1D &h1,const GH1D &h2); + friend GH1D operator/(const GH1D &h1,const GH1D &h2); + friend GH1D operator+(const GH1D &h1,const GH1D &h2); + friend GH1D operator-(const GH1D &h1,const GH1D &h2); +}; - GPeak* DoPhotoPeakFit(double xlow,double xhigh,Option_t *opt=""); // *MENU* - GPeak* DoPhotoPeakFitNormBG(double xlow,double xhigh,Option_t *opt=""); // *MENU* - - double GetLastXlow() const { return xl_last;} - double GetLastXhigh() const { return xh_last;} - -private: - TRef parent; - int projection_axis; - - TClass *fFillClass; //! - TMethodCall *fFillMethod; //! +GH1D operator*(double c1,const GH1D &h1); +inline GH1D operator*(const GH1D &h1,double c1) { return operator*(c1,h1); } +GH1D operator*(const GH1D &h1,const GH1D &h2); +GH1D operator/(const GH1D &h1,const GH1D &h2); +GH1D operator+(const GH1D &h1,const GH1D &h2); +GH1D operator-(const GH1D &h1,const GH1D &h2); - double xl_last; //! - double xh_last; //! - ClassDef(GH1D,1) -}; #endif /* GH1D_H */ diff --git a/include/GH2.h b/include/GH2.h new file mode 100644 index 00000000..e5b8340e --- /dev/null +++ b/include/GH2.h @@ -0,0 +1,150 @@ +#ifndef __GH2_H_ +#define __GH2_H_ + +#include + +#include +#include +#include +#include + +class TProfile; + +class GH2 : public GH1 { + protected: + Double_t fScalefactor; //Scale factor + Double_t fTsumwy; //Total Sum of weight*Y + Double_t fTsumwy2; //Total Sum of weight*Y*Y + Double_t fTsumwxy; //Total Sum of weight*X*Y + + GH2(); + GH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup + ,Int_t nbinsy,Double_t ylow,Double_t yup); + GH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins + ,Int_t nbinsy,Double_t ylow,Double_t yup); + GH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup + ,Int_t nbinsy,const Double_t *ybins); + GH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins + ,Int_t nbinsy,const Double_t *ybins); + GH2(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins + ,Int_t nbinsy,const Float_t *ybins); + + virtual Int_t BufferFill(Double_t x, Double_t y, Double_t w); + virtual GH1D *DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const; + virtual TProfile *DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const; + virtual GH1D *DoQuantiles(bool onX, const char *name, Double_t prob) const; + virtual void DoFitSlices(bool onX, TF1 *f1, Int_t firstbin, Int_t lastbin, + Int_t cut, Option_t *option, TObjArray* arr); + + Int_t BufferFill(Double_t, Double_t) {return -2;} //may not use + Int_t Fill(Double_t); //MayNotUse + Int_t Fill(const char*, Double_t) { return Fill(0);} //MayNotUse + + private: + + GH2(const GH2&); + GH2& operator=(const GH2&); // Not implemented + + public: + operator TH2*() {return (TH2*)((TH1*)this) ; } + + virtual ~GH2(); + virtual Int_t BufferEmpty(Int_t action=0); + virtual void Copy(TObject &hnew) const; + virtual Int_t Fill(Double_t x, Double_t y); + virtual Int_t Fill(Double_t x, Double_t y, Double_t w); + virtual Int_t Fill(Double_t x, const char *namey, Double_t w); + virtual Int_t Fill(const char *namex, Double_t y, Double_t w); + virtual Int_t Fill(const char *namex, const char *namey, Double_t w); + virtual void FillN(Int_t, const Double_t *, const Double_t *, Int_t) {;} //MayNotUse + virtual void FillN(Int_t ntimes, const Double_t *x, const Double_t *y, const Double_t *w, Int_t stride=1); + virtual void FillRandom(const char *fname, Int_t ntimes=5000); + virtual void FillRandom(GH1 *h, Int_t ntimes=5000); + virtual Int_t FindFirstBinAbove(Double_t threshold=0, Int_t axis=1) const; + virtual Int_t FindLastBinAbove (Double_t threshold=0, Int_t axis=1) const; + virtual void FitSlicesX(TF1 *f1=0,Int_t firstybin=0, Int_t lastybin=-1, + Int_t cut=0, Option_t *option="QNR", TObjArray* arr = 0); // *MENU* + virtual void FitSlicesY(TF1 *f1=0,Int_t firstxbin=0, Int_t lastxbin=-1, + Int_t cut=0, Option_t *option="QNR", TObjArray* arr = 0); // *MENU* + virtual Int_t GetBin(Int_t binx, Int_t biny, Int_t binz = 0) const; + virtual Double_t GetBinWithContent2(Double_t c, Int_t &binx, Int_t &biny, + Int_t firstxbin=1, Int_t lastxbin=-1, + Int_t firstybin=1, Int_t lastybin=-1, Double_t maxdiff=0) const; + virtual Double_t GetBinContent(Int_t bin) const { return GH1::GetBinContent(bin); } + virtual Double_t GetBinContent(Int_t binx, Int_t biny) const + { return GH1::GetBinContent( GetBin(binx, biny) ); } + virtual Double_t GetBinContent(Int_t binx, Int_t biny, Int_t) const + { return GH1::GetBinContent( GetBin(binx, biny) ); } + using GH1::GetBinErrorLow; + using GH1::GetBinErrorUp; + virtual Double_t GetBinErrorLow(Int_t binx, Int_t biny) { return GH1::GetBinErrorLow( GetBin(binx, biny) ); } + virtual Double_t GetBinErrorUp(Int_t binx, Int_t biny) { return GH1::GetBinErrorUp( GetBin(binx, biny) ); } + virtual Double_t GetCorrelationFactor(Int_t axis1=1,Int_t axis2=2) const; + virtual Double_t GetCovariance(Int_t axis1=1,Int_t axis2=2) const; + virtual void GetRandom2(Double_t &x, Double_t &y); + virtual void GetStats(Double_t *stats) const; + virtual Double_t Integral(Option_t *option="") const; + //virtual Double_t Integral(Int_t, Int_t, Option_t * ="") const {return 0;} + using GH1::Integral; + virtual Double_t Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Option_t *option="") const; + virtual Double_t Integral(Int_t, Int_t, Int_t, Int_t, Int_t, Int_t, Option_t * ="") const {return 0;} + using GH1::IntegralAndError; + virtual Double_t IntegralAndError(Int_t binx1, Int_t binx2, + Int_t biny1, Int_t biny2, Double_t & err, Option_t *option="") const; + virtual Double_t Interpolate(Double_t x); + virtual Double_t Interpolate(Double_t x, Double_t y); + virtual Double_t Interpolate(Double_t x, Double_t y, Double_t z); + virtual Double_t KolmogorovTest(const GH1 *h2, Option_t *option="") const; + virtual Long64_t Merge(TCollection *list); + virtual GH2 *RebinX(Int_t ngroup=2, const char *newname=""); + virtual GH2 *RebinY(Int_t ngroup=2, const char *newname=""); + virtual GH2 *Rebin2D(Int_t nxgroup=2, Int_t nygroup=2, const char *newname=""); + TProfile *ProfileX(const char *name="_pfx", Int_t firstybin=1, Int_t lastybin=-1, Option_t *option="") const; // *MENU* + TProfile *ProfileY(const char *name="_pfy", Int_t firstxbin=1, Int_t lastxbin=-1, Option_t *option="") const; // *MENU* + GH1D *ProjectionX(const char *name="_px", Int_t firstybin=0, Int_t lastybin=-1, Option_t *option="+") const; // *MENU* + GH1D *ProjectionY(const char *name="_py", Int_t firstxbin=0, Int_t lastxbin=-1, Option_t *option="+") const; // *MENU* + virtual void PutStats(Double_t *stats); + GH1D *QuantilesX(Double_t prob = 0.5, const char * name = "_qx" ) const; + GH1D *QuantilesY(Double_t prob = 0.5, const char * name = "_qy" ) const; + virtual void Reset(Option_t *option=""); + virtual void SetBinContent(Int_t bin, Double_t content); + virtual void SetBinContent(Int_t binx, Int_t biny, Double_t content) { SetBinContent(GetBin(binx, biny), content); } + virtual void SetBinContent(Int_t binx, Int_t biny, Int_t, Double_t content) { SetBinContent(GetBin(binx, biny), content); } + virtual void SetShowProjectionX(Int_t nbins=1); // *MENU* + virtual void SetShowProjectionY(Int_t nbins=1); // *MENU* + virtual GH1 *ShowBackground(Int_t niter=20, Option_t *option="same"); + virtual Int_t ShowPeaks(Double_t sigma=2, Option_t *option="", Double_t threshold=0.05); // *MENU* + virtual void Smooth(Int_t ntimes=1, Option_t *option=""); // *MENU* + + + + //////////////////////////// + // added functionality // + //////////////////////////// + + public: + GH1D *ProjectionX_BG(const char *name="_bg_px", Int_t ylowbin=0,Int_t yhighbin=-1, + Int_t ylowbgbin=0,Int_t yhighbgbin=-1,double scale=-1,Option_t *opt="") const; // *MENU* + GH1D *ProjectionY_BG(const char *name="_bg_px", Int_t xlowbin=0,Int_t xhighbin=-1, + Int_t xlowbgbin=0,Int_t xhighbgbin=-1,double scale=-1,Option_t *opt="") const; // *MENU* + enum { kForward = 1, kBackward = -1 }; + GH1D *SummaryProjection(GH1 *hist,int axis,int direction,bool show_empty) const; + + GH1 *GetNext(TObject *obj=0,int direction=GH2::kForward) const; + + TList *GetProjections() const { return &fProjections; } + + std::map FitSummary(double low,double high,int axis=1,Option_t *opt="PhotoPeak") const; + + private: + void AddToProjections(GH1 *hist) const { fProjections.Add(hist); hist->SetDirectory(0); } + mutable TList fProjections; + + //friend class GH1; + + ClassDef(GH2,1) //2-Dim histogram base class +}; + + + +#endif diff --git a/include/GH2Base.h b/include/GH2Base.h deleted file mode 100644 index 5b790f72..00000000 --- a/include/GH2Base.h +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef GH2BASE__H -#define GH2BASE__H - -#include -#include -#include - -#include -#include -#include - -class GH1D; - -enum kBackgroundSubtraction { - kNoBackground, - kRegionBackground, - kMatchedLowerMarker, - kSplitTwoMarker, - kTotalFraction -}; - -enum kDirection{ - kXDirection, - kYDirection -}; - -class GH2Base { - -public: - GH2Base() { Init(); } - - virtual ~GH2Base(); - - virtual void GH2Clear(Option_t *opt=""); - - virtual TH2 *GetTH2() = 0; - - GH1D* Projection_Background(int axis=0, - int firstbin = 0, - int lastbin = -1, - int firstbackground_bin = 0, - int lastbackground_bin = -1, - kBackgroundSubtraction mode = kRegionBackground); - - //GH1D* SummaryProject(int binnum); - - GH1D* ProjectionX_Background(int firstbin = 0, - int lastbin = -1, - int firstbackground_bin = 0, - int lastbackground_bin = -1, - kBackgroundSubtraction mode = kRegionBackground); // *MENU* - - GH1D* GH2ProjectionX(const char* name="_px", - int firstbin = 0, - int lastbin = -1, - Option_t* option="",bool KeepEmpty=false); // *MENU* - - GH1D* GH2ProjectionY(const char* name="_py", - int firstbin = 0, - int lastbin = -1, - Option_t* option="",bool KeepEmpty=false); // *MENU* - - GH1D* ProjectionY_Background(int firstbin = 0, - int lastbin = -1, - int firstbackground_bin = 0, - int lastbackground_bin = -1, - kBackgroundSubtraction mode = kRegionBackground); // *MENU* - - GH1D* GetPrevious(const GH1D* curr,bool DrawEmpty=true); - GH1D* GetPrevSummary(const GH1D* curr,bool DrawEmpty=false); - GH1D* GetNext(const GH1D* curr,bool DrawEmpty=true); - GH1D* GetNextSummary(const GH1D* curr,bool DrawEmpty=false); - - TList* GetProjections() { return fProjections; } - TList* GetSummaryProjections() { return fSummaryProjections; } - - void SetSummary(bool is_summary = true) { fIsSummary = is_summary; } - bool GetSummary() const { return fIsSummary; } - - void SetSummaryDirection(kDirection dir) { fSummaryDirection = dir; } - kDirection GetSummaryDirection() const { return fSummaryDirection; } - - - class iterator { - public: - iterator(GH2Base* mat, bool at_end = false) - : mat(mat), first(mat->GetNext(NULL)), curr(at_end ? NULL : first) { } - - GH1D& operator*() const { - return *curr; - } - GH1D* operator->() const { - return curr; - } - - // prefix increment - iterator& operator++() { - curr = mat->GetNext(curr); - if(curr==first) { curr = 0; } - return *this; - } - - // postfix increment - iterator operator++(int) { - iterator current = *this; - ++(*this); - return current; - } - - bool operator==(const iterator& b) const { - return (mat==b.mat && - first==b.first && - curr==b.curr); - } - bool operator!=(const iterator& b) const { - return !(*this == b); - } - - private: - GH2Base* mat; - GH1D* first; - GH1D* curr; - }; - - iterator begin() { return iterator(this, false); } - iterator end() { return iterator(this, true); } - - -private: - void Init(); - TList* fProjections; - - TList* fSummaryProjections; //! - bool fIsSummary; - kDirection fSummaryDirection; - - ClassDef(GH2Base,1); -}; - -#endif diff --git a/include/GH2D.h b/include/GH2D.h index 52359f27..d83f5f7e 100644 --- a/include/GH2D.h +++ b/include/GH2D.h @@ -1,27 +1,26 @@ #ifndef GH2D__H #define GH2D__H -#include -#include +//#include +//#include -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include -#include -#include +//#include +//class GH1D; -class GH1D; -class TClass; -class TMethodCall; +#include -class GH2D : public TH2D , public GH2Base { +class GH2D : public GH2, public TArrayI { public: - GH2D() { } - GH2D(const TObject&); + GH2D(); + GH2D(const GH2D&); + GH2D(const TH1 &h1d); GH2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins,Int_t nbinsy, const Double_t *ybins); GH2D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins,Int_t nbinsy, const Float_t *ybins); GH2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins, @@ -32,41 +31,32 @@ class GH2D : public TH2D , public GH2Base { Int_t nbinsy, Double_t ylow, Double_t yup); ~GH2D(); - virtual void Draw(Option_t *opt=""); - //virtual void Draw(TCutG*); - TH1 *DrawCopy(Option_t *opt="") const; - TH1 *DrawNormalized(Option_t *opt="",Double_t norm=1) const; + virtual void AddBinContent(int bin); + virtual void AddBinContent(int bin,double w); - virtual void Clear(Option_t *opt=""); - virtual void Print(Option_t *opt="") const; - virtual void Copy(TObject&) const; - virtual TObject *Clone(const char *newname="") const; - - GH1D* ProjectionX(const char* name="_px", - int firstbin = 0, - int lastbin = -1, - Option_t* option=""); // *MENU* + virtual void Copy(TObject &obj) const; + + GH2D &operator=(const GH2D &h1); + + virtual void Reset(Option_t *opt=""); + virtual void SetBinsLength(int n=-1); - GH1D* ProjectionY(const char* name="_py", - int firstbin = 0, - int lastbin = -1, - Option_t* option=""); // *MENU* - virtual TH2 *GetTH2() { return this; } + //Int_t Write(const char *name="",Int_t option=0,Int_t bufsize=0) const; - void SetFillMethod(const char *classnamex,const char *methodnamex,const char* paramx="", - const char *classnamey="",const char *methodnamey="",const char* paraym=""); +protected: + virtual double RetrieveBinContent(int bin) const { return double (fArray[bin]); } + virtual void UpdateBinContent(int bin,double content) { fArray[bin] = float(content); } - Int_t Fill(const TObject* objx,const TObject *objy=NULL); + ClassDef(GH2D,3) +}; -private: - - TClass *fXFillClass; //! - TClass *fYFillClass; //! - TMethodCall *fXFillMethod; //! - TMethodCall *fYFillMethod; //! +GH2D operator*(float c1,const GH2D &h1); +inline GH2D operator*(const GH2D &h1,float c1) { return operator*(c1,h1); } +GH2D operator*(const GH2D &h1,const GH2D &h2); +GH2D operator/(const GH2D &h1,const GH2D &h2); +GH2D operator+(const GH2D &h1,const GH2D &h2); +GH2D operator-(const GH2D &h1,const GH2D &h2); - ClassDef(GH2D,1) -}; #endif diff --git a/include/GH2I.h b/include/GH2I.h index 393d7cf9..48648a61 100644 --- a/include/GH2I.h +++ b/include/GH2I.h @@ -1,24 +1,26 @@ #ifndef GH2I__H #define GH2I__H -#include -#include +//#include +//#include -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include -#include +//#include +//class GH1D; -class GH1D; +#include -class GH2I : public TH2I , public GH2Base { +class GH2I : public GH2, public TArrayI { public: - GH2I() { } - GH2I(const TObject&); + GH2I(); + GH2I(const GH2I&); + GH2I(const TH1 &h1d); GH2I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins,Int_t nbinsy, const Double_t *ybins); GH2I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins,Int_t nbinsy, const Float_t *ybins); GH2I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins, @@ -29,29 +31,29 @@ class GH2I : public TH2I , public GH2Base { Int_t nbinsy, Double_t ylow, Double_t yup); ~GH2I(); - virtual void Draw(Option_t *opt=""); - TH1 *DrawCopy(Option_t *opt="") const; - TH1 *DrawNormalized(Option_t *opt="",Double_t norm=1) const; + virtual void AddBinContent(int bin); + virtual void AddBinContent(int bin,double w); - virtual void Clear(Option_t *opt=""); - virtual void Print(Option_t *opt="") const; - virtual void Copy(TObject&) const; - virtual TObject *Clone(const char *newname="") const; + virtual void Copy(TObject &obj) const; + + GH2I &operator=(const GH2I &h1); + + virtual void Reset(Option_t *opt=""); + virtual void SetBinsLength(int n=-1); - GH1D* ProjectionX(const char* name="_px", - int firstbin = 0, - int lastbin = -1, - Option_t* option=""); // *MENU* +protected: + virtual double RetrieveBinContent(int bin) const { return double (fArray[bin]); } + virtual void UpdateBinContent(int bin,double content) { fArray[bin] = float(content); } - GH1D* ProjectionY(const char* name="_py", - int firstbin = 0, - int lastbin = -1, - Option_t* option=""); // *MENU* + ClassDef(GH2I,3) +}; - virtual TH2 *GetTH2() { return this; } +GH2I operator*(float c1,const GH2I &h1); +inline GH2I operator*(const GH2I &h1,float c1) { return operator*(c1,h1); } +GH2I operator*(const GH2I &h1,const GH2I &h2); +GH2I operator/(const GH2I &h1,const GH2I &h2); +GH2I operator+(const GH2I &h1,const GH2I &h2); +GH2I operator-(const GH2I &h1,const GH2I &h2); -private: - ClassDef(GH2I,2) -}; #endif diff --git a/include/GHistPopup.h b/include/GHistPopup.h new file mode 100644 index 00000000..7085b107 --- /dev/null +++ b/include/GHistPopup.h @@ -0,0 +1,33 @@ +#ifndef _GHISTPOPUP_H_ +#define _GHISTPOPUP_H_ + +#include +#include + +#include + +class GH2; + +class GHistPopup : public GPopup { + public: + GHistPopup(GH2 *parent,int w=500,int h=200); + + virtual ~GHistPopup() { } + + void PrintSelected() const; + + void SetFrames(); + + private: + TGListView *listv; + TGLVContainer *listc; + + void AddEntry(TList*); + void AddEntry(const char*); + + + ClassDef(GHistPopup,0) +}; + + +#endif diff --git a/include/GPeak.h b/include/GPeak.h index bf41de4a..20ef3598 100644 --- a/include/GPeak.h +++ b/include/GPeak.h @@ -66,6 +66,8 @@ class GPeak : public TF1 { double fChi2; double fNdf; + void DetachBackground(); + Bool_t IsInitialized() const { return init_flag; } void SetInitialized(Bool_t flag = true) {init_flag = flag;} bool init_flag; diff --git a/include/GPopup.h b/include/GPopup.h index 60bf9db1..0fee7b6c 100644 --- a/include/GPopup.h +++ b/include/GPopup.h @@ -20,6 +20,11 @@ class GPopup : public TGTransientFrame { virtual void Print(Option_t *opt="") const; + virtual void SetFrames() = 0; + + protected: + void Init(); + ClassDef(GPopup,0) }; diff --git a/include/GRootCommands.h b/include/GRootCommands.h index 44704280..de249306 100644 --- a/include/GRootCommands.h +++ b/include/GRootCommands.h @@ -13,9 +13,12 @@ class GMarker; class TF1; class GPeak; class GGaus; +class GDoubleGaus; #include "TDirectory.h" +#define ISPID 32 + extern TChain *gChain; int LabelPeaks(TH1*,double,double,Option_t *opt=""); @@ -25,25 +28,27 @@ bool RemovePeaks(TH1**,unsigned int); GPeak *PhotoPeakFit(TH1*,double,double,Option_t *opt=""); GPeak *PhotoPeakFitNormBG(TH1*,double,double,Option_t *opt=""); GGaus *GausFit(TH1*,double,double,Option_t *opt=""); -TF1 *DoubleGausFit(TH1*,double,double,double,double,Option_t *opt=""); +GDoubleGaus *DoubleGausFit(TH1*,double,double,double,double,Option_t *opt=""); + + std::string MergeStrings(const std::vector& strings, char split='\n'); -bool GetProjectionX(GH2D *hist,double low, double high, double bg_low=0,double bg_high=0); -bool GetProjectionX(GH2D *hist,GH2D *hist2, - double low, double high,double bg_low=-1,double bg_high=-1, - bool overlay = false, - double back_low=-1,double back_high=-1,double back_bg_low=-1, - double back_bg_high=-1, - bool back_overlay=false); - -bool GetProjectionY(GH2D *hist,double low, double high, double bg_low=0,double bg_high=0); -bool GetProjectionY(GH2D *hist,GH2D *hist2, - double low, double high,double bg_low=-1,double bg_high=-1, - bool overlay = false, - double back_low=-1,double back_high=-1,double back_bg_low=-1, - double back_bg_high=-1, - bool back_overlay=false); +//bool GetProjectionX(GH2D *hist,double low, double high, double bg_low=0,double bg_high=0); +//bool GetProjectionX(GH2D *hist,GH2D *hist2, +// double low, double high,double bg_low=-1,double bg_high=-1, +// bool overlay = false, +// double back_low=-1,double back_high=-1,double back_bg_low=-1, +// double back_bg_high=-1, +// bool back_overlay=false); + +//bool GetProjectionY(GH2D *hist,double low, double high, double bg_low=0,double bg_high=0); +//bool GetProjectionY(GH2D *hist,GH2D *hist2, +// double low, double high,double bg_low=-1,double bg_high=-1, +// bool overlay = false, +// double back_low=-1,double back_high=-1,double back_bg_low=-1, +// double back_bg_high=-1, +// bool back_overlay=false); //bool PeakFit(TH1*,Double_t,Double_t,Option_t *opt=""); @@ -62,9 +67,14 @@ TF1 *GrabFit(int i=0); //return the ith fit from the current canvas. void StartGUI(); bool GUIIsRunning(); +class DummyGuiCaller { +public: + void CallUpdate(); //*SIGNAL* +}; + //enum EAxis {kXAxis = 1,kYAxis = 2,kXYaxis = 3,kZaxis = 4,kXZaxis = 5,kYZAxis = 6,kXYZAxis=7}; enum EAxis {kXAxis = 1,kYAxis = 2}; -TH2 *AddOffset(TH2 *mat,double offset,EAxis axis=kXAxis); +//TH2 *AddOffset(TH2 *mat,double offset,EAxis axis=kXAxis); #endif diff --git a/include/GRootFunctions.h b/include/GRootFunctions.h index d63f2741..802e51f3 100644 --- a/include/GRootFunctions.h +++ b/include/GRootFunctions.h @@ -16,20 +16,49 @@ namespace GRootFunctions { Double_t PhotoPeakBG(Double_t *dim, Double_t *par); Double_t PhotoPeakBGExcludeRegion(Double_t *dim,Double_t *par); Double_t Gaus(Double_t *dim, Double_t *par); + Double_t DoubleGaus(Double_t *dim, Double_t *par); Double_t SkewedGaus(Double_t *dim, Double_t *par); Double_t Efficiency(Double_t *dim, Double_t *par); + + Double_t GausExpo(Double_t *dim,Double_t *par); Double_t LanGaus(Double_t *dim,Double_t *par); Double_t LanGausHighRes(Double_t *dim,Double_t *par); Double_t GammaEff(Double_t *dim,Double_t *par); + Double_t AlignedAD(Double_t *x,Double_t *par); + Double_t AlignedAD_Norm(Double_t *x,Double_t *par); + Double_t AlignedADPol_Norm(Double_t *x,Double_t *par); - Double_t ComptonFormula(Double_t *x,Double_t *par); + Double_t ComptonEnergy(Double_t *x,Double_t *par); + Double_t ComptonAngle(Double_t *x,Double_t *par); + Double_t ComptonRatio(Double_t *x,Double_t *par); Double_t AnalyzingPower(Double_t *x,Double_t *par); + Double_t Polarization(Double_t *x,Double_t *par); + Double_t PolarizationAsymmetry(Double_t *x,Double_t *par); + Double_t KN_unpol(Double_t *x,Double_t *par); + Double_t KN_unpol_norm(Double_t *x,Double_t *par); + Double_t KN_pol(Double_t *x,Double_t *par); + + Double_t W_pol(Double_t *x, Double_t *par); + Double_t W_pol_dirk(Double_t *x, Double_t *par); + Double_t W_pol_dirk2(Double_t *x, Double_t *par); + Double_t W_pol_norm(Double_t *x, Double_t *par); + Double_t W_pol2(Double_t *x, Double_t *par); + Double_t W_pol3(Double_t *x, Double_t *par); + Double_t W_pol4(Double_t *x, Double_t *par); + Double_t W_pol5(Double_t *x, Double_t *par); + Double_t W_pol6(Double_t *x, Double_t *par); + Double_t W_pol7(Double_t *x, Double_t *par); + + Double_t W_pol_test(Double_t *x, Double_t *par); + Double_t W_pol_diff(Double_t *x, Double_t *par); + + Double_t Q_pol(Double_t *x, Double_t *par); } diff --git a/include/TBank29.h b/include/TBank88.h similarity index 70% rename from include/TBank29.h rename to include/TBank88.h index f5691734..5b4a2e18 100644 --- a/include/TBank29.h +++ b/include/TBank88.h @@ -1,5 +1,5 @@ -#ifndef TBANK29_H -#define TBANK29_H +#ifndef TBANK88_H +#define TBANK88_H #include #include @@ -9,11 +9,11 @@ #include "TDetector.h" #include "TMode3.h" -class TBank29 : public TDetector { +class TBank88 : public TDetector { public: - TBank29(); - ~TBank29(); + TBank88(); + ~TBank88(); virtual void Copy(TObject& obj) const; virtual void Clear(Option_t *opt = ""); @@ -28,13 +28,17 @@ class TBank29 : public TDetector { Long_t GetTimestamp() { return Timestamp(); } //if(Size()>0) return ((TMode3Hit&)GetHit(0)).GetTimestamp(); else return -1; } + + double GetCharge() const { return channels.at(0).Charge(); } ///this prob shouldn't be zero.... + const TMode3Hit &GetHit(int i) const { return channels.at(i); } + size_t Size() const { return channels.size(); } private: virtual int BuildHits(std::vector& raw_data); std::vector channels; - ClassDef(TBank29,1); + ClassDef(TBank88,1); }; diff --git a/include/TCaesar.h b/include/TCaesar.h index ce2f590f..537d3958 100644 --- a/include/TCaesar.h +++ b/include/TCaesar.h @@ -49,7 +49,7 @@ class TCaesar : public TDetector { void SetULM(int ulm) { fUlm = ulm; } - unsigned int Size() const { return caesar_hits.size(); } + size_t Size() const { return caesar_hits.size(); } int AddbackSize() { BuildAddback(); return addback_hits.size(); } //Corrects TCaesar time (gain matched) by subtracting out the diff --git a/include/TCalibrator.h b/include/TCalibrator.h index 5cf2de69..6c78abdf 100644 --- a/include/TCalibrator.h +++ b/include/TCalibrator.h @@ -24,18 +24,21 @@ class TCalibrator : public TNamed { virtual void Draw(Option_t *option=""); UInt_t Size() const { return fPeaks.size(); } + bool Check() const; + int GetFitOrder() const { return fit_order; } void SetFitOrder(int order) { fit_order = order; } TGraph& MakeCalibrationGraph(bool zerozero=false); // double min_figure_of_merit = 0.001); TGraphErrors &MakeEffGraph(double secondsi=3600.,double bq=100000.,Option_t *opt="draw"); + bool SaveEffGraph(std::string datafile="",std::string fitfile=""); std::vector Calibrate(double min_figure_of_merit = 0.001); int AddData(TH1* source_data, std::string source, - double sigma=2.0,double threshold=0.05,double error=0.001); + double sigma=2.0,double threshold=0.05,bool rm_bg=false,double error=0.001); int AddData(TH1* source_data, TNucleus* source, - double sigma=2.0,double threshold=0.05,double error=0.001); + double sigma=2.0,double threshold=0.05,bool rm_bg=false,double error=0.001); void UpdateTChannel(TChannel* channel); @@ -48,17 +51,22 @@ class TCalibrator : public TNamed { double energy; double area; double intensity; + double reso; std::string nucleus; }; - void AddPeak(double cent,double eng,std::string nuc,double a=0.0,double inten=0.0); + void AddPeak(double cent,double eng,std::string nuc,double a=0.0,double inten=0.0,double reso=0); Peak GetPeak(UInt_t i) const { return fPeaks.at(i); } - + int GetNPeaks() const { return fPeaks.size();} + TH1 *ApplyCalibration(TH1 *source,int bins=8000,double range=4000,Option_t *opt="") const; + TGraph *FitGraph() { return &fit_graph; } TGraph *EffGraph() { return &eff_graph; } TF1 *LinFit() { return linfit; } TF1 *EffFit() { return efffit; } - + + double GetChi2(Option_t *opt="") const; + std::string PrintEfficency(const char *filenamei=""); #ifndef __CINT__ diff --git a/include/TChannel.h b/include/TChannel.h index 44b8c046..d1dbd910 100644 --- a/include/TChannel.h +++ b/include/TChannel.h @@ -8,6 +8,7 @@ #include #include +#include class TChannel : public TNamed { public: @@ -47,6 +48,7 @@ class TChannel : public TNamed { const char* GetCollectedCharge() const { return collected_charge.c_str(); } double GetPedestal() const { return pedestal; } + TVector3 GetChannelPosition() const { return fPosition; } void SetAddress(unsigned int temp) { address = temp; } void SetName(const char *temp) { @@ -87,7 +89,6 @@ class TChannel : public TNamed { public: static int ParseInputData(std::string &input,Option_t *opt=""); static int WriteToBuffer(Option_t *opt=""); - static void trim(std::string *, const std::string &trimChars=" \f\n\r\t\v"); static std::vector ParseListOfDoubles(std::istream& ss); static double Calibrate(int value, const std::vector& coeff); @@ -109,6 +110,13 @@ class TChannel : public TNamed { std::string collected_charge; int segment; + void SetChannelX(double x) { fPosition.SetX(x); } + void SetChannelY(double y) { fPosition.SetY(y); } + void SetChannelZ(double z) { fPosition.SetZ(z); } + + + TVector3 fPosition; + // For backwards compatibility, unpack the name // into the system/array_position/arraysubposition/collectedcharge/segment. void UnpackMnemonic(std::string name); @@ -133,7 +141,9 @@ class TChannel : public TNamed { static std::map fChannelMap; static TChannel *fDefaultChannel; - ClassDef(TChannel,2); + + + ClassDef(TChannel,3); }; #endif diff --git a/include/TCluster.h b/include/TCluster.h new file mode 100644 index 00000000..dcc03dbd --- /dev/null +++ b/include/TCluster.h @@ -0,0 +1,220 @@ +#ifndef TCLUSTER_H +#define TCLUSTER_H + +#include "TGretinaHit.h" + +#include "GRootFunctions.h" + +#define CLUSTER_ANGLE 0.383972 +//22 degrees in rad. +#define CLUSTER_BUILD_TIME 50 +//500 ns - coarse timing between it actions points to build the cluster.... guesstamatied by Jing. pcb. + + + +// GRETINA is currently a collection of xtals - each crystals contains: +// - a "good" core chare / energy +// - a LED trigger based on the core charge +// - t0 time, best event start time as determined by Decomp +// - a number of Segment preamps containing: +// - Calibrated segment charge +// - Energy assigned to the interaction by Decomp +// - X,Y,Z locally assigned by Decomp +// - a error code supplied by Decomp +// +// +// If we want to treat GRETINA as an individual array, there are a few things +// we need to do. We are going to treat the list of individual detectors +// as long list of interactions points. To get to this state, there are a few +// data mapping we need to do as well as decisions that need to be made. First +// an interaction will be defined as: +// - a xtal preamp-id +// - a seg preamp-id +// - energy ( decomp assigned energy/decomp summed energy for the xtal) * Core -Energy +// - time core-led time - t0. +// - X Y Z in laboratory coordinates +// +// some decisions need to be made to get the data in this format. The two biggest +// i can think of at the moment are: +// - what Decomp error codes do we accept (some are worse than others) +// - what do we do when Decomp decides a signal segment has 2+ interaction points. +// - currently, i plan to collapse the interactions. The energy will be the +// summed assigned value. The XYZ will be the weighted average (weights will +// be assigned of the recorded Decomp assignemt). +// +// +// This list of interactions then needs to be organized. First step of organization tends +// to be clustering. Here, we essentially group interactions that fall together within a +// 22 deg cone. This truncated list of interaction points are called a TCluster here. To +// first order, this clusters replace a traditional addback hit - with the sum of all energies +// of each interaction within the cluster the total assigned energy of an individual gamma-ray. +// Hence a number of gamma-rays interacting in the array would coorispond to a number of clusters +// in the array, +// +// Once points are grouped - the next logical step is to track, ie. order the interaction points. +// We will comeback to this point in the future. +// +// +// + + +/* +class TInteractionPoint { + public: + TInteractionPoint() { } + TInteractionPoint(const TInteractionPoint &IP); + TInteractionPoint(int seg,float eng,float frac,TVector3 lpos) : + fSegNum(seg),fEng(eng),fDecompEng(frac),fLPosition(lpos) { } + virtual ~TInteractionPoint() { } + virtual void Copy(const TInteractionPoint&); + void Add(TInteractionPoint&); + virtual int GetSegNum() const { return fSegNum; } + virtual float GetPreampE() const { return fEng; } + virtual float GetDecompE() const { return fDecompEng; } + virtual float GetAssignE() const { return fAssignedEng; } + virtual int GetOrder() const { return fOrder; } + virtual TVector3 GetPosition(int xtal) const; // { return TGretina::CrystalToGlobal(xtal, + TVector3 GetLocalPosition() const { return fLPosition; } + void SetOrder(int o) { fOrder=o; } + void SetAssignE(float e) { fAssignedEng = e; } + void Print(Option_t *opt="") const; + void SetSegNum(int seg) { fSegNum = seg; } + int Wedge() const { return ((GetSegNum()-1)%6); } + private: + int fSegNum; + float fEng; // energy as recorded by preamp. energy in mode2 format + float fDecompEng; // energy as assigned by decomp. fraction in mode2 format + float fAssignedEng; // percent eng assigned by decomp scaled to the core. not in mode2 format + int fOrder; // interaction order + //TVector3 fPosition; // in global coordinates + TVector3 fLPosition; // in local coordinates. + ClassDef(TInteractionPoint,1) +}; +*/ + +class TClusterPoint : public TInteractionPoint { + public: + TClusterPoint(); + TClusterPoint(TGretinaHit &hit, TInteractionPoint &ip); + virtual ~TClusterPoint(); + + TVector3 GetPosition() const { return TInteractionPoint::GetPosition(fXtalId); } + + double GetEnergy() const { return TInteractionPoint::GetAssignE(); } + + long GetTimestamp() const { return fTimestamp; } + double GetTime() const { return ((double)fTimestamp) - fT0; } + double GetT0() const { return fT0; } + int GetPad() const { return fPad; } + int GetXtal() const { return fXtalId; } + + int GetWedge() const { return GetSegNum()%6; } //returns 0-5 + int GetLayer() const { return GetSegNum()/6; } + + //TVector3 GetPosition() const { return GetPosition(GetXtal()); } + double GetPhi() const { + double phi = GetPosition().Phi(); + if(phi<0) { + return TMath::TwoPi()+phi; + } else { + return phi; + } + } + double GetTheta() const { return GetPosition().Theta(); } + double GetPhiDeg() const { return GetPhi()*TMath::RadToDeg(); } + double GetThetaDeg() const { return GetTheta()*TMath::RadToDeg(); } + + void Print(Option_t *opt="") const; + void Clear(Option_t *opt=""); + void Combine(const TClusterPoint &other); + bool operator==(const TClusterPoint &rhs) const { + return ((GetXtal()==rhs.GetXtal()) && (GetSegNum()==rhs.GetSegNum())); } + bool operator<(const TClusterPoint &rhs) const { + return (GetEnergy()>rhs.GetEnergy()); } + + private: + int fXtalId; + int fXtalAddress; + long fTimestamp; + float fT0; + int fPad; + ClassDef(TClusterPoint,1); +}; + + +class TCluster { + public: + TCluster(); + virtual ~TCluster(); + + void Clear(Option_t *opt=""); + void Print(Option_t *opt="") const; + int Size() const { return fClusterPoints.size(); } + TClusterPoint Get(int i) const { return fClusterPoints.at(i); } + TClusterPoint GetPoint(int i) const { return fClusterPoints.at(i); } + TVector3 GetCenterOfMass() const { return fCenterOfMass; } + TVector3 GetPosition() const { return fClusterPoints.front().GetPosition(); } + double GetEnergy() const { return fEnergySum; } + double GetTime() const { return fClusterPoints.front().GetTime(); } + int GetXtal(int i=0) const { return fClusterPoints.at(i).GetXtal(); } + int GetWedge(int i=0) const { return fClusterPoints.at(i).GetWedge(); } + //int UniqueXtals() const; //determine the number of xtals in the cluster + int UniqueXtals() const { return fXtals.size(); } + //determine the number of xtals in the cluster + + void Add(TClusterPoint &cp) { // inserts an Cluster Point into the Cluster, book keeps + if(Size()==0) { + fCenterOfMass = cp.GetPosition(); + } else { + double esum = fEnergySum + cp.GetEnergy(); + double x = (fCenterOfMass.X()*fEnergySum + cp.GetPosition().X()*cp.GetEnergy())/esum; + double y = (fCenterOfMass.Y()*fEnergySum + cp.GetPosition().Y()*cp.GetEnergy())/esum; + double z = (fCenterOfMass.Z()*fEnergySum + cp.GetPosition().Z()*cp.GetEnergy())/esum; + fCenterOfMass.SetXYZ(x,y,z); + } + fXtals.insert(cp.GetXtal()); + fEnergySum+=cp.GetEnergy(); + fClusterPoints.push_back(TClusterPoint(cp)); + std::sort(fClusterPoints.begin(),fClusterPoints.end()); + } + + void CompressInteractions(); // combines int_pt with same xtal && same seg + + + static void CompressInteractions(std::vector *pts); + static void WedgeInteractions(std::vector *pts); + //static void XtalInteractions(std::vector *pts); + //std::vector GetClusters() const { return fClusterPoints; } + + void Fit(); + + double GetFOM() const { return fFOM; } + void SetFOM(double fom) { fFOM=fom; } + + double GetTheta() const { return fTheta; } + void SetTheta(double theta) { fTheta=theta; } + + double GetKN() const { return fKN; } + void SetKN(double kn) { fKN=kn; } + + private: + double fEnergySum; + double fFOM; + double fKN; + double fTheta; //for now, just to plot Klein-Nishina formula DH + + TVector3 fCenterOfMass; + std::vector fClusterPoints; + std::set fXtals; + //std::set fXtals; + + ClassDef(TCluster,3) +}; + + + + + + +#endif + diff --git a/include/TDetector.h b/include/TDetector.h index 09d32e70..221e4c31 100644 --- a/include/TDetector.h +++ b/include/TDetector.h @@ -2,11 +2,14 @@ #define _TDETECTOR_H_ #include +#include #include "TNamed.h" +#include "TBuffer.h" #include "TDetectorHit.h" + #ifndef __CINT__ class TRawEvent; #else @@ -29,7 +32,10 @@ class TDetector : public TNamed { virtual void InsertHit(const TDetectorHit&) = 0; virtual TDetectorHit& GetHit(int i) = 0; - virtual unsigned int Size() const { return fSize; } + //virtual size_t Size() const { return (size_t)fSize; } + virtual size_t Size() const = 0; //{ return (size_t)fSize; } + //virtual unsigned long Size() const = 0; //{ return (size_t)fSize; } + //virtual unsigned int Size() const = 0; //{ return (size_t)fSize; } Long_t Timestamp() const { return fTimestamp; } diff --git a/include/TDetectorEnv.h b/include/TDetectorEnv.h index c48c6b51..3d6f25a5 100644 --- a/include/TDetectorEnv.h +++ b/include/TDetectorEnv.h @@ -13,14 +13,15 @@ class TDetectorEnv : public TNamed { static bool Caesar() { return Get().source_ids[kDetectorSystems::CAESAR].size(); } static bool Gretina() { return Get().source_ids[kDetectorSystems::GRETINA].size(); } - static bool Bank29() { return Get().source_ids[kDetectorSystems::BANK29].size(); } + static bool Bank88() { return Get().source_ids[kDetectorSystems::BANK88].size(); } static bool Mode3() { return Get().source_ids[kDetectorSystems::MODE3].size(); } static bool Janus() { return Get().source_ids[kDetectorSystems::JANUS].size(); } static bool Phoswall() { return Get().source_ids[kDetectorSystems::PHOSWALL].size(); } static bool S800() { return Get().source_ids[kDetectorSystems::S800].size(); } static bool S800Scaler() { return Get().source_ids[kDetectorSystems::S800SCALER].size(); } static bool Sega() { return Get().source_ids[kDetectorSystems::SEGA].size(); } - static bool FastScint() { return Get().source_ids[kDetectorSystems::FASTSCINT].size(); } + static bool FastScint() { return Get().source_ids[kDetectorSystems::FASTSCINT].size(); } + static bool Lenda() { return Get().source_ids[kDetectorSystems::LENDA].size(); } static const std::vector& CaesarIDs() { return Get().source_ids[kDetectorSystems::CAESAR]; } static const std::vector& SegaIDs() { return Get().source_ids[kDetectorSystems::SEGA]; } @@ -30,8 +31,9 @@ class TDetectorEnv : public TNamed { static const std::vector& JANUSIDs() { return Get().source_ids[kDetectorSystems::JANUS]; } static const std::vector& GretinaIDs() { return Get().source_ids[kDetectorSystems::GRETINA]; } static const std::vector& Mode3IDs() { return Get().source_ids[kDetectorSystems::MODE3]; } - static const std::vector& Bank29IDs() { return Get().source_ids[kDetectorSystems::BANK29]; } - static const std::vector& FastScintIDs() { return Get().source_ids[kDetectorSystems::FASTSCINT]; } + static const std::vector& Bank88IDs() { return Get().source_ids[kDetectorSystems::BANK88]; } + static const std::vector& FastScintIDs() { return Get().source_ids[kDetectorSystems::FASTSCINT]; } + static const std::vector& LendaIDs() { return Get().source_ids[kDetectorSystems::LENDA]; } kDetectorSystems DetermineSystem(int source_id) const; kDetectorSystems DetermineSystem(TRawEvent& event) const; diff --git a/include/TDetectorHit.h b/include/TDetectorHit.h index e358bd6d..c8bfcd5e 100644 --- a/include/TDetectorHit.h +++ b/include/TDetectorHit.h @@ -11,6 +11,7 @@ class TDetectorHit : public TObject { virtual ~TDetectorHit(); virtual const char* GetName() const; + virtual int GetNumber() const; virtual Int_t Compare(const TObject *obj) const; //needed for root containers virtual bool IsSortable() const { return true; } @@ -20,7 +21,8 @@ class TDetectorHit : public TObject { virtual void Print(Option_t *opt = "" ) const; Int_t Address() const { return fAddress; } - virtual Int_t Charge() const; + virtual Int_t Charge() const; + virtual float RawCharge() const { return fCharge; } Int_t Time() const { return fTime; } long Timestamp() const { return fTimestamp; } @@ -38,10 +40,10 @@ class TDetectorHit : public TObject { static const TVector3 BeamUnitVec; //! protected: - Int_t fAddress; + Int_t fAddress; Float_t fCharge; - Int_t fTime; - long fTimestamp; + Int_t fTime; + Long_t fTimestamp; unsigned char fFlags; @@ -57,6 +59,8 @@ class TDetectorHit : public TObject { }; ClassDef(TDetectorHit,4) + //ClassDef(TDetectorHit,0) + }; #endif diff --git a/include/TF1Sum.h b/include/TF1Sum.h new file mode 100644 index 00000000..7ee8fdc7 --- /dev/null +++ b/include/TF1Sum.h @@ -0,0 +1,51 @@ +#include +#include + +#include + +class TF1Sum : public TNamed { + + + public: + TF1Sum():TNamed("TF1Sum","TF1Sum"),fFit(0),npars(0) { } + TF1Sum(const TF1Sum& other) + : TNamed(other), fFit(0), npars(other.npars), xlow(other.xlow), xhigh(other.xhigh), + fTF1s(other.fTF1s) { } + + ~TF1Sum() { if(fFit) delete fFit; } + + void AddTF1(TF1 *f); + + void Print(Option_t *opt="") const; + + Double_t EvalPar(const Double_t *x,const Double_t *params=0); + + double operator()(double *x,double *p) { return EvalPar(x,p); } + + void SetRange(double l,double h) { xlow =l; xhigh=h; } + int GetNpar() const { return npars; } + + operator TF1*() { return fFit;} + + TF1 *GetFunc() { return fFit; } + + virtual void Draw(Option_t *opt="all"); + + + private: + TF1 *fFit; + int npars; + double xlow; + double xhigh; + + std::vector fParam; + std::vector fParErr; + std::vector fParMax; + std::vector fParMin; + std::vector fParName; + + std::vector fTF1s; + + ClassDef(TF1Sum,0); +}; + diff --git a/include/TFSU.h b/include/TFSU.h new file mode 100644 index 00000000..b64c83b7 --- /dev/null +++ b/include/TFSU.h @@ -0,0 +1,44 @@ + +#ifndef __TFSU_H__ +#define __TFSU_H__ + + +#include +#include + +class TFSU: public TDetector { + public: + TFSU(); + ~TFSU(); + + + void Clear(Option_t *opt=""); + void Print(Option_t *opt="") const; + void Copy(TObject& obj) const; + + TFSUHit &GetFSUHit(int i) { return fFSUHits.at(i); } + size_t Size() const { return fFSUHits.size(); } + + virtual void InsertHit(const TDetectorHit &hit) { fFSUHits.emplace_back((TFSUHit&)hit); fSize++; } + virtual TDetectorHit& GetHit(int i) { return fFSUHits.at(i); } + + TFSUHit GetDeltaE() const { return fDeltaE; } + TFSUHit GetE() const { return fEnergy; } + + bool GoodParticle() const { if(fDeltaE.Charge()<1 || fEnergy.Charge()<1) return false; return true; } + + private: + int BuildHits(std::vector& raw_data); + std::vector fFSUHits; + + TFSUHit fDeltaE; + TFSUHit fEnergy; + + + ClassDef(TFSU,2) +}; + + +#endif + + diff --git a/include/TFSUHit.h b/include/TFSUHit.h new file mode 100644 index 00000000..bbd0c7b2 --- /dev/null +++ b/include/TFSUHit.h @@ -0,0 +1,31 @@ +#ifndef __TFSUHIT_H__ +#define __TFSUHIT_H__ + +#include +#include + +class TFSUHit : public TDetectorHit { + public: + TFSUHit(); + ~TFSUHit(); + + void Clear(Option_t *opt=""); + void Print(Option_t *opt="") const; + + Int_t Crate() const {return ((fAddress&0x00000f00)>>8); } + Int_t Slot() const {return ((fAddress&0x000000f0)>>4); } + Int_t Channel() const {return ((fAddress&0x0000000f)); } + + Int_t Id() const {return (Slot()*16+Channel()); } + + TVector3 GetPosition() const; + + double GetDoppler(const TVector3 *recoil_vec=0) const; + + double GetDoppler(double beta) const; + + ClassDef(TFSUHit,1) +}; + +#endif + diff --git a/include/TFastScint.h b/include/TFastScint.h index fa94998e..17311688 100644 --- a/include/TFastScint.h +++ b/include/TFastScint.h @@ -19,10 +19,10 @@ class TFastScint : public TDetector { virtual void Clear(Option_t* opt = ""); virtual void InsertHit(const TDetectorHit&); - virtual TFastScintHit GetLaBrHit(int i) const; + virtual const TFastScintHit& GetLaBrHit(int i) const; virtual TDetectorHit& GetHit(int i); TFastScintHit* FindHit(int); - virtual unsigned int Size() const; + virtual size_t Size() const { return fs_hits.size(); } virtual int GoodSize() const; int GetDetNumberIn_fs_hits(Int_t det); @@ -41,14 +41,17 @@ class TFastScint : public TDetector { int GetErrors() {return errors; }; void SetTrigTime(UShort_t time) { trig_time = time; } - int GetTrigTime() { return trig_time; } + int GetTrigTime() const { return trig_time; } + + void SetRefTime(int refTime); + int GetRefTime() const {return fReferenceTime;} static TVector3& GetPosition(int); private: virtual int BuildHits(std::vector& raw_data); - int Build_From(TNSCLEvent &event,bool Zero_Suppress = false); + int Build_From(TRawEvent &event); //TClonesArray* fs_hits; //-> std::vector fs_hits; @@ -57,6 +60,7 @@ class TFastScint : public TDetector { int tdc_TS; int trig_time; + int fReferenceTime; static int errors; //! diff --git a/include/TFastScintHit.h b/include/TFastScintHit.h index b26d4524..51874bff 100644 --- a/include/TFastScintHit.h +++ b/include/TFastScintHit.h @@ -4,37 +4,45 @@ #include "TDetectorHit.h" class TFastScintHit : public TDetectorHit { -public: - TFastScintHit(); - TFastScintHit(const TDetectorHit&); - - virtual void Print(Option_t* opt = "") const; - virtual void Clear(Option_t* opt = ""); - virtual void Copy(TObject& obj) const; - - //void SetCharge(int chg) { fCharge = chg; } - void SetChannel(int chan) { fChannel = chan; } - //void SetTime(int time) { fTime = time; } - //void SetTimestamp(long ts) { fTimestamp = ts; } - //void SetEnergy(); - - //virtual int Charge() const { return fCharge; } - int GetChannel() const { return fChannel; } - //int GetTime() const { return fTime; } - //long GetTimestamp() const { return fTimestamp; } - //float GetEnergy() const { return fEnergy; } - // - TVector3 &GetPosition() const; - - -private: - //long fTimestamp; - int fChannel; - //int fTime; - //int fCharge; - //float fEnergy; - - ClassDef(TFastScintHit,22) + public: + TFastScintHit(); + TFastScintHit(const TDetectorHit&); + + virtual void Print(Option_t* opt = "") const; + virtual void Clear(Option_t* opt = ""); + virtual void Copy(TObject& obj) const; + + int GetChannel() const { return Address() & 0x1f; } + + TVector3 &GetPosition() const; + + void SetTime(unsigned short time) { fTimes.push_back(time); } + virtual int Time() const { + if(fTimes.size()) { + return fTimes[0]; + } else { + return -1; + } + } + + const std::vector& GetAllTimes() const { return fTimes; } + size_t GetNumTimes() const { return fTimes.size(); } + int GetMTime(size_t j) const { + //if(GetNumTimes()rhs.Charge(); } // fAddress fTimes; + + ClassDef(TFastScintHit,24) }; #endif /* _TFASTSCINTDETECTORHIT_H_ */ diff --git a/include/TGRUTOptions.h b/include/TGRUTOptions.h index 6a71f413..909cf9e5 100644 --- a/include/TGRUTOptions.h +++ b/include/TGRUTOptions.h @@ -49,6 +49,7 @@ class TGRUTOptions : public TObject { bool MakeHistos() const { return fMakeHistos; } bool SortMultiple() const { return fSortMultiple; } + bool UseFSU() const { return fFSU; } bool IsOnline() const { return fIsOnline; } @@ -65,6 +66,8 @@ class TGRUTOptions : public TObject { bool LongFileDescription() const { return fLongFileDescription; } + bool SuppressErrors() const { return fSuppressErrors; } + void SetStartGUI(bool flag=true) { fStartGui=flag; } @@ -106,6 +109,9 @@ class TGRUTOptions : public TObject { bool fStartGui; bool fMakeHistos; bool fSortMultiple; + bool fSuppressErrors; + + bool fFSU; bool fTimeSortInput; int fTimeSortDepth; diff --git a/include/TGRUTTypes.h b/include/TGRUTTypes.h index a018448a..697ad376 100644 --- a/include/TGRUTTypes.h +++ b/include/TGRUTTypes.h @@ -13,9 +13,13 @@ enum kDetectorSystems { MODE3 = 2, S800 = 5, S800SCALER = 10, - BANK29 = 8, + BANK88 = 8, GRETINA_SIM= 11, S800_SIM = 9, + LENDA = 21, + + UML = 26, + OBJ = 25, // temporary SEGA = 64, JANUS = 65, @@ -23,6 +27,8 @@ enum kDetectorSystems { CAESAR = 80, + FSU = 99, + PHOSWALL = 17, NSCLSCALERS = 100 diff --git a/include/TGRUTUtilities.h b/include/TGRUTUtilities.h index 2cde6549..11f48f40 100644 --- a/include/TGRUTUtilities.h +++ b/include/TGRUTUtilities.h @@ -29,5 +29,6 @@ std::vector MakeVectorFromFile(const char *fname); std::string ReplaceAll(std::string str, const std::string& from, const std::string& to); +void trim(std::string& line, const std::string & trimChars = " \f\n\r\t\v"); #endif diff --git a/include/TGretSim.h b/include/TGretSim.h index f612850d..ad3fc86a 100644 --- a/include/TGretSim.h +++ b/include/TGretSim.h @@ -19,7 +19,7 @@ class TGretSim : public TDetector { virtual void Copy(TObject& obj) const; virtual void Print(Option_t *opt = "") const; virtual void Clear(Option_t *opt = ""); - virtual UInt_t Size() const { return gretsim_hits.size(); } + virtual size_t Size() const { return gretsim_hits.size(); } virtual void InsertHit(const TDetectorHit& hit); virtual TDetectorHit& GetHit(int i) { return gretsim_hits.at(i); } diff --git a/include/TGretina.h b/include/TGretina.h index f2775aba..ed394d3a 100644 --- a/include/TGretina.h +++ b/include/TGretina.h @@ -5,14 +5,16 @@ #include #endif +#include + #include #include - -#include +#include #include "TDetector.h" #include "TGretinaHit.h" +#include "TCluster.h" class TGretina : public TDetector { @@ -23,54 +25,59 @@ class TGretina : public TDetector { virtual void Copy(TObject& obj) const; virtual void Print(Option_t *opt = "") const; + virtual void PrintInteractions(Option_t *opt = "") const; virtual void Clear(Option_t *opt = ""); - virtual UInt_t Size() const { return gretina_hits.size(); } - virtual Int_t AddbackSize(int EngRange=-1) { BuildAddback(EngRange); return addback_hits.size(); } - void ResetAddback() { addback_hits.clear();} + virtual size_t Size() const { return gretina_hits.size(); } + //virtual UInt_t Size() const { return gretina_hits.size(); } + //virtual Int_t AddbackSize(int EngRange=-1) { BuildAddback(EngRange); return addback_hits.size(); } + //void ResetAddback() { addback_hits.clear();} virtual void InsertHit(const TDetectorHit& hit); virtual TDetectorHit& GetHit(int i) { return gretina_hits.at(i); } //const TGretinaHit& GetGretinaHit(int i) const { return gretina_hits.at(i); } - TGretinaHit GetGretinaHit(int i) const { return gretina_hits.at(i); } - const TGretinaHit& GetAddbackHit(int i) const { return addback_hits.at(i); } + TGretinaHit GetGretinaHit(int i) const { return gretina_hits.at(i); } + //const TGretinaHit& GetAddbackHit(int i) const { return addback_hits.at(i); } - void PrintHit(int i){ gretina_hits.at(i).Print(); } + void PrintHit(int i) { gretina_hits.at(i).Print(); } - static TVector3 CrystalToGlobal(int cryId, - Float_t localX=0,Float_t localY=0,Float_t localZ=0); + static TVector3 CrystalToGlobal(int cryId,Float_t localX=0,Float_t localY=0,Float_t localZ=0); static TVector3 GetSegmentPosition(int cryid,int segment); //return the position of the segemnt in the lab system static TVector3 GetCrystalPosition(int cryid); //return the position of the crysal in the lab system - static void DrawDopplerGamma(Double_t Beta=0.1,Option_t *gate="",Option_t *opt="",Long_t entries=kMaxLong,TChain *chain=0); - static void DrawDopplerBeta(Option_t *gate="",Option_t *opt="",Long_t entries=kMaxLong,TChain *chain=0); - static void DrawEnVsTheta(Double_t Beta=0.1,Option_t *gate="",Option_t *opt="",Long_t entries=kMaxLong,TChain *chain=0); - static void DrawCoreSummary(Option_t *gate="",Option_t *opt="",Long_t entries=kMaxLong,TChain *chain=0); + //static double ComptonAngle(double eoriginal,double escatterer); + //static double ComptonEnergy(double eoriginal,double theta); + void CleanHits(); -#ifndef __CINT__ - static void SetAddbackCondition(std::function condition) { - fAddbackCondition = condition; - } - static std::function GetAddbackCondition() { - return fAddbackCondition; - } -#endif const std::vector &GetAllHits() const { return gretina_hits; } + void Sort() { } void SortHits(); + //int BuildAddback(int EngRange=-1) const; + + int BuildClusters() const; + void PrintClusters(Option_t *opt="") const; + int ClusterSize() const { return clusters.size(); } + TCluster &GetCluster(int i) const { return clusters.at(i); } + + + double GetTotalEnergy() const; + //void CompressClusters() { for(unsigned int x=0;x fAddbackCondition; -#endif +//#ifndef __CINT__ +// static std::function fAddbackCondition; +//#endif virtual int BuildHits(std::vector& raw_data); std::vector gretina_hits; - mutable std::vector addback_hits; //! + //mutable std::vector addback_hits; //! + mutable std::vector clusters; //! static Float_t crmat[32][4][4][4]; static Float_t m_segpos[2][36][3]; @@ -78,12 +85,9 @@ class TGretina : public TDetector { static void SetSegmentCRMAT(); static bool fCRMATSet; - - ClassDef(TGretina,3); + ClassDef(TGretina,4); }; - - #endif diff --git a/include/TGretinaHit.h b/include/TGretinaHit.h index a61ba44b..1f53230c 100644 --- a/include/TGretinaHit.h +++ b/include/TGretinaHit.h @@ -7,16 +7,63 @@ #include #include - #include -//#include "TGEBEvent.h" #include "TDetectorHit.h" #define MAXHPGESEGMENTS 36 class TSmartBuffer; -class TS800; + + +class TInteractionPoint { + public: + TInteractionPoint() { } + TInteractionPoint(const TInteractionPoint &IP); + TInteractionPoint(int seg,float eng,float frac,TVector3 lpos) : + fSegNum(seg),fEng(eng),fDecompEng(frac),fLPosition(lpos) { } + virtual ~TInteractionPoint() { } + + virtual void Copy(const TInteractionPoint&); + void Add(TInteractionPoint&); + + virtual int GetSegNum() const { return fSegNum; } + virtual float GetPreampE() const { return fEng; } + virtual float GetDecompE() const { return fDecompEng; } + virtual float GetAssignE() const { return fAssignedEng; } + virtual int GetOrder() const { return fOrder; } + virtual TVector3 GetPosition(int xtal) const; // { return TGretina::CrystalToGlobal(xtal, + TVector3 GetLocalPosition() const { return fLPosition; } + void SetOrder(int o) { fOrder=o; } + void SetAssignE(float e) { fAssignedEng = e; } + + void Print(Option_t *opt="") const; + void Clear(Option_t *opt=""); + + void SetSegNum(int seg) { fSegNum = seg; } + + int Wedge() const { return ((GetSegNum()-1)%6); } + + bool operator == (const TInteractionPoint &rhs) const { + return (GetDecompE() == rhs.GetDecompE()); + } + bool operator < (const TInteractionPoint &rhs) const{ + return (GetDecompE() > rhs.GetDecompE()); + } + + private: + int fSegNum; + float fEng; // energy as recorded by preamp. energy in mode2 format + float fDecompEng; // energy as assigned by decomp. fraction in mode2 format + float fAssignedEng; // percent eng assigned by decomp scaled to the core. not in mode2 format + int fOrder; // interaction order + //TVector3 fPosition; // in global coordinates + TVector3 fLPosition; // in local coordinates. + ClassDef(TInteractionPoint,1) + +}; + + class TGretinaHit : public TDetectorHit { @@ -29,39 +76,35 @@ class TGretinaHit : public TDetectorHit { void BuildFrom(TSmartBuffer& raw); - Long_t GetTimestamp() const { return fTimeStamp; } - Double_t GetTime() const { return (double)fTimeStamp - (double)fWalkCorrection; } + Double_t GetTime() const { return (double)Timestamp() - (double)fT0; } + Double_t GetT0() const { return fT0; } Int_t GetAddress() const { return fAddress; } + Int_t GetXtalId() const { return fCrystalId; } Int_t GetCrystalId() const { return fCrystalId; } - Int_t GetHoleNumber() const { return fCrystalId/4-1; } + Int_t GetHoleNumber() const { return fCrystalId/4; } Int_t GetCrystalNumber() const { return fCrystalId%4; } Float_t GetCoreEnergy() const { return fCoreEnergy; } Int_t GetCoreCharge(int i) const { return fCoreCharge[i]; } Float_t GetCoreEnergy(int i) const; // { return fCoreCharge[i]; } - virtual Int_t Charge() const { return fCoreCharge[3]; } + virtual Int_t Charge() const { return fCoreCharge[3]; } + virtual Double_t GetEnergy() const { return fCoreEnergy; } - const char *GetName() const; + const char *GetName() const { return TDetectorHit::GetName(); } + int GetNumber() const { return TDetectorHit::GetNumber(); } Int_t GetPad() const { return fPad; } void Print(Option_t *opt="") const; void Clear(Option_t *opt=""); - Int_t Compare(const TObject *obj) const { - TGretinaHit *other = (TGretinaHit*)obj; - if(this->GetCoreEnergy()>other->GetCoreEnergy()) - return -1; - else if(this->GetCoreEnergy()GetCoreEnergy()) - return 1; //sort largest to smallest. - return 0; - } + Int_t Compare(const TObject *obj) const; - Int_t Size() const { return fNumberOfInteractions; }//fSegmentNumber.size(); } + Int_t Size() const { return fInteractions.size(); }//fSegmentNumber.size(); } double GetX() const { return GetPosition().X(); } double GetY() const { return GetPosition().Y(); } double GetZ() const { return GetPosition().Z(); } - double GetPhi() { + double GetPhi() const { double phi = GetPosition().Phi(); if(phi<0) { return TMath::TwoPi()+phi; @@ -74,136 +117,69 @@ class TGretinaHit : public TDetectorHit { double GetThetaDeg() { return GetTheta()*TMath::RadToDeg(); } bool HasInteractions() { return fNumberOfInteractions; } - //TGretinaHit& operator+=(const TGretinaHit&); - //TGretinaHit& operator+(const TGretinaHit&); bool operator<(const TGretinaHit &rhs) const { return fCoreEnergy > rhs.fCoreEnergy; } - - - double GetDopplerSim(double beta, double en,const TVector3 *gvec=0, const TVector3 *vec=0){ - if(Size()<1) - return 0.0; - if(vec==0) { - vec = &BeamUnitVec; - } - TVector3 vechold = GetPosition(); - if(gvec==0){ - gvec = &vechold; - } - - double tmp = 0.0; - double gamma = 1/(sqrt(1-pow(beta,2))); - tmp = en*gamma *(1 - beta*TMath::Cos(gvec->Angle(*vec))); - return tmp; - } - double GetDoppler(double beta,const TVector3 *vec=0) { - if(Size()<1) - return 0.0; - if(vec==0) { - vec = &BeamUnitVec; - } - double tmp = 0.0; - double gamma = 1/(sqrt(1-pow(beta,2))); - tmp = fCoreEnergy*gamma *(1 - beta*TMath::Cos(GetPosition().Angle(*vec))); - return tmp; - } - double GetDoppler_2(double beta,const TVector3 *vec=0) { - if(Size()<1) - return 0.0; - if(vec==0) { - vec = &BeamUnitVec; - } - double tmp = 0.0; - double gamma = 1/(sqrt(1-pow(beta,2))); - tmp = fCoreEnergy*gamma *(1 - beta*TMath::Cos(GetPosition_2().Angle(*vec))); - return tmp; - } - double GetDoppler(const TS800 *s800,bool doDTAcorr=false,int EngRange=-1); - double GetDoppler(int EngRange, double beta,const TVector3 *vec=0) { - if(Size()<1) - return 0.0; - if(vec==0) { - vec = &BeamUnitVec; - } - double tmp = 0.0; - double gamma = 1/(sqrt(1-pow(beta,2))); - tmp = GetCoreEnergy(EngRange)*gamma *(1 - beta*TMath::Cos(GetPosition().Angle(*vec))); - return tmp; - } - - - + double GetDoppler(double beta,const TVector3 *vec=0); double GetDoppler_dB(double beta,const TVector3 *vec=0, double Dta=0); + TVector3 GetPosition() const; // const { return GetIntPosition(0); } - Int_t GetFirstIntPoint() const { return fFirstInteraction; } - Int_t GetSecondIntPoint() const { return fSecondInteraction; } - Int_t NumberOfInteractions() const { return fNumberOfInteractions; } - Int_t GetSegmentId(const int &i) const { return fSegmentNumber.at(i); } - Float_t GetSegmentEng(const int &i) const { return fInteractionEnergy.at(i); } - TVector3 GetInteractionPosition(int i) const; //{ return fGlobalInteractionPosition[i]; } - TVector3 GetLocalPosition(int i) const; - //TVector3 GetCrystalPosition(int i) const { return TVector3(0,0,1): } - TVector3 GetPosition() const { return GetFirstIntPosition(); } - TVector3 GetPosition_2() const { return GetFirstIntPosition_2(); } - TVector3 GetLastPosition() const; - - TVector3 GetCrystalPosition() const; - TVector3 GetSegmentPosition() const; - - - - TVector3 GetFirstIntPosition() const; - TVector3 GetFirstIntPosition_2() const; - TVector3 GetSecondIntPosition() const; - - void AddToSelf(const TGretinaHit& other); - - //void SetPosition(TVector3 &vec) { fCorePosition = vec; } + int CleanInteractions(); + TInteractionPoint GetInteractionPoint(int i) const { return fInteractions.at(i); } + //Int_t NumberOfInteractions() const { return fNumberOfInteractions; } + Int_t NumberOfInteractions() const { return fInteractions.size(); } + Int_t GetSegmentId(int i) const { return GetInteractionPoint(i).GetSegNum(); } + Float_t GetIntPreampEng(int i) const { return GetInteractionPoint(i).GetPreampE(); } + Float_t GetIntDecomEng(int i) const { return GetInteractionPoint(i).GetDecompE(); } + Float_t GetIntAssignEng(int i) const { return GetInteractionPoint(i).GetAssignE(); } + TVector3 GetIntPosition(int i) const { return GetInteractionPoint(i).GetPosition(GetCrystalId()); } + TVector3 GetLocalIntPosition(int i) const { return GetInteractionPoint(i).GetLocalPosition(); } + TVector3 GetCrystalPosition() const;// { return TGretina::GetCrystalPosition(fCrystalId); } + void SetCoreEnergy(float temp) const { fCoreEnergy = temp; } + double GetIntMag(int i) const { return GetIntPosition(i).Mag(); } + double GetIntTheta(int i) const { return GetIntPosition(i).Theta(); } + double GetIntThetaDeg(int i) const { return GetIntTheta(i)*TMath::RadToDeg(); } + double GetIntPhi(int i) const { + double phi = GetIntPosition(i).Phi(); + if(phi<0) { + return TMath::TwoPi()+phi; + } else { + return phi; + } + } + double GetIntPhiDeg(int i) const { return GetIntPhi(i)*TMath::RadToDeg(); } -//private: - void SortHits(); - Long_t fTimeStamp; - Float_t fWalkCorrection; +private: + //void SortHits(); + void SortInts(); - Int_t fAddress; + Float_t fT0; //WalkCorrection; Int_t fCrystalId; mutable Float_t fCoreEnergy; Int_t fCoreCharge[4]; Int_t fPad; - - Int_t fFirstInteraction; - Int_t fSecondInteraction; - Int_t fNumberOfInteractions; + + std::vector fInteractions; //[fNumberOfInteractions]; - /// The number of the segment containing the interaction. - /** - Note: This is not equal to the segment number as read from the datastream. - This is equal to 36*raw.crystal_id + raw.segnum. ///not anymore pcb. - */ - std::vector fSegmentNumber; //[fNumberOfInteractions] - - /// The position of the interaction point in lab coordinates - /** - Note: this is not equal to the position as read from the datastream. - This has been transformed to lab coordinates. - To get the crystal coordinate, use TGretinaHit::GetCrystalPosition(int i). - */ - std::vector fGlobalInteractionPosition; //[fNumberOfInteractions] - std::vector fLocalInteractionPosition; //[fNumberOfInteractions] - std::vector fInteractionEnergy; //[fNumberOfInteractions] - std::vector fInteractionFraction; //[fNumberOfInteractions] - - ClassDef(TGretinaHit,4) + ClassDef(TGretinaHit,7) }; + + + + + #endif + + + + diff --git a/include/THistogramLoop.h b/include/THistogramLoop.h index 0475d1e4..0c41d21a 100644 --- a/include/THistogramLoop.h +++ b/include/THistogramLoop.h @@ -36,8 +36,8 @@ class THistogramLoop : public StoppableThread { TList* GetObjects(); TList* GetGates(); - size_t GetItemsPopped() { return input_queue->ItemsPopped(); } - size_t GetItemsPushed() { return input_queue->ItemsPushed(); } + size_t GetItemsPopped() { return output_queue->ItemsPopped(); } + size_t GetItemsPushed() { return output_queue->ItemsPushed(); } size_t GetItemsCurrent() { return 0; } size_t GetRate() { return 0; } diff --git a/include/TJanus.h b/include/TJanus.h index 8ba346f7..4ea644c6 100644 --- a/include/TJanus.h +++ b/include/TJanus.h @@ -37,6 +37,8 @@ class TJanus : public TDetector { static double GetBeta(double betamax, double kr_angle_rad, bool energy_loss=false, double collision_pos=0.5); static double SimAngle(); + size_t Size() const { return janus_hits.size(); } + private: virtual int BuildHits(std::vector& raw_data); diff --git a/include/TKinematics.h b/include/TKinematics.h index a6170a7f..d632878a 100644 --- a/include/TKinematics.h +++ b/include/TKinematics.h @@ -43,6 +43,7 @@ class TKinematics : public TNamed { TGraph* Evslab_graph(double thmin, double thmax, double size, int part = 2); + TGraph* Evslab_graph_reverse(double thmin, double thmax, double size, int part=2); double GetCmEnergy(double eBeam); double GetCmEnergy(); diff --git a/include/TLenda.h b/include/TLenda.h new file mode 100644 index 00000000..2b0ce2dc --- /dev/null +++ b/include/TLenda.h @@ -0,0 +1,34 @@ +#ifndef _TLENDA_H_ +#define _TLENDA_H_ + +#include + +#include +#include + +class TLenda : public TDetector { + public: + TLenda() { } + ~TLenda() { } + + void Copy(TObject &obj) const { } //TDetector::Copy(obj); } + + void Clear(Option_t *opt="") { TDetector::Clear(opt); } + TLendaHit &GetLendaHit(int i) { return lenda_hits.at(i); } + + void InsertHit(const TDetectorHit&) { } + TDetectorHit &GetHit(int i) { return lenda_hits.at(i); } + + static TVector3 GetPosition(int i) { return TVector3(0,0,1); } + + size_t Size() const { return lenda_hits.size(); } + + private: + int BuildHits(std::vector& raw_data); + //{ printf("lenda build hits called\n"); fflush(stdout);return 0;} + std::vector lenda_hits; + + ClassDef(TLenda,1); +}; + +#endif diff --git a/include/TLendaHit.h b/include/TLendaHit.h new file mode 100644 index 00000000..8bf0b377 --- /dev/null +++ b/include/TLendaHit.h @@ -0,0 +1,36 @@ +#ifndef _TLENDAHIT_H_ +#define _TLENDAHIT_H_ + +#include +#include + +class TLendaHit : public TDetectorHit { + public: + TLendaHit() { } + ~TLendaHit() { } + + virtual void Copy(TObject& obj) const { TDetectorHit::Copy(obj); } + virtual void Clear(Option_t *opt = "");// { TDetectorHit::Clear(opt); } + virtual void Print(Option_t *opt = "") const { TDetectorHit::Print(opt); } + //virtual void Draw(Option_t* opt = "") { TDetectorHit::Draw(opt); } + + std::vector* GetTrace() { return &fTrace; } + void SetTrace(unsigned int trace_length, const unsigned short* trace); + //void DrawTrace() { } + int Size() { return fTrace.size(); } + + int GetSlot() const { return 0; } + int GetCrate() const { return 0; } + int GetChannel() const { return 0; } + + TVector3 GetPosition() { return TVector3(0,0,1); } + + + + private: + std::vector fTrace; + + ClassDef(TLendaHit,1) +}; + +#endif diff --git a/include/TMode3.h b/include/TMode3.h index a4b554fd..09bff3c9 100644 --- a/include/TMode3.h +++ b/include/TMode3.h @@ -16,15 +16,16 @@ class TMode3 : public TDetector { ~TMode3(); virtual void Copy(TObject& obj) const; - virtual void Print(Option_t *opt = "") const; + virtual void Print(Option_t *opt = "all") const; + virtual void Draw(Option_t *opt = "") const; virtual void Clear(Option_t *opt = ""); - virtual unsigned int Size() const { return mode3_hits.size(); } + virtual size_t Size() const { return mode3_hits.size(); } virtual void InsertHit(const TDetectorHit& hit); virtual TDetectorHit& GetHit(int i) { return mode3_hits.at(i); } - const TMode3Hit& GetMode3Hit(int i) { return mode3_hits.at(i); } + const TMode3Hit& GetMode3Hit(size_t i) const { return mode3_hits.at(i); } void PrintHit(int i){ mode3_hits.at(i).Print(); } diff --git a/include/TMode3Hit.h b/include/TMode3Hit.h index 4607d402..065e773c 100644 --- a/include/TMode3Hit.h +++ b/include/TMode3Hit.h @@ -21,8 +21,8 @@ class TMode3Hit : public TDetectorHit { //virtual void InsertHit(const TDetectorHit& hit) { return; } //virtual TDetectorHit& GetHit(const int &i=0) { return hit; } - //virtual int Size() { return 1; } - double AverageWave(int samples=-1); + virtual size_t Size() const { return waveform.size(); } + double AverageWave(int samples=-1) const; void BuildFrom(TSmartBuffer& buf); @@ -33,6 +33,8 @@ class TMode3Hit : public TDetectorHit { Int_t GetSegmentId() const { return GetVME()*10 + GetChannel(); } Int_t GetAbsSegId() const { return GetCrystal()*40 + GetSegmentId() ; } Int_t GetCrystalId() const { return GetHole()*4 + GetCrystal(); } + + Int_t WaveSize() const { return wavesize; } const std::vector& GetWave() const { return waveform; } Long_t GetLed() const { return led; } @@ -54,8 +56,9 @@ class TMode3Hit : public TDetectorHit { double GetEnergy1() const; double GetEnergy2() const; - void Draw(Option_t *opt=""); + void Draw(Option_t *opt="") const; + bool operator<(const TMode3Hit &rhs) const { return GetSegmentId() < rhs.GetSegmentId(); } private: //virtual int BuildHits(); diff --git a/include/TNSCLScalers.h b/include/TNSCLScalers.h index f8597bab..83d819c3 100644 --- a/include/TNSCLScalers.h +++ b/include/TNSCLScalers.h @@ -16,7 +16,7 @@ class TNSCLScalers : public TDetector { virtual void Print(Option_t *opt="") const; virtual void Clear(Option_t *opt=""); - unsigned int Size() const { return scalers.size(); } + size_t Size() const { return scalers.size(); } int GetScaler(int i) const { return scalers.at(i); } int GetSourceID() const { return source_id; } diff --git a/include/TOBJ.h b/include/TOBJ.h new file mode 100644 index 00000000..99109c96 --- /dev/null +++ b/include/TOBJ.h @@ -0,0 +1,49 @@ +#ifndef _TOBJ_H_ +#define _TOBJ_H_ + +#include + +#include +#include + +#include +#include + +class TOBJ : public TDetector { + public: + TOBJ() { } + ~TOBJ() { } + + void Copy(TObject &obj) const { } //TDetector::Copy(obj); } + + void Clear(Option_t *opt="") { TDetector::Clear(opt); obj_hits.clear(); } + + void InsertHit(const TDetectorHit&) { } + TDetectorHit &GetHit(int i) { return obj_hits.at(i); } + static TVector3 GetPosition(int i) { return TVector3(0,0,1); } + + size_t Size() const { return obj_hits.size(); } + + + TOBJHit GetOBJHit(int i) { return obj_hits[i]; } //.at(i); } + // TOBJHit GetObj() const { return fobj; } + + bool Good() const { return true; } + + + //private: + int BuildHits(std::vector& raw_data); + //{ printf("lenda build hits called\n"); fflush(stdout);return 0;} + + + std::vector obj_hits; +// TOBJHit fobj; + + + //////////////////// + //////////////////// + //////////////////// + ClassDef(TOBJ,4); +}; + +#endif diff --git a/include/TOBJHit.h b/include/TOBJHit.h new file mode 100644 index 00000000..8bcd996a --- /dev/null +++ b/include/TOBJHit.h @@ -0,0 +1,63 @@ +#ifndef _TOBJHIT_H_ +#define _TOBJHIT_H_ + +#include +#include +#include + +class TOBJHit : public TDetectorHit { + public: + TOBJHit() : htrace(nullptr),ttrace(nullptr),etrace(nullptr),pileup(false) { } + ~TOBJHit() { } + + virtual void Copy(TObject& obj) const { TDetectorHit::Copy(obj); } + virtual void Clear(Option_t *opt = "");// { TDetectorHit::Clear(opt); } + virtual void Print(Option_t *opt = "") const { TDetectorHit::Print(opt); } + //virtual void Draw(Option_t* opt = "") { TDetectorHit::Draw(opt); } + + std::vector* GetTrace() { return &fTrace; } + void SetTrace(unsigned int trace_length, const unsigned short* trace); + //void DrawTrace() { } + int Size() { return fTrace.size(); } + + int GetCrate() const { return 0; } + int GetSlot() const { return ((Address()&0x000000f0)>>4); } + int GetChannel() const { return ((GetSlot()-2)*16) + (Address()&0x0000000f); } + + TVector3 GetPosition() { return TVector3(0,0,1); } + + int GetNumber() const { return GetSlot()*16+GetChannel(); } + + void SetExternalTimestamp(long ets) { fExternalTimestamp = ets; } + long GetExternalTimestamp() const { return fExternalTimestamp; } + void DrawTrace(Option_t *option); + void DrawETrace(Option_t *option); + void DrawTTrace(Option_t *option); + void TrigFilter(Double_t tpeak,Double_t tgap); // in unit of ticks + void EnergyFilter(Double_t tpeak,Double_t tgap,Double_t tau); // in unit of ticks + void SetPileup(bool flag){pileup = flag; } + bool GetPileup() const { return pileup;} + void ClearETrace() { fETrace.clear();} + void ClearTTrace() { fTTrace.clear();} + double GetOfflineEnergy() const { return fEnergy;} + void CalOfflineEnergy(double thres = 0); + + + + private: + std::vector fTrace; + std::vector fETrace; + std::vector fTTrace; + GH1D *htrace; //! + GH1D *ttrace; //! + GH1D *etrace; //! + Bool_t pileup; + Double_t fEnergy; + Double_t PeakSample; + + long fExternalTimestamp; + + ClassDef(TOBJHit,1) +}; + +#endif diff --git a/include/TOldSega.h.bak b/include/TOldSega.h.bak new file mode 100644 index 00000000..da875d94 --- /dev/null +++ b/include/TOldSega.h.bak @@ -0,0 +1,56 @@ +#ifndef __TOLDSEGA_H__ +#define __TOLDSEGA_H__ + + +#include + +#include + +#include +#include + +class TOldSega : public TDetector { + public: + TOldSega() { } + TOldSega(const TOldSega &rhs) { rhs.Copy(*this); } + + void Copy(TObject &rhs) const; // { TDetector::Copy(rhs); } + void Print(Option_t *opt="") const; // { TDetector::Print(opt); } + void Clear(Option_t *opt=""); + + void InsertHit(const TDetectorHit &hit) { TOldSegaHit &oshit = (TOldSegaHit&)hit; oshit.Sort(); sega_hits.push_back(oshit); } + TDetectorHit& GetHit(int i) { return sega_hits.at(i); } + TOldSegaHit& GetSegaHit(int i) { return sega_hits.at(i); } + size_t Size() const { return sega_hits.size(); } + + unsigned short GetMasterLive() const { return masterlive; } + unsigned short GetXfpScint() const { return xfpscint; } + unsigned short GetRf() const { return rf; } + + void SetMasterLive(unsigned short tmp) { masterlive = tmp; } + void SetXfpScint(unsigned short tmp) { xfpscint = tmp; } + void SetRf(unsigned short tmp) { rf = tmp; } + + TOldSega& operator=(const TOldSega& rhs) { rhs.Copy(*this); return *this;} + + //static TVector3& GetPosition(int det,int seg) { return fSegaPositions[det]; } + + + private: + int BuildHits(std::vector& raw_data) { return sega_hits.size(); } + + std::vector sega_hits; + + unsigned short masterlive; + unsigned short xfpscint; + unsigned short rf; + + public: + static TVector3 GetGlobalSegmentPosition(int det,int seg); + + ClassDef(TOldSega,2) +}; + + +#endif + diff --git a/include/TOldSegaHit.h.bak b/include/TOldSegaHit.h.bak new file mode 100644 index 00000000..3374a1e6 --- /dev/null +++ b/include/TOldSegaHit.h.bak @@ -0,0 +1,58 @@ +#ifndef __TOLDSEGAHIT_H__ +#define __TOLDSEGAHIT_H__ + + +#include + +#include +#include + +class TOldSegaHit : public TDetectorHit { + + public: + TOldSegaHit() { } + TOldSegaHit(const TOldSegaHit &rhs) { rhs.Copy(*this); } + + void Copy(TObject &rhs) const; // { TDetectorHit::Copy(rhs); } + void Print(Option_t *opt="") const; // { TDetectorHit::Print(opt); } + void Clear(Option_t *opt=""); + + TDetectorHit &GetSegment(int i) { return segments.at(i); } + int Size() const { return segments.size(); } + + void AddSegment(int id, float charge); + + int GetSegId(int i=0) const { if(Size()>i) return (segments.at(i).Address())&0x000000ff; return -1; } + int GetSegChg(int i) const { if(Size()>i) return (segments.at(i).Charge()); return -1; } + float GetSegEng(int i) const { if(Size()>i) return (segments.at(i).GetEnergy()); return -1.0; } + + + int GetDetId() const { return (Address()&0x0000ff00)>>8; } + int GetDetNum() const { if(TChannel::GetChannel(Address())) return TChannel::GetChannel(Address())->GetNumber(); return -1; } + + void Sort() { std::sort(segments.begin(),segments.end()); } + + TVector3 GetPosition() const; + + double GetDoppler(double beta,const TVector3 *vec=0) const { + if(Size()<1) + return 0.0; + if(vec==0) { + vec = &BeamUnitVec; + } + double tmp = 0.0; + double gamma = 1/(sqrt(1-pow(beta,2))); + tmp = GetEnergy()*gamma *(1 - beta*TMath::Cos(GetPosition().Angle(*vec))); + return tmp; + } + + private: + std::vector segments; + + ClassDef(TOldSegaHit,1) +}; + + + +#endif + diff --git a/include/TPhosWall.h b/include/TPhosWall.h index f3e385e9..bc0177ef 100644 --- a/include/TPhosWall.h +++ b/include/TPhosWall.h @@ -7,7 +7,7 @@ #include "TDetector.h" #include "TGEBEvent.h" #include "TPhosWallHit.h" -#include "TNucleus.h" +//#include "TNucleus.h" #define MAXPIXEL 256 @@ -27,7 +27,7 @@ class TPhosWall : public TDetector { virtual void InsertHit(const TDetectorHit& hit); - unsigned int Size() const { return phoswall_hits.size(); } + size_t Size() const { return phoswall_hits.size(); } int Pixel(int i) const { return phoswall_hits.at(i).Pixel(); } int A(int i) const { return phoswall_hits.at(i).A(); } int B(int i) const { return phoswall_hits.at(i).B(); } @@ -40,8 +40,8 @@ class TPhosWall : public TDetector { const TPhosWallHit& GetPhosWallHit(int i) const { return phoswall_hits.at(i); } TDetectorHit& GetHit(int i) { return phoswall_hits.at(i); } - void Draw(Option_t *opt=""); - static void DrawPID(Option_t *gate="",Option_t *opt="BC",Long_t entries=kMaxLong,TChain *chain=0); + //void Draw(Option_t *opt=""); + //static void DrawPID(Option_t *gate="",Option_t *opt="BC",Long_t entries=kMaxLong,TChain *chain=0); TVector3 GetHitPosition() { if(fLargestHit>-1) return GetWallPosition(Pixel(fLargestHit)); else return TVector3(sqrt(-1),sqrt(-1),sqrt(-1)); } diff --git a/include/TRawBanks.h b/include/TRawBanks.h index 0b4cbe18..e2e47982 100644 --- a/include/TRawBanks.h +++ b/include/TRawBanks.h @@ -99,6 +99,29 @@ struct G4S800 { friend std::ostream& operator<<(std::ostream& os, const G4S800 &s800pack); +struct MQDCHeader { + UInt_t datum; + UInt_t signature() const { return (datum&0xc0000000)>>30; } + UInt_t subheader() const { return (datum&0x3f000000)>>24; } + UInt_t moduleid() const { return (datum&0x00ff0000)>>16; } + UInt_t outformat() const { return (datum&0x00008000)>>15; } + UInt_t adcres() const { return (datum&0x00007000)>>12; } + UInt_t size() const { return (datum&0x00000fff)>>0; } +}; + +struct MTDCHeader { + UInt_t datum; + UInt_t signature() const { return (datum&0xc0000000)>>30; } + UInt_t subheader() const { return (datum&0x3f000000)>>24; } + UInt_t moduleid() const { return (datum&0x00ff0000)>>16; } + UInt_t tdcres() const { return (datum&0x0000f000)>>12; } + UInt_t size() const { return (datum&0x00000fff)>>0; } +}; + + + + + // General Mesytec Stuff: struct Mesy_Word{ // This is 2x16 bits = 32 bits. The MQDC talks in 32 bit words. @@ -220,7 +243,7 @@ typedef struct { // Decomposed GRETINA Data Float_t tot_e; Int_t core_e[4]; Long_t timestamp; - Long_t trig_time; + Long_t trig_time; Float_t t0; Float_t cfd; Float_t chisq; diff --git a/include/TRawSource.h b/include/TRawSource.h index 6dde2c73..633de5b7 100644 --- a/include/TRawSource.h +++ b/include/TRawSource.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "TByteSource.h" #include "TGRUTTypes.h" diff --git a/include/TRuntimeObjects.h b/include/TRuntimeObjects.h index e5ecba03..4db081a6 100644 --- a/include/TRuntimeObjects.h +++ b/include/TRuntimeObjects.h @@ -3,6 +3,7 @@ #include #include +#include #include "TCutG.h" #include "TDirectory.h" @@ -10,11 +11,15 @@ #include "TUnpackedEvent.h" -class TH1; -class TH2; +class GH1; +class GH2; class TFile; class TProfile; +class GH1D; +class GH2D; +class TDetector; + /// Object passed to the online histograms. /** For each event, an instance of this type will be passed to the custom histogrammer. @@ -40,6 +45,9 @@ class TRuntimeObjects : public TNamed { T* GetDetector(){ return detectors->GetDetector(); } + TDetector *GetDetector(std::string dname) const { + return detectors->GetDetector(dname); + } TCutG* GetCut(const std::string& name); @@ -50,29 +58,52 @@ class TRuntimeObjects : public TNamed { TList* GetGatesPtr() { return gates; } - TH1* FillHistogram(const char* name, + GH1* FillHistogram(const char* name, int bins, double low, double high, double value, double weight=1); - TH2* FillHistogram(const char* name, + GH2* FillHistogram(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue, double weight=1); + + GH1* FillHistogram(const char* name, + int bins, double low, double high, const char *value, double weight); + GH2* FillHistogram(const char* name, + int Xbins, double Xlow, double Xhigh, const char *Xvalue, + int Ybins, double Ylow, double Yhigh, double Yvalue, + double weight); + + + + GH1D* InitHistogram(const char* name,const char *title,int bins, double low, double high); + GH2D* InitHistogram(const char* name,const char *title,int Xbins, double Xlow, double Xhigh, + int Ybins, double Ylow, double Yhigh); + GH1D* InitHistogram(const char* dir,const char* name,const char *title,int bins, double low, double high); + GH2D* InitHistogram(const char* dir,const char* name,const char *title,int Xbins, double Xlow, double Xhigh, + int Ybins, double Ylow, double Yhigh); + int FillHistogram(const char* name); + int FillHistogram(const char* dir,const char* name); + + + + + TProfile* FillProfileHist(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, double Yvalue); - TH2* FillHistogramSym(const char* name, + GH2* FillHistogramSym(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue); - TH1* FillHistogram(const std::string& name, + GH1* FillHistogram(const std::string& name, int bins, double low, double high, double value, double weight=1){ return FillHistogram(name.c_str(), bins, low, high, value, weight); } - TH2* FillHistogram(const std::string& name, + GH2* FillHistogram(const std::string& name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue, double weight=1) { @@ -88,7 +119,7 @@ class TRuntimeObjects : public TNamed { Xbins, Xlow, Xhigh, Xvalue, Yvalue); } - TH2* FillHistogramSym(const std::string& name, + GH2* FillHistogramSym(const std::string& name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue) { return FillHistogramSym(name.c_str(), @@ -99,10 +130,22 @@ class TRuntimeObjects : public TNamed { TDirectory* FillHistogram(const char* dirname,const char* name, int bins, double low, double high, double value, double weight=1); + TDirectory* FillHistogram(const char* dirname,const char* name, + int bins, double low, double high, const char *value, + double weight); + TDirectory* FillHistogram(const char* dirname,const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue, double weight=1); + + TDirectory* FillHistogram(const char* dirname,const char* name, + int Xbins, double Xlow, double Xhigh, const char* Xvalue, + int Ybins, double Ylow, double Yhigh, double Yvalue, + double weight); + + + TDirectory* FillProfileHist(const char* dirname,const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, double Yvalue); @@ -118,6 +161,100 @@ class TRuntimeObjects : public TNamed { bins, low, high, value, weight); } + + TDirectory* FillHistogram(const std::string& dirname,const std::string& name, + int bins, double low, double high, std::vector values, + double weight=1) { + TDirectory *d = 0; + for(size_t i=0;i values, + double weight=1) { + TDirectory *d = 0; + for(size_t i=0;i values, + double weight=1) { + TDirectory *d = 0; + for(size_t i=0;i values, + double weight=1) { + TDirectory *d = 0; + for(size_t i=0;i values, + double weight=1) { + TDirectory *d = 0; + for(size_t i=0;i values, + double weight=1) { + TDirectory *d = 0; + for(size_t i=0;i& raw_data); @@ -112,6 +160,7 @@ class TS800 : public TDetector { bool HandleIonCPacket(unsigned short*,int); //! bool HandleCRDCPacket(unsigned short*,int); //! bool HandleMTDCPacket(unsigned short*,int); //! + bool HandleOBJPinPacket(unsigned short*,int); //! TScintillator scint[3]; TTrigger trigger; @@ -120,6 +169,7 @@ class TS800 : public TDetector { TIonChamber ion; TCrdc crdc1; TCrdc crdc2; + UShort_t pine; //THodoscope hodo[32]; //TMultiHitTof multi_tof; diff --git a/include/TS800Hit.h b/include/TS800Hit.h index cfe3c0c8..4756d573 100644 --- a/include/TS800Hit.h +++ b/include/TS800Hit.h @@ -176,6 +176,10 @@ class TCrdc : public TDetectorHit { unsigned short anode; unsigned short time; + mutable bool has_cached_dispersive_x; //! + mutable double cached_dispersive_x; //! + + static TF1 *fgaus; @@ -225,13 +229,24 @@ class TIonChamber : public TDetectorHit { int GetChannel(int i) const { if(i>=Size()) return -1; return fChan.at(i); } int GetData(int i) const { if(i>=Size()) return -1; return fData.at(i); } int Size() const { return fChan.size(); } - float GetdE(); - float GetSum(); + float GetdE(TCrdc *); + float GetdE(double crdc_1_x, double crdc_1_y); + float GetSum() const; float GetAve(); - float GetdECorr(TCrdc*); + // float GetdECorr(TCrdc*); int Address(int i) const { return TDetectorHit::Address() + GetChannel(i); } + + float GetCalData(int i) const { + TChannel *c = TChannel::GetChannel(Address(GetChannel(i))); + if(c){ + return c->CalEnergy(GetData(i)); + }else{ + return (float)GetData(i); + } + } + virtual void Copy(TObject&) const; virtual void Print(Option_t *opt="") const; virtual void Clear(Option_t *opt=""); @@ -338,13 +353,11 @@ class TIonChamber : public TS800Channel { TIonChamber() { } TIonChamber(const TIonChamber &ion) { ion.Copy(*this); } TIonChamber(short value):TS800Channel(value) { } - virtual void Clear(Option_t *opt="") { TS800Channel::Clear(opt); } virtual void Print(Option_t *opt="") const { printf("Ion Chamber");TS800Channel::Print(opt);} virtual void Copy(TObject &obj) const { TS800Channel::Copy(obj); } private: ClassDef(TIonChamber,1) - }; */ @@ -369,17 +382,36 @@ class TMTof : public TDetectorHit { int RefSize() const { return fRef.size(); } + //bool Correlate() const; + //bool CorrelateE1Up() const; + //bool CorrelateObj() const; + //bool CorrelateXfp() const; + + double GetCorrelatedXfp() const; //{ return fCorrelatedXFP; } //! + double GetCorrelatedObj() const; //{ return fCorrelatedOBJ; } //! + double GetCorrelatedE1Up() const; //{ return fCorrelatedE1Up; } //! + + //double GetCorrelatedXfpE1() const { return GetCorrelatedXfp()-GetCorrelatedE1Up(); } //! + //double GetCorrelatedObjE1() const { return GetCorrelatedObj()-GetCorrelatedE1Up(); } //! + + double GetCorrelatedXfpE1() const; //! + double GetCorrelatedObjE1() const; //! + double GetCorrelatedRfE1() const; //! - //private: - mutable int fCorrelatedXFP; //! - mutable int fCorrelatedOBJ; //! - mutable int fCorrelatedE1; //! - mutable int fCorrelatedXFP_Ch15; //! - mutable int fCorrelatedOBJ_Ch15; //! - mutable int fCorrelatedE1_Ch15; //! + private: + mutable double fCorrelatedXFP; //! + mutable double fCorrelatedOBJ; //! + mutable double fCorrelatedE1Up; //! + mutable double fCorrelatedRfE1; //! + mutable double fCorrelatedOBJE1; + mutable double fCorrelatedXFPE1; + //mutable int fCorrelatedXFP_Ch15; //! + //mutable int fCorrelatedOBJ_Ch15; //! + //mutable int fCorrelatedE1_Ch15; //! + public: std::vector fE1Up; // Channel 0 std::vector fE1Down; // Channel 1 std::vector fXfp; // Channel 2 diff --git a/include/TS800Scaler.h b/include/TS800Scaler.h index 73db486b..e6c7d160 100644 --- a/include/TS800Scaler.h +++ b/include/TS800Scaler.h @@ -17,7 +17,7 @@ class TS800Scaler : public TDetector { virtual void Print(Option_t *opt) const; virtual void Clear(Option_t *opt); - unsigned int Size() const { return scalers.size(); } + size_t Size() const { return scalers.size(); } int GetScaler(int i) const { return scalers.at(i); } // These functions are needed to satisfy TDetector's requirements. diff --git a/include/TS800Sim.h b/include/TS800Sim.h index 1a379fea..fe870587 100644 --- a/include/TS800Sim.h +++ b/include/TS800Sim.h @@ -19,7 +19,7 @@ class TS800Sim : public TDetector { virtual void Copy(TObject& obj) const; virtual void Print(Option_t *opt = "") const; virtual void Clear(Option_t *opt = ""); - virtual UInt_t Size() const { return s800sim_hits.size(); } + virtual size_t Size() const { return s800sim_hits.size(); } virtual void InsertHit(const TDetectorHit& hit); virtual TDetectorHit& GetHit(int i) { return s800sim_hits.at(i); } diff --git a/include/TSega.h b/include/TSega.h index 0c932bcf..e9d5c602 100644 --- a/include/TSega.h +++ b/include/TSega.h @@ -19,6 +19,8 @@ class TSega : public TDetector { virtual void InsertHit(const TDetectorHit&); virtual TDetectorHit& GetHit(int i); + void SortHitsByTimestamp(); + virtual void SetRunStart(unsigned int unix_time); static TVector3 GetSegmentPosition(int detnum, int segnum); @@ -28,6 +30,8 @@ class TSega : public TDetector { std::vector::iterator begin() { return sega_hits.begin(); } std::vector::iterator end() { return sega_hits.end(); } + size_t Size() const { return sega_hits.size(); } + private: virtual int BuildHits(std::vector& raw_data); static void LoadDetectorPositions(); diff --git a/include/TSegaHit.h b/include/TSegaHit.h index e0f127ae..418b5048 100644 --- a/include/TSegaHit.h +++ b/include/TSegaHit.h @@ -46,11 +46,12 @@ class TSegaHit : public TDetectorHit { void DrawTrace(int segnum); - TVector3 GetPosition(bool apply_array_offset = true) const; + TVector3 GetPosition(bool apply_array_offset = true, + TVector3 array_offset = TVector3(sqrt(-1.0),sqrt(-1.0),sqrt(-1.0))) const; double GetDoppler(double beta, const TVector3& particle_vec = TVector3(0,0,1), - const TVector3& sega_offset = TVector3(0,0,0)) const; + const TVector3& sega_offset = TVector3(sqrt(-1.0),sqrt(-1.0),sqrt(-1.0))) const; double GetTraceHeight() const; double GetTraceHeightDoppler(double beta,const TVector3& vec = TVector3(0,0,1)) const; diff --git a/include/TSmartBuffer.h b/include/TSmartBuffer.h index 86964cd9..7d318e5c 100644 --- a/include/TSmartBuffer.h +++ b/include/TSmartBuffer.h @@ -64,8 +64,6 @@ class TSmartBuffer : public TObject { #endif #endif - - /// Clears the object. /** The object will be left in the same state diff --git a/include/TTransition.h b/include/TTransition.h index 0bd218a3..72262efa 100644 --- a/include/TTransition.h +++ b/include/TTransition.h @@ -6,6 +6,7 @@ */ #include +#include #include "TClass.h" #include "TObject.h" diff --git a/include/TUML.h b/include/TUML.h new file mode 100644 index 00000000..9fa4b2a2 --- /dev/null +++ b/include/TUML.h @@ -0,0 +1,136 @@ +#ifndef _TUML_H_ +#define _TUML_H_ + +#include + +#include +#include + +#include +#include + +class TUML : public TDetector { + public: + TUML() { } + ~TUML() { } + + void Copy(TObject &obj) const { } //TDetector::Copy(obj); } + + void Clear(Option_t *opt="") { TDetector::Clear(opt); uml_hits.clear(); } + + void InsertHit(const TDetectorHit&) { } + TDetectorHit &GetHit(int i) { return uml_hits.at(i); } + static TVector3 GetPosition(int i) { return TVector3(0,0,1); } + + size_t Size() const { return uml_hits.size(); } + size_t SizeSssd() const { return fSssd.size(); } + + + TUMLHit GetUMLHit(int i) { return uml_hits[i]; } //.at(i); } + TUMLHit GetPin1() const { return fPin1; } + TUMLHit GetPin2() const { return fPin2; } + TUMLHit GetImplant() const { return fImplant; } + TUMLHit GetVeto() const { return fVeto; } + + TUMLHit GetXfp1() const { return fXfp1; } + TUMLHit GetXfp2() const { return fXfp2; } + + // double GetTac1() const { return fTac1 * 3.2671; } + // double GetTac2() const { return fTac2 * 3.3555 * 2; } + // double GetTac3() const { return fTac3 * 3.6493 * 2; } + // double GetTac4() const { return fTac4 * 3.3999 * 2; } + // double GetTac5() const { return fTac5 * 3.5; } + // coefficients added by e15130.cal, below returns tof value + double GetTac1() const { return fTac1 > 0 ? fTac1*GValue::Value("TOF1_slope") / 1000. +GValue::Value("TOF1_offset") : 0; } + double GetTac2() const { return fTac2 > 0 ? fTac2*GValue::Value("TOF2_slope") / 1000. +GValue::Value("TOF2_offset") : 0; } + double GetTac3() const { return fTac3; } + double GetTac4() const { return fTac4; } + double GetTac5() const { return fTac5; } + +// double GetTof() const { return -GetTac1() / 1000. + GValue::Value("Tof_Offset"); }// this should be ns + double GetTof() const { return 1/2.*(GetTac1()+GetTac2()); }// this should be ns +// double GetTof() const { return GetTac1(); }// this should be ns + + + bool Good() const { return true; } + + //double TKE() const; + double GetSssdEnergy() const; + double GetXPosition() const; + + //double GetBhro() const; + //double AoQ() const; + //double Beta() const; + + double Araw() const { return AoQ * Z; } + double Am2Z() const { return Araw() - 2*Z; } + double Am3Z() const { return Araw() - 3*Z; } + + double A() const { return AoQ * Q; } + double Am2Q() const { return A() - 2*Q; } + double Am3Q() const { return A() - 3*Q; } + + double ZmQ() const { return Z - Q; } + + double GetTKE() const { return TKE; } + double GetBeta() const { return beta; } + double GetGamma() const { return gamma; } + double GetdBrho() const { return dbrho; } + double GetBrho() const { return brho; } + double GetAoQ() const { return AoQ; } + double GetZ() const { return Z; } + double GetQ() const { return Q; } + + void CalParameters(); + void ReCalBrho(); + + + //private: + int BuildHits(std::vector& raw_data); + //{ printf("lenda build hits called\n"); fflush(stdout);return 0;} + + double fTac1; // pin1-xfp + double fTac2; // pin2-xfp + double fTac3; // sssd-xfp + double fTac4; // implant-xfp + double fTac5; // pin1-xfp + + TUMLHit fPin1; + TUMLHit fPin2; + TUMLHit fImplant; // pin3 + TUMLHit fVeto; + + TUMLHit fXfp1; + TUMLHit fXfp2; + + std::vector fSssd; + std::vector uml_hits; + + /////////////////////// + //// Oleg ToF Things // + /////////////////////// + + double CalTKE() const; + double Beta_to_Gamma(double beta) const; + double SetAoQ(); + double SetZ() const; + + double TKE; //! + double beta; //! + double gamma; //! + double dbrho; //! + double brho; //! + double AoQ; //! + double Z; //! + double Q; //! + + double gamma_energy; + double gamma_time; + + //////////////////// + //////////////////// + //////////////////// + ClassDef(TUML,4); +}; + +#endif diff --git a/include/TUMLHit.h b/include/TUMLHit.h new file mode 100644 index 00000000..e4a8d5b3 --- /dev/null +++ b/include/TUMLHit.h @@ -0,0 +1,42 @@ +#ifndef _TUMLHIT_H_ +#define _TUMLHIT_H_ + +#include +#include + +class TUMLHit : public TDetectorHit { + public: + TUMLHit() { } + ~TUMLHit() { } + + virtual void Copy(TObject& obj) const { TDetectorHit::Copy(obj); } + virtual void Clear(Option_t *opt = "");// { TDetectorHit::Clear(opt); } + virtual void Print(Option_t *opt = "") const { TDetectorHit::Print(opt); } + //virtual void Draw(Option_t* opt = "") { TDetectorHit::Draw(opt); } + + std::vector* GetTrace() { return &fTrace; } + void SetTrace(unsigned int trace_length, const unsigned short* trace); + //void DrawTrace() { } + int Size() { return fTrace.size(); } + + int GetCrate() const { return 0; } + int GetSlot() const { return ((Address()&0x000000f0)>>4); } + int GetChannel() const { return ((GetSlot()-2)*16) + (Address()&0x0000000f); } + + TVector3 GetPosition() { return TVector3(0,0,1); } + + int GetNumber() const { return GetSlot()*16+GetChannel(); } + + void SetExternalTimestamp(long ets) { fExternalTimestamp = ets; } + long GetExternalTimestamp() const { return fExternalTimestamp; } + + + private: + std::vector fTrace; + + long fExternalTimestamp; + + ClassDef(TUMLHit,1) +}; + +#endif diff --git a/include/TUnpackedEvent.h b/include/TUnpackedEvent.h index f7a9bddf..cf996bf2 100644 --- a/include/TUnpackedEvent.h +++ b/include/TUnpackedEvent.h @@ -18,6 +18,7 @@ class TUnpackedEvent { template T* GetDetector(bool make_if_not_found = false); + TDetector* GetDetector(std::string) const; std::vector& GetDetectors() { return detectors; } void AddDetector(TDetector* det) { detectors.push_back(det); } @@ -58,4 +59,7 @@ T* TUnpackedEvent::GetDetector(bool make_if_not_found) { } #endif + + + #endif /* _TUNPACKEDEVENT_H_ */ diff --git a/include/TVariable.h b/include/TVariable.h new file mode 100644 index 00000000..fe7eca46 --- /dev/null +++ b/include/TVariable.h @@ -0,0 +1,98 @@ +#ifndef _TVARIABLE_H_ +#define _TVARIABLE_H_ + +#include +#include +#include +#include + +#include + +class TVariable { + public: + TVariable():fValue(sqrt(-1)),fName("") { } + TVariable(double v,const char *s) : fValue(v),fName(s) { } + TVariable(const TVariable &v) { v.Copy(*this); } + virtual ~TVariable() { } + + virtual void Copy(TVariable&) const; + virtual void Print(Option_t *opt="") const; + void Clear(Option_t *opt); + + const char *GetName() const { return fName.c_str(); } + void Set(double tmp) { fValue = tmp; } + + bool IsZero() const {if((fValue!=fValue)||GetAsInt()==0) return true;return false;} + + double GetAsDouble() const { return fValue; } + int GetAsInt() const { return static_cast(fValue); } + UInt_t GetAsUInt() const { return static_cast(fValue); } + short GetAsShort() const { return static_cast(fValue); } + UShort_t GetAsUShort() const { return static_cast(fValue); } + long GetAsLong() const { return static_cast(fValue); } + ULong_t GetAsULong() const { return static_cast(fValue); } + + TVariable& operator=(const TVariable &v) { v.Copy(*this); return *this;} + TVariable& operator+=(const TVariable &rhs) {fValue+=rhs.fValue;return *this;} + TVariable& operator-=(const TVariable &rhs) {fValue-=rhs.fValue;return *this;} + TVariable& operator*=(const TVariable &rhs) {fValue*=rhs.fValue;return *this;} + TVariable& operator/=(const TVariable &rhs) {fValue/=rhs.fValue;return *this;} + bool operator!() const { return IsZero(); } + double operator()() const { return GetAsDouble(); } + void operator++() {fValue=fValue+1.0;} + void operator++(int d) {fValue+=d;} + void operator--() {fValue=fValue-1.0;} + void operator--(int d) {fValue-=d;} + + //TODO: move these to the cxx, use std::tie + bool operator==(const TVariable &v) { return GetAsInt()==v.GetAsInt(); } + bool operator!=(const TVariable &v) { return GetAsInt()!=v.GetAsInt(); } + bool operator<=(const TVariable &v) { return GetAsInt()<=v.GetAsInt(); } + bool operator>=(const TVariable &v) { return GetAsInt()>=v.GetAsInt(); } + bool operator<(const TVariable &v) { return GetAsInt()(const TVariable &v) { return GetAsInt()>v.GetAsInt(); } + + + friend TVariable operator+(const TVariable& lhs,const TVariable& rhs); + friend double operator+(const TVariable& lhs,double); + friend TVariable operator-(const TVariable& lhs,const TVariable& rhs); + friend double operator-(const TVariable& lhs,double); + friend TVariable operator*(const TVariable& lhs,const TVariable& rhs); + friend double operator*(const TVariable& lhs,double); + friend TVariable operator/(const TVariable& lhs,const TVariable& rhs); + friend double operator/(const TVariable& lhs,double); + friend TVariable operator%(const TVariable& lhs,const TVariable& rhs); + friend int operator%(const TVariable& lhs,int); + + friend std::ostream& operator<<(std::ostream&,const TVariable&); + + + private: + double fValue; + std::string fName; + + static std::map fVarMap; + + private: + double Value(std::string); + + + ClassDef(TVariable,1) + +}; + +TVariable operator+(const TVariable&,const TVariable&); +double operator+(const TVariable&,double); +TVariable operator-(const TVariable&,const TVariable&); +double operator-(const TVariable&,double); +TVariable operator*(const TVariable&,const TVariable&); +double operator*(const TVariable&,double); +TVariable operator/(const TVariable&,const TVariable&); +double operator/(const TVariable&,double); +TVariable operator%(const TVariable&,const TVariable&); +int operator%(const TVariable&,int); + +std::ostream& operator<<(std::ostream&,const TVariable&); + +#endif + diff --git a/include/ThreadsafeQueue.h b/include/ThreadsafeQueue.h index 9862f685..680c327c 100644 --- a/include/ThreadsafeQueue.h +++ b/include/ThreadsafeQueue.h @@ -55,7 +55,7 @@ class ThreadsafeQueue { #ifndef __CINT__ template ThreadsafeQueue::ThreadsafeQueue() - : max_queue_size(200000), + : max_queue_size(20000), items_in_queue(0), items_pushed(0), items_popped(0), is_finished(false) { } diff --git a/libraries/GROOT/GCanvas.cxx b/libraries/GROOT/GCanvas.cxx index d6f5e400..9ec35613 100644 --- a/libraries/GROOT/GCanvas.cxx +++ b/libraries/GROOT/GCanvas.cxx @@ -28,7 +28,7 @@ #include //#include -#include +#include //#include "GROOTGuiFactory.h" #include "GRootCommands.h" @@ -45,6 +45,7 @@ #include +#include "TBuffer.h" #include "TGRUTint.h" #ifndef kArrowKeyPress @@ -61,17 +62,17 @@ enum MyArrowPress{ ClassImp(GMarker) -void GMarker::Copy(TObject &object) const { - TObject::Copy(object); - ((GMarker&)object).x = x; - ((GMarker&)object).y = y; - ((GMarker&)object).localx = localx; - ((GMarker&)object).localy = localy; - ((GMarker&)object).linex = 0; - ((GMarker&)object).liney = 0; - ((GMarker&)object).binx = binx; - ((GMarker&)object).biny = biny; -} + void GMarker::Copy(TObject &object) const { + TObject::Copy(object); + ((GMarker&)object).x = x; + ((GMarker&)object).y = y; + ((GMarker&)object).localx = localx; + ((GMarker&)object).localy = localy; + ((GMarker&)object).linex = 0; + ((GMarker&)object).liney = 0; + ((GMarker&)object).binx = binx; + ((GMarker&)object).biny = biny; + } void GMarker::Print(Option_t *opt) const { @@ -168,6 +169,16 @@ GCanvas::GCanvas(const char* name, const char* title, Int_t wtopx, Int_t wtopy, } +GCanvas::GCanvas(Int_t cols,Int_t rows,Bool_t build) + :TCanvas(build) { + GCanvasInit(); + this->Divide(cols,rows); + this->cd(1); + } + + + + GCanvas::~GCanvas() { //TCanvas::~TCanvas(); } @@ -182,7 +193,7 @@ void GCanvas::GCanvasInit() { fMarkerMode = true; control_key = false; fGuiEnabled = false; - fBackgroundMode = kNoBackground; + //fBackgroundMode = kNoBackground; //if(gVirtualX->InheritsFrom("TGX11")) { // printf("\tusing x11-like graphical interface.\n"); //} @@ -316,7 +327,7 @@ bool GCanvas::SetBackgroundMarkers() { marker->SetColor(kBlue); } - fBackgroundMode = kRegionBackground; + //fBackgroundMode = kRegionBackground; return true; } @@ -325,33 +336,33 @@ bool GCanvas::CycleBackgroundSubtraction() { if(fBackgroundMarkers.size() < 2){ return false; } - - Color_t color = 0; - - switch(fBackgroundMode){ - case kNoBackground: - fBackgroundMode = kRegionBackground; - Prompt(); - color = kBlue; - break; - case kRegionBackground: - fBackgroundMode = kTotalFraction; - color = kGreen; - break; - case kTotalFraction: - fBackgroundMode = kMatchedLowerMarker; - color = kOrange; - break; - case kMatchedLowerMarker: - fBackgroundMode = kSplitTwoMarker; - color = kMagenta; - break; - case kSplitTwoMarker: - fBackgroundMode = kNoBackground; - color = 0; - break; - }; - + // + Color_t color = kBlue; + // + // switch(fBackgroundMode){ + // case kNoBackground: + // fBackgroundMode = kRegionBackground; + // Prompt(); + // color = kBlue; + // break; + // case kRegionBackground: + // fBackgroundMode = kTotalFraction; + // color = kGreen; + // break; + // case kTotalFraction: + // fBackgroundMode = kMatchedLowerMarker; + // color = kOrange; + // break; + // case kMatchedLowerMarker: + // fBackgroundMode = kSplitTwoMarker; + // color = kMagenta; + // break; + // case kSplitTwoMarker: + // fBackgroundMode = kNoBackground; + // color = 0; + // break; + // }; + // for(auto marker : fBackgroundMarkers){ marker->SetColor(color); } @@ -535,8 +546,10 @@ bool GCanvas::HandleMouseShiftPress(Int_t event,Int_t x,Int_t y) { TH1 *hist = 0; TIter iter(gPad->GetListOfPrimitives()); while(TObject *obj = iter.Next()) { - if(obj->InheritsFrom(TH1::Class())) + if(obj->InheritsFrom(TH1::Class())) { hist = (TH1*)obj; + break; + } } if(!hist) return false; @@ -545,11 +558,11 @@ bool GCanvas::HandleMouseShiftPress(Int_t event,Int_t x,Int_t y) { switch(hist->GetDimension()) { case 1: { - if(hist->InheritsFrom(GH1D::Class())) { - new GCanvas(); - ((GH1D*)hist)->GetParent()->Draw("colz"); - return true; - } + //if(hist->InheritsFrom(GH1D::Class())) { + // new GCanvas(); + // ((GH1D*)hist)->GetHistParent()->Draw("colz"); + // return true; + //} std::vector hists = FindHists(); new GCanvas(); //options.Append("HIST"); @@ -574,6 +587,7 @@ bool GCanvas::HandleMouseControlPress(Int_t event,Int_t x,Int_t y) { return false; //printf("GetSelected()->GetName() = %s\n",GetSelected()->GetName()); if(GetSelected()->InheritsFrom(TCutG::Class())) { + GetSelected()->SetBit(ISPID); if(TRuntimeObjects::Get()) TRuntimeObjects::Get()->GetGates().Add(GetSelected()); } @@ -624,6 +638,8 @@ bool GCanvas::Process1DArrowKeyPress(Event_t *event,UInt_t *keysym) { int xdiff = last-first; int mdiff = max-min-2; + GH1 *next=NULL; + switch (*keysym) { case kMyArrowLeft: { @@ -675,54 +691,61 @@ bool GCanvas::Process1DArrowKeyPress(Event_t *event,UInt_t *keysym) { } break; - case kMyArrowUp: { - GH1D* ghist = NULL; - for(auto hist : hists){ - if(hist->InheritsFrom(GH1D::Class())){ - ghist = (GH1D*)hist; - break; - } - } - - if(ghist) { - TH1* prev = ghist->GetNext(); - if(prev) { - prev->GetXaxis()->SetRange(first,last); - //prev->GetXaxis()->SetRange(axis->GetBinLowEdge(first), - // axis->GetBinUpEdge(last)); - prev->Draw(""); - RedrawMarkers(); - edited = true; - } - } - } - break; - - case kMyArrowDown: { - GH1D* ghist = NULL; - for(auto hist : hists){ - if(hist->InheritsFrom(GH1D::Class())){ - ghist = (GH1D*)hist; - break; - } - } - - if(ghist) { - TH1* prev = ghist->GetPrevious(); - if(prev) { - prev->GetXaxis()->SetRange(first,last); - //prev->GetXaxis()->SetRange(axis->GetBinLowEdge(first), - // axis->GetBinUpEdge(last)); - prev->Draw(""); - RedrawMarkers(); - edited = true; - } - } - } - break; + case kMyArrowUp: + gHist = NULL; + next = NULL; + //printf("%s\tkkey_arrowup.\n",__PRETTY_FUNCTION__); + for(auto hist : hists){ + if(hist->InheritsFrom(GH1::Class())){ + gHist = (GH1*)hist; + break; + } + } + if(gHist && gHist->IsSummary() && gHist->GetHistParent() && gHist->GetHistParent()->InheritsFrom(GH2::Class())) { + next = ((GH2*)gHist->GetHistParent())->SummaryProjection(gHist,gHist->GetProjectionAxis(), + (int)GH2::kForward,false); + } else if(gHist && gHist->GetHistParent()) { + next = ((GH2*)gHist->GetHistParent())->GetNext(gHist,(int)GH2::kForward); + } + if(next) { + next->GetXaxis()->SetRangeUser(gHist->GetXaxis()->GetBinLowEdge(gHist->GetXaxis()->GetFirst()), + gHist->GetXaxis()->GetBinUpEdge(gHist->GetXaxis()->GetLast())); + //prev->GetXaxis()->SetRange(axis->GetBinLowEdge(first), + // axis->GetBinUpEdge(last)); + next->Draw(""); + RedrawMarkers(); + edited = true; + } + break; + case kMyArrowDown: + //printf("%s\tkkey_arrowdown.\n",__PRETTY_FUNCTION__); + gHist = NULL; + next = NULL; + for(auto hist : hists){ + if(hist->InheritsFrom(GH1::Class())){ + gHist = (GH1*)hist; + break; + } + } + if(gHist && gHist->IsSummary() && gHist->GetHistParent() && gHist->GetHistParent()->InheritsFrom(GH2::Class())) { + next = ((GH2*)gHist->GetHistParent())->SummaryProjection(gHist,gHist->GetProjectionAxis(), + (int)GH2::kBackward,false); + } else if(gHist && gHist->GetHistParent()) { + next = ((GH2*)gHist->GetHistParent())->GetNext(gHist,(int)GH2::kBackward); + } + if(next) { + next->GetXaxis()->SetRangeUser(gHist->GetXaxis()->GetBinLowEdge(gHist->GetXaxis()->GetFirst()), + gHist->GetXaxis()->GetBinUpEdge(gHist->GetXaxis()->GetLast())); + //prev->GetXaxis()->SetRange(axis->GetBinLowEdge(first), + // axis->GetBinUpEdge(last)); + next->Draw(""); + RedrawMarkers(); + edited = true; + } + break; default: - printf("keysym = %i\n",*keysym); - break; + printf("keysym = %i\n",*keysym); + break; } return edited; } @@ -756,7 +779,10 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { case kKey_Control: toggle_control(); break; - + case kKey_F3: + hists.at(0)->DrawPanel(); + edited = false; + break; case kKey_b: edited = SetBackgroundMarkers(); break; @@ -764,18 +790,17 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { case kKey_B: edited = CycleBackgroundSubtraction(); break; - - case kKey_d: - { - printf("i am here.\n"); - new GPopup(gClient->GetDefaultRoot(),gClient->GetDefaultRoot(),500,200); - //new GPopup(0,0); - //this); - //TGFileInfo fi; - //new TGFileDialog(gClient->GetDefaultRoot(),gClient->GetDefaultRoot(), - // kFDOpen, &fi); + case kKey_c: + //printf("c was pressed!\n"); + break; + case kKey_d: + //printf("i am here.\n"); + if(hists.size()>0 && hists.at(0)->InheritsFrom(GH1::Class())) { + if(((GH1*)hists.at(0))->GetHistParent() && ((GH1*)hists.at(0))->GetHistParent()->InheritsFrom(GH2::Class())) { + //new GHistPopup((GH2*)((GH1*)hists.at(0))->GetHistParent()); + } } break; @@ -829,37 +854,32 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { } break; case kKey_F: - //this->GetListOfPrimitives()->Print(); - if(hists.back()->IsA() != GH1D::Class()) - break; - { - GH1D *ghist = (GH1D*)hists.back(); - GetContextMenu()->Action(ghist,ghist->Class()->GetMethodAny("DoPhotoPeakFit")); - { - double x1 = ghist->GetLastXlow(); - double x2 = ghist->GetLastXhigh(); - TIter iter(this->GetCanvas()->GetListOfPrimitives()); - while(TObject *obj = iter.Next()) { - if(obj->InheritsFrom(TPad::Class())) { - TPad *pad = (TPad*)obj; - TIter iter2(pad->GetListOfPrimitives()); - while(TObject *obj2=iter2.Next()) { - if(obj2->InheritsFrom(TH1::Class())) { - GH1D* hist = (GH1D*)obj2; - hist->DoPhotoPeakFit(x1,x2); - pad->Modified(); - pad->Update(); - } - } - } - } - - //for(int i=0;iGetXaxis()->SetRangeUser(hists.back()->GetXaxis()->GetFirst(),hists.back()->GetXaxis()->GetLast()); - - } - edited = true; - } + //if(hists.back()->IsA() != GH1D::Class()) + // break; + //{ + //GH1D *ghist = (GH1D*)hists.back(); + //GetContextMenu()->Action(ghist,ghist->Class()->GetMethodAny("DoPhotoPeakFit")); + //{ + // double x1 = ghist->GetLastXlow(); + // double x2 = ghist->GetLastXhigh(); + // TIter iter(this->GetCanvas()->GetListOfPrimitives()); + // while(TObject *obj = iter.Next()) { + // if(obj->InheritsFrom(TPad::Class())) { + // TPad *pad = (TPad*)obj; + // TIter iter2(pad->GetListOfPrimitives()); + // while(TObject *obj2=iter2.Next()) { + // if(obj2->InheritsFrom(TH1::Class())) { + // GH1D* hist = (GH1D*)obj2; + // hist->DoPhotoPeakFit(x1,x2); + // pad->Modified(); + // pad->Update(); + // } + // } + // } + // } + //} + //edited = true; + //} break; @@ -869,10 +889,21 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { if(GausFit(hists.back(),fMarkers.at(fMarkers.size()-2)->localx,fMarkers.back()->localx)) edited = true; break; - - //case kKey_G: - // edited = GausBGFit(); - // break; + case kKey_G: + if(!hists.back() || !fMarkers.size()==4) { + printf( CYAN "must have a a1 hist with 4 markers drawn" RESET_COLOR "\n"); + } else { + std::vector xvalues; + xvalues.push_back(fMarkers.at(0)->localx); + xvalues.push_back(fMarkers.at(1)->localx); + xvalues.push_back(fMarkers.at(2)->localx); + xvalues.push_back(fMarkers.at(3)->localx); + RemoveMarker("all"); + std::sort(xvalues.begin(),xvalues.end()); + //std::cout << xvalues.at(1)<<"\t"<1) { @@ -905,6 +936,20 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { printf( RESET_COLOR ); } + break; + case kKey_k: + gHist=0; + for(auto hist : hists){ + if(hist->InheritsFrom(GH1::Class())){ + gHist = (GH1D*)hist; + break; + } + } + if(gHist) { + GetContextMenu()->Action(gHist,gHist->Class()->GetMethodAny("Calibrate")); + edited = true; + } + break; case kKey_l: if(GetLogy()){ @@ -955,6 +1000,7 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { } edited=true; break; + case kKey_o: for(unsigned int i=0;iGetXaxis()->UnZoom(); @@ -964,93 +1010,77 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { edited = true; break; - case kKey_p: { - if(GetNMarkers() < 2){ - break; - } - GH1D* ghist = NULL; - for(auto hist : hists){ - if(hist->InheritsFrom(GH1D::Class())){ - ghist = (GH1D*)hist; - break; - } - } - // ok, i found a bug. if someone tries to gate on a histogram - // that is already zoomed, bad things will happen; namely the bins - // in the zoomed histogram will not map correctly to the parent. To get - // around this we need the bin value, not the bin! pcb. - // - if(ghist){ - GH1D* proj = NULL; - int binlow = fMarkers.at(fMarkers.size()-1)->binx; - int binhigh = fMarkers.at(fMarkers.size()-2)->binx; - if(binlow > binhigh){ - std::swap(binlow, binhigh); - } - double value_low = ghist->GetXaxis()->GetBinLowEdge(binlow); - double value_high = ghist->GetXaxis()->GetBinLowEdge(binhigh); - - { - double epsilon = 16*(std::nextafter(value_low, INFINITY) - value_low); - value_low += epsilon; - } - - { - double epsilon = 16*(value_high - std::nextafter(value_high, -INFINITY)); - value_high -= epsilon; - } - - if(fBackgroundMarkers.size()>=2 && - fBackgroundMode!=kNoBackground){ - int bg_binlow = fBackgroundMarkers.at(0)->binx; - int bg_binhigh = fBackgroundMarkers.at(1)->binx; - if(bg_binlow > bg_binhigh){ - std::swap(bg_binlow, bg_binhigh); - } - double bg_value_low = ghist->GetXaxis()->GetBinCenter(bg_binlow); - double bg_value_high = ghist->GetXaxis()->GetBinCenter(bg_binhigh); - { - double epsilon = 16*(std::nextafter(value_low, INFINITY) - value_low); - bg_value_low += epsilon; - } - - { - double epsilon = 16*(value_high - std::nextafter(value_high, -INFINITY)); - bg_value_high -= epsilon; + case kKey_O: + { + TIter iter(this->GetListOfPrimitives()); + while(TObject *obj = iter.Next()){ + if(obj->InheritsFrom(TPad::Class())){ + TPad *pad = (TPad*)obj; + TIter iter2(pad->GetListOfPrimitives()); + while(TObject *obj2 = iter2.Next()){ + if(obj2->InheritsFrom(TH1::Class()) || obj2->InheritsFrom(GH1::Class())){ + TH1 *hist = (TH1*)obj2; + hist->GetXaxis()->UnZoom(); + hist->GetYaxis()->UnZoom(); } - // Using binhigh-1 instead of binhigh, - // because the ProjectionX/Y functions from ROOT use inclusive bin numbers, - // rather than exclusive. - // - proj = ghist->Project_Background(value_low, value_high, - bg_value_low, bg_value_high, - fBackgroundMode); - } else { - proj = ghist->Project(value_low, value_high); - } - if(proj){ - proj->Draw(""); - edited=true; } + pad->Modified(); + pad->Update(); } } + edited = true; + } break; - case kKey_P: { - GH1D* ghist = NULL; - for(auto hist : hists){ - if(hist->InheritsFrom(GH1D::Class())){ - ghist = (GH1D*)hist; - break; - } - } + case kKey_p: + if(GetNMarkers()<2) { + break; + } + gHist=0; + for(auto hist : hists){ + if(hist->InheritsFrom(GH1::Class())){ + gHist = (GH1D*)hist; + break; + } + } + if(gHist) { + GH1D *proj=0; + int binlow = fMarkers.at(fMarkers.size()-1)->binx; + int binhigh = fMarkers.at(fMarkers.size()-2)->binx; + if(binlow > binhigh) std::swap(binlow, binhigh); + if(fBackgroundMarkers.size()>=2) { //&& + int bg_binlow = fBackgroundMarkers.at(0)->binx; + int bg_binhigh = fBackgroundMarkers.at(1)->binx; + if(bg_binlow > bg_binhigh) std::swap(bg_binlow, bg_binhigh); + double scale = -1*(double(binhigh)-double(binlow))/(double(bg_binhigh)-double(bg_binlow)); + //proj = gHist->Project(binlow,binhigh,bg_binlow,bg_binhigh,scale,"keep+"); + proj = gHist->Project(binlow,binhigh,bg_binlow,bg_binhigh,scale); + } else { + //proj = gHist->Project(binlow,binhigh,"keep+"); + proj = gHist->Project(binlow,binhigh); + } + if(proj){ + proj->Draw(""); + edited=true; + } + } + break; - if(ghist){ - ghist->GetParent()->Draw(); - edited=true; - } - } - break; +// case kKey_P: { +// GH1D* ghist = NULL; +// for(auto hist : hists){ +// if(hist->InheritsFrom(GH1D::Class())){ +// ghist = (GH1D*)hist; +// break; +// } +// } +// +// if(ghist && ghist->GetHistParent()) { +// ghist->GetHistParent()->Draw(); +// edited=true; +// } +// } +// break; case kKey_q:{ TH1* ghist = hists.at(0); if(GetNMarkers()>1) { @@ -1097,7 +1127,7 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { TPad *pad = (TPad*)obj; TIter iter2(pad->GetListOfPrimitives()); while(TObject *obj2=iter2.Next()) { - if(obj2->InheritsFrom(TH1::Class())) { + if(obj2->InheritsFrom(TH1::Class())||obj2->InheritsFrom(GH1::Class())) { TH1* hist = (TH1*)obj2; hist->GetYaxis()->SetRangeUser(y1,y2); pad->Modified(); @@ -1162,6 +1192,54 @@ bool GCanvas::Process1DKeyboardPress(Event_t *event,UInt_t *keysym) { RemoveMarker("all"); } break; + case kKey_y: + if(gPad->GetLogy()) { + gPad->SetLogy(0); + }else{ + gPad->SetLogy(1); + } + edited = true; + break; + case kKey_Y: + //printf("in upper case Z\n"); + { + TIter iter(this->GetListOfPrimitives()); + bool set = !gPad->GetLogy(); + //int counter = 0; + while(TObject *obj = iter.Next()) { + if(obj->InheritsFrom(TPad::Class())) { + TPad *pad = (TPad*)obj; + TIter iter2(pad->GetListOfPrimitives()); + while(TObject *obj2=iter2.Next()) { + if(obj2->InheritsFrom(TH1::Class()) || + obj2->InheritsFrom(GH1::Class())) { + //TH2* hist = (TH2*)obj2; + if(set && !pad->GetLogy()) { + //printf("\t %i set=true && logz=false;\n",counter++); + TVirtualPad *cpad = gPad; + pad->cd(); + gPad->SetLogy(1); + cpad->cd(); + edited = true; + } else if(!set && pad->GetLogy()) { + //printf("\t %i set=false && logz=true;\n",counter++); + TVirtualPad *cpad = gPad; + pad->cd(); + gPad->SetLogy(0); + cpad->cd(); + edited = true; + } + } + } + } + } + + //for(int i=0;iGetXaxis()->SetRangeUser(hists.back()->GetXaxis()->GetFirst(),hists.back()->GetXaxis()->GetLast()); + + } + edited = true; + break; case kKey_F9:{ int color = hists.at(0)->GetLineColor() + 1; if(color>9) @@ -1193,9 +1271,41 @@ bool GCanvas::Process2DKeyboardPress(Event_t *event,UInt_t *keysym) { bool edited = false; //printf("2d hist key pressed.\n"); std::vector hists = FindHists(2); + std::vector hists_oned = FindHists(1); if(hists.size()<1) return edited; switch(*keysym) { + case kKey_c: + //printf("%s\n",this->IsA()->GetName()); + { + double ymin,ymax,xmin,xmax; + int islogz = gPad->GetLogz(); + ymin = hists.back()->GetYaxis()->GetBinLowEdge(hists.back()->GetYaxis()->GetFirst()); + ymax = hists.back()->GetYaxis()->GetBinUpEdge(hists.back()->GetYaxis()->GetLast()); + xmin = hists.back()->GetXaxis()->GetBinLowEdge(hists.back()->GetXaxis()->GetFirst()); + xmax = hists.back()->GetXaxis()->GetBinUpEdge(hists.back()->GetXaxis()->GetLast()); + TIter iter(GetListOfPrimitives()); + while(TObject *obj = iter.Next()) { + if(obj->InheritsFrom(TPad::Class())) { + ((TPad*)obj)->SetLogz(islogz); + TIter iter2(((TPad*)obj)->GetListOfPrimitives()); + while(TObject *obj2 = iter2.Next()) { + //printf("%s \n",obj2->GetName()); + if(obj2->InheritsFrom(TH1::Class())) { + //printf("dim = %i @ 0x%08x \n",((TH1*)obj2)->GetDimension() ); + + if(((TH1*)obj2)->GetDimension()==2) { + ((TH1*)obj2)->GetYaxis()->SetRangeUser(ymin,ymax); + ((TH1*)obj2)->GetXaxis()->SetRangeUser(xmin,xmax); + } + } + } + } + } + } + edited = true; + //printf("c was pressed!\n"); + break; case kKey_e: if(GetNMarkers()<2) break; @@ -1229,7 +1339,7 @@ bool GCanvas::Process2DKeyboardPress(Event_t *event,UInt_t *keysym) { TPad *pad = (TPad*)obj; TIter iter2(pad->GetListOfPrimitives()); while(TObject *obj2=iter2.Next()) { - if(obj2->InheritsFrom(TH1::Class())) { + if(obj2->InheritsFrom(TH1::Class())||obj2->InheritsFrom(GH1::Class())) { TH1* hist = (TH1*)obj2; hist->GetXaxis()->SetRangeUser(x1,x2); pad->Modified(); @@ -1283,6 +1393,20 @@ bool GCanvas::Process2DKeyboardPress(Event_t *event,UInt_t *keysym) { edited = true; RemoveMarker("all"); break; + case kKey_i: + if(gPad) { + for(unsigned int i=0;iGetListOfPrimitives()); + while(TObject *obj =iter.Next()) { + if(obj->InheritsFrom(TCutG::Class())) { + TH2* h = (TH2*)hists.at(i); + double sum = ((TCutG*)obj)->IntegralHist(h); + printf(CYAN "\t%s:\t %.02f" RESET_COLOR "\n",obj->GetName(),sum); + } + } + } + } + break; case kKey_n: RemoveMarker("all"); //for(unsigned int i=0;iSumw2(false); edited = true; break; + case kKey_N: + RemoveMarker("all"); + { + std::vector toremove; + TList *mylist = gPad->GetListOfPrimitives(); + for(int i=0;iGetSize();i++) { + if(mylist->At(i)->InheritsFrom(TCutG::Class())) { + toremove.push_back(mylist->At(i)->GetName()); + } + } + for(int i=0;iRemove(mylist->FindObject(toremove.at(i).c_str())); + } + } + RemovePeaks(hists.data(),hists.size()); + for(unsigned int ii=0;iiSumw2(false); + edited = true; + break; case kKey_o: for(unsigned int i=0;iInheritsFrom(GH2Base::Class())){ + if(hist->InheritsFrom(GH2::Class())){ ghist = (GH2D*)hist; break; } @@ -1324,205 +1467,195 @@ bool GCanvas::Process2DKeyboardPress(Event_t *event,UInt_t *keysym) { } break; case kKey_r: - if(GetNMarkers()<2) - break; - { - //fMarkers.at(fMarkers.size()-1)->Print(); - //fMarkers.at(fMarkers.size()-2)->Print(); - double y1 = fMarkers.at(fMarkers.size()-1)->localy; - double y2 = fMarkers.at(fMarkers.size()-2)->localy; - if(y1>y2) - std::swap(y1,y2); - for(unsigned int i=0;iGetYaxis()->SetRangeUser(y1,y2); - } - edited = true; - RemoveMarker("all"); - break; + if(GetNMarkers()<2) + break; + { + //fMarkers.at(fMarkers.size()-1)->Print(); + //fMarkers.at(fMarkers.size()-2)->Print(); + double y1 = fMarkers.at(fMarkers.size()-1)->localy; + double y2 = fMarkers.at(fMarkers.size()-2)->localy; + if(y1>y2) + std::swap(y1,y2); + for(unsigned int i=0;iGetYaxis()->SetRangeUser(y1,y2); + } + edited = true; + RemoveMarker("all"); + break; case kKey_R: - //this->GetListOfPrimitives()->Print(); - GetContextMenu()->Action(hists.back()->GetYaxis(),hists.back()->GetYaxis()->Class()->GetMethodAny("SetRangeUser")); - { - double y1 = hists.back()->GetYaxis()->GetBinCenter(hists.back()->GetYaxis()->GetFirst()); - double y2 = hists.back()->GetYaxis()->GetBinCenter(hists.back()->GetYaxis()->GetLast()); - TIter iter(this->GetListOfPrimitives()); - while(TObject *obj = iter.Next()) { - if(obj->InheritsFrom(TPad::Class())) { - TPad *pad = (TPad*)obj; - TIter iter2(pad->GetListOfPrimitives()); - while(TObject *obj2=iter2.Next()) { - if(obj2->InheritsFrom(TH2::Class())) { - TH2* hist = (TH2*)obj2; - hist->GetYaxis()->SetRangeUser(y1,y2); - pad->Modified(); - pad->Update(); - } - } - } - } + //this->GetListOfPrimitives()->Print(); + GetContextMenu()->Action(hists.back()->GetYaxis(),hists.back()->GetYaxis()->Class()->GetMethodAny("SetRangeUser")); + { + double y1 = hists.back()->GetYaxis()->GetBinCenter(hists.back()->GetYaxis()->GetFirst()); + double y2 = hists.back()->GetYaxis()->GetBinCenter(hists.back()->GetYaxis()->GetLast()); + TIter iter(this->GetListOfPrimitives()); + while(TObject *obj = iter.Next()) { + if(obj->InheritsFrom(TPad::Class())) { + TPad *pad = (TPad*)obj; + TIter iter2(pad->GetListOfPrimitives()); + while(TObject *obj2=iter2.Next()) { + if(obj2->InheritsFrom(TH2::Class()) || + (obj2->InheritsFrom(GH2::Class()))) { + TH2* hist = (TH2*)obj2; + hist->GetYaxis()->SetRangeUser(y1,y2); + pad->Modified(); + pad->Update(); + } + } + } + } - //for(int i=0;iGetXaxis()->SetRangeUser(hists.back()->GetXaxis()->GetFirst(),hists.back()->GetXaxis()->GetLast()); + //for(int i=0;iGetXaxis()->SetRangeUser(hists.back()->GetXaxis()->GetFirst(),hists.back()->GetXaxis()->GetLast()); - } - edited = true; - break; + } + edited = true; + break; - case kKey_x: { - GH2D* ghist = NULL; - for(auto hist : hists) { - if(hist->InheritsFrom(GH2Base::Class())){ - ghist = (GH2D*)hist; - break; - } + case kKey_x: + gHist = NULL; + for(auto hist : hists) { + if(hist->InheritsFrom(GH2::Class())){ + gHist = (GH2*)hist; + break; } + } - if(ghist){ - ghist->SetSummary(0); - TH1 *phist = ghist->ProjectionX();//->Draw(); - if(phist) { - new GCanvas(); - phist->Draw(""); - } - edited=true; + if(gHist){ + //gHist->SetSummary(0); + GH1 *phist = ((GH2*)gHist)->ProjectionX();//->Draw(); + if(phist) { + new GCanvas(); + phist->Draw(""); } + edited=true; } break; - case kKey_X: { - GH2D* ghist = NULL; - for(auto hist : hists) { - if(hist->InheritsFrom(GH2Base::Class())){ - ghist = (GH2D*)hist; - break; - } + case kKey_X: + gHist = NULL; + for(auto hist : hists) { + if(hist->InheritsFrom(GH2::Class())){ + gHist = (GH2*)hist; + break; } - - if(ghist){ - ghist->SetSummary(true); - ghist->SetSummaryDirection(kYDirection); - TH1* phist = ghist->GetNextSummary(0,false); - if(phist) { - new GCanvas(); - phist->Draw(""); - } - edited = true; + } + if(gHist){ + GH1* phist = ((GH2*)gHist)->SummaryProjection(0,GH1::kXaxis,GH2::kForward,false); + if(phist) { + new GCanvas(); + phist->Draw(""); } + edited = true; } break; - case kKey_y: { - GH2D* ghist = NULL; - for(auto hist : hists) { - if(hist->InheritsFrom(GH2Base::Class())){ - ghist = (GH2D*)hist; - break; - } + case kKey_y: + gHist = NULL; + for(auto hist : hists) { + if(hist->InheritsFrom(GH2::Class())){ + gHist = (GH2*)hist; + break; } + } - if(ghist){ - ghist->SetSummary(0); - //printf("ghist = 0x%08x\n",ghist); - TH1 *phist = ghist->ProjectionY();//->Draw(); - //printf("phist = 0x%08x\n",phist); - //printf("phist->GetName() = %s\n",phist->GetName()); - if(phist) { - new GCanvas(); - phist->Draw(""); - } - edited=true; + if(gHist){ + GH1 *phist = ((GH2*)gHist)->ProjectionY();//->Draw(); + if(phist) { + new GCanvas(); + phist->Draw(""); } + edited=true; } + break; - case kKey_Y: { - GH2D* ghist = NULL; - for(auto hist : hists) { - if(hist->InheritsFrom(GH2Base::Class())){ - ghist = (GH2D*)hist; - break; - } + case kKey_Y: + gHist = NULL; + for(auto hist : hists) { + if(hist->InheritsFrom(GH2::Class())){ + gHist = (GH2*)hist; + break; } + } - if(ghist){ - ghist->SetSummary(true); - ghist->SetSummaryDirection(kXDirection); - //TH1* phist = ghist->SummaryProject(1); - TH1* phist = ghist->GetNextSummary(0,false); - if(phist) { - new GCanvas(); - phist->Draw(""); - } - edited = true; + if(gHist){ + //gHist->SetSummary(true); + GH1* phist = ((GH2*)gHist)->SummaryProjection(0,GH1::kYaxis,GH2::kForward,false); + if(phist) { + new GCanvas(); + phist->Draw(""); } + edited = true; } break; case kKey_z: - //printf("in lower case z\n"); - if(gPad->GetLogz()){ - //printf("\t GetLogZ() = true;\n"); - // Show full z range, not restricted to positive values. - //for(unsigned int i=0;iGetYaxis()->UnZoom(); - //} - //TVirtualPad *cpad = gPad; - //this->cd(); - gPad->SetLogz(0); - //cpad->cd(); - } else { - //printf("\t GetLogZ() = false;\n"); - // Only show plot from 0 up when in log scale. - //for(unsigned int i=0;iGetZaxis()->GetXmin()<0) { - // hists.at(i)->GetZaxis()->SetRangeUser(0,hists.at(i)->GetYaxis()->GetXmax()); - // } - //} - //TVirtualPad *cpad = gPad; - //this->cd(); - gPad->SetLogz(1); - //cpad->cd(); - } - edited = true; - break; + //printf("in lower case z\n"); + if(gPad->GetLogz()){ + //printf("\t GetLogZ() = true;\n"); + // Show full z range, not restricted to positive values. + //for(unsigned int i=0;iGetYaxis()->UnZoom(); + //} + //TVirtualPad *cpad = gPad; + //this->cd(); + gPad->SetLogz(0); + //cpad->cd(); + } else { + //printf("\t GetLogZ() = false;\n"); + // Only show plot from 0 up when in log scale. + //for(unsigned int i=0;iGetZaxis()->GetXmin()<0) { + // hists.at(i)->GetZaxis()->SetRangeUser(0,hists.at(i)->GetYaxis()->GetXmax()); + // } + //} + //TVirtualPad *cpad = gPad; + //this->cd(); + gPad->SetLogz(1); + //cpad->cd(); + } + edited = true; + break; case kKey_Z: - //printf("in upper case Z\n"); - { - TIter iter(this->GetListOfPrimitives()); - bool set = !gPad->GetLogz(); - //int counter = 0; - while(TObject *obj = iter.Next()) { - if(obj->InheritsFrom(TPad::Class())) { - TPad *pad = (TPad*)obj; - TIter iter2(pad->GetListOfPrimitives()); - while(TObject *obj2=iter2.Next()) { - if(obj2->InheritsFrom(TH2::Class())) { - //TH2* hist = (TH2*)obj2; - if(set && !pad->GetLogz()) { - //printf("\t %i set=true && logz=false;\n",counter++); - TVirtualPad *cpad = gPad; - pad->cd(); - gPad->SetLogz(1); - cpad->cd(); - edited = true; - } else if(!set && pad->GetLogz()) { - //printf("\t %i set=false && logz=true;\n",counter++); - TVirtualPad *cpad = gPad; - pad->cd(); - gPad->SetLogz(0); - cpad->cd(); - edited = true; - } - } - } - } - } + //printf("in upper case Z\n"); + { + TIter iter(this->GetListOfPrimitives()); + bool set = !gPad->GetLogz(); + //int counter = 0; + while(TObject *obj = iter.Next()) { + if(obj->InheritsFrom(TPad::Class())) { + TPad *pad = (TPad*)obj; + TIter iter2(pad->GetListOfPrimitives()); + while(TObject *obj2=iter2.Next()) { + if(obj2->InheritsFrom(TH2::Class()) || + obj2->InheritsFrom(GH2::Class())) { + //TH2* hist = (TH2*)obj2; + if(set && !pad->GetLogz()) { + //printf("\t %i set=true && logz=false;\n",counter++); + TVirtualPad *cpad = gPad; + pad->cd(); + gPad->SetLogz(1); + cpad->cd(); + edited = true; + } else if(!set && pad->GetLogz()) { + //printf("\t %i set=false && logz=true;\n",counter++); + TVirtualPad *cpad = gPad; + pad->cd(); + gPad->SetLogz(0); + cpad->cd(); + edited = true; + } + } + } + } + } - //for(int i=0;iGetXaxis()->SetRangeUser(hists.back()->GetXaxis()->GetFirst(),hists.back()->GetXaxis()->GetLast()); + //for(int i=0;iGetXaxis()->SetRangeUser(hists.back()->GetXaxis()->GetFirst(),hists.back()->GetXaxis()->GetLast()); - } - edited = true; - break; + } + edited = true; + break; @@ -2004,7 +2137,7 @@ TH1 *GCanvas::GetBackGroundHist(GMarker *addlow,GMarker *addhigh) { return 0; Double_t bg_frac = (addhigh->localx-addlow->localx +1)*const_bg->GetParameter(0)/pj_total; //GMemObj = *mobj = GRootObjectManager::Instance()->FindObject(hist->GetName()); - //if(!mobj || !mobj->GetParent() || !mobj->GetParent()->InheritsFrom("TH2")) + //if(!mobj || !mobj->GetHistParent() || !mobj->GetHistParent()->InheritsFrom("TH2")) // return 0; TH1 *temp = (TH1*)hist->Clone(Form("%s_bg",hist->GetName())); temp ->SetTitle(Form(" - bg(frac %0.4f)",bg_frac)); @@ -2017,17 +2150,17 @@ TH1 *GCanvas::GetBackGroundHist(GMarker *addlow,GMarker *addhigh) { return temp_bg; OrderBGMarkers(); GMemObj *mobj = GRootObjectManager::Instance()->FindMemObject(hist->GetName()); - if(!mobj || !mobj->GetParent() || !mobj->GetParent()->InheritsFrom("TH2")) + if(!mobj || !mobj->GetHistParent() || !mobj->GetHistParent()->InheritsFrom("TH2")) return temp_bg; int bin0,bin1; if(!strcmp(mobj->GetOption(),"ProjY")) { - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-1)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-2)->localx); - temp_bg = ((TH2*)mobj->GetParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-1)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-2)->localx); + temp_bg = ((TH2*)mobj->GetHistParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); } else { - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-1)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-2)->localx); - temp_bg = ((TH2*)mobj->GetParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-1)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(fBG_Markers.size()-2)->localx); + temp_bg = ((TH2*)mobj->GetHistParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); } temp_bg->SetTitle(Form(" - bg(%.0f to %.0f)",fBG_Markers.at(0)->localx,fBG_Markers.at(1)->localx)); return temp_bg; @@ -2040,23 +2173,23 @@ TH1 *GCanvas::GetBackGroundHist(GMarker *addlow,GMarker *addhigh) { return temp_bg; OrderBGMarkers(); GMemObj *mobj = GRootObjectManager::Instance()->FindMemObject(hist->GetName()); - if(!mobj || !mobj->GetParent() || !mobj->GetParent()->InheritsFrom("TH2")) + if(!mobj || !mobj->GetHistParent() || !mobj->GetHistParent()->InheritsFrom("TH2")) return temp_bg; int bin0,bin1; if(!strcmp(mobj->GetOption(),"ProjY")) { - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); - temp_bg = ((TH2*)mobj->GetParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(2)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(3)->localx); - temp_bg1 = ((TH2*)mobj->GetParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); + temp_bg = ((TH2*)mobj->GetHistParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(2)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(3)->localx); + temp_bg1 = ((TH2*)mobj->GetHistParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); } else { - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); - temp_bg = ((TH2*)mobj->GetParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(2)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(3)->localx); - temp_bg1 = ((TH2*)mobj->GetParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); + temp_bg = ((TH2*)mobj->GetHistParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(2)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(3)->localx); + temp_bg1 = ((TH2*)mobj->GetHistParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); } temp_bg->Add(temp_bg1,1); temp_bg->SetTitle(Form(" - bg(%.0f to %.0f and %.0f to %.0f)",fBG_Markers.at(0)->localx,fBG_Markers.at(1)->localx, @@ -2070,17 +2203,17 @@ TH1 *GCanvas::GetBackGroundHist(GMarker *addlow,GMarker *addhigh) { return temp_bg; OrderBGMarkers(); GMemObj *mobj = GRootObjectManager::Instance()->FindMemObject(hist->GetName()); - if(!mobj || !mobj->GetParent() || !mobj->GetParent()->InheritsFrom("TH2")) + if(!mobj || !mobj->GetHistParent() || !mobj->GetHistParent()->InheritsFrom("TH2")) return temp_bg; int bin0,bin1; if(!strcmp(mobj->GetOption(),"ProjY")) { - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); - temp_bg = ((TH2*)mobj->GetParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); + temp_bg = ((TH2*)mobj->GetHistParent())->ProjectionX(Form("%s_bg",hist->GetName()),bin0,bin1); } else { - bin1 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); - bin0 = ((TH2*)mobj->GetParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); - temp_bg = ((TH2*)mobj->GetParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); + bin1 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(0)->localx); + bin0 = ((TH2*)mobj->GetHistParent())->GetXaxis()->FindBin(fBG_Markers.at(1)->localx); + temp_bg = ((TH2*)mobj->GetHistParent())->ProjectionY(Form("%s_bg",hist->GetName()),bin0,bin1); } temp_bg->SetTitle(Form(" - bg(%.0f to %.0f)",fBG_Markers.at(0)->localx,fBG_Markers.at(1)->localx)); return temp_bg; @@ -2094,3 +2227,11 @@ TH1 *GCanvas::GetBackGroundHist(GMarker *addlow,GMarker *addhigh) { return 0; } */ + + +void GCanvas::Streamer(TBuffer &R__b) +{ + TCanvas::Streamer(R__b); +} + + diff --git a/libraries/GROOT/GCutG.cxx b/libraries/GROOT/GCutG.cxx index 03200267..3e59f8f2 100644 --- a/libraries/GROOT/GCutG.cxx +++ b/libraries/GROOT/GCutG.cxx @@ -18,7 +18,7 @@ void GCutG::Print(Option_t *opt) const { } -int GCutG::SaveTo(const char *cutname,const char* filename,Option_t* option) { +int GCutG::SaveTo(const char *cutname,const char* filename,const char *tagname,Option_t* option) { TPreserveGDirectory pd; std::string fname = filename; std::string cname = cutname; @@ -30,15 +30,21 @@ int GCutG::SaveTo(const char *cutname,const char* filename,Option_t* option) { fname = gEnv->GetValue("GRUT.DefaultCutFile",""); GCutG *cut = (GCutG*)this->Clone(cname.c_str()); cut->SetNameTitle(cname.c_str(),cname.c_str()); + cut->SetTag(tagname); TFile f(fname.c_str(),option); + //printf("Attepting to save %s to %s... ",cut->GetName(),f.GetName()); if(f.Get(cname.c_str())) { f.cd();//Get(cname.c_str())->Delete(); gDirectory->Delete(cname.c_str()); } - return cut->Write(cname.c_str(),TObject::kOverwrite | TObject::kSingleKey); + //int bytes = cut->Write(cname.c_str(),TObject::kOverwrite | TObject::kSingleKey); + f.Add(cut,true); + //printf("%i\n",bytes); fflush(stdout); + return f.Write(); } + void GCutG::SetGateMethod(const char* xclass,const char* xmethod, const char* yclass,const char* ymethod) { fXGateClass = xclass; diff --git a/libraries/GROOT/GDoubleGaus.cxx b/libraries/GROOT/GDoubleGaus.cxx new file mode 100644 index 00000000..2a7e75ec --- /dev/null +++ b/libraries/GROOT/GDoubleGaus.cxx @@ -0,0 +1,336 @@ + +#include +#include +#include +#include +#include +#include + +#include "Globals.h" +#include "GRootFunctions.h" +#include "GCanvas.h" + +ClassImp(GDoubleGaus) + +GDoubleGaus::GDoubleGaus(Double_t cent1,Double_t cent2,Double_t xlow,Double_t xhigh,Option_t *opt) + : TF1("doublegausbg",GRootFunctions::DoubleGaus,xlow,xhigh,7,1,TF1::EAddToList::kNo), + fBGFit("background","pol1",xlow,xhigh,TF1::EAddToList::kNo), + fGaus1("fGaus1","gaus(0)+pol1(3)",xlow,xhigh,TF1::EAddToList::kNo), + fGaus2("fGaus2","gaus(0)+pol1(3)",xlow,xhigh,TF1::EAddToList::kNo){ + Clear(""); + if(xlow>xhigh) + std::swap(xlow,xhigh); + + if(cent1>cent2) + std::swap(cent1,cent2); + + TF1::SetRange(xlow,xhigh); + + fBGFit.SetNpx(1000); + fBGFit.SetLineStyle(2); + fBGFit.SetLineColor(kBlack); + + // Changing the name here causes an infinite loop when starting the FitEditor + //SetName(Form("gaus_%d_to_%d",(Int_t)(xlow),(Int_t)(xhigh))); + InitNames(); + //TF1::SetParameter("centroid",cent); + +} + + + +GDoubleGaus::GDoubleGaus() + : TF1("gausbg",GRootFunctions::DoubleGaus,0,1000,7,1,TF1::EAddToList::kNo), + fBGFit("background","pol1",0,1000) { + + Clear(); + InitNames(); + fBGFit.SetNpx(1000); + fBGFit.SetLineStyle(2); + fBGFit.SetLineColor(kBlack); +} + +GDoubleGaus::GDoubleGaus(const GDoubleGaus &peak) + : TF1(peak) { + peak.Copy(*this); +} + +GDoubleGaus::~GDoubleGaus() { + //if(background) + // delete background; +} + +void GDoubleGaus::InitNames(){ + TF1::SetParName(0,"height1"); + TF1::SetParName(1,"centroid1"); + TF1::SetParName(2,"height2"); + TF1::SetParName(3,"centroid2"); + TF1::SetParName(4,"sigma"); + TF1::SetParName(5,"bg_offset"); + TF1::SetParName(6,"bg_slope"); +} + +void GDoubleGaus::Copy(TObject &obj) const { + + TF1::Copy(obj); + ((GDoubleGaus&)obj).init_flag = init_flag; + ((GDoubleGaus&)obj).fAreaTotal = fAreaTotal; + ((GDoubleGaus&)obj).fDAreaTotal = fDAreaTotal; + ((GDoubleGaus&)obj).fArea1 = fArea1; + ((GDoubleGaus&)obj).fDArea1 = fDArea1; + ((GDoubleGaus&)obj).fArea2 = fArea2; + ((GDoubleGaus&)obj).fDArea2 = fDArea2; + + ((GDoubleGaus&)obj).fSumTotal = fSumTotal; + ((GDoubleGaus&)obj).fDSumTotal = fDSumTotal; + ((GDoubleGaus&)obj).fSum1 = fSum1; + ((GDoubleGaus&)obj).fDSum1 = fDSum1; + ((GDoubleGaus&)obj).fSum2 = fSum2; + ((GDoubleGaus&)obj).fDSum2 = fDSum2; + + ((GDoubleGaus&)obj).fChi2 = fChi2; + ((GDoubleGaus&)obj).fNdf = fNdf; + + fBGFit.Copy((((GDoubleGaus&)obj).fBGFit)); +} + +bool GDoubleGaus::InitParams(TH1 *fithist,double cent1, double cent2){ + if(!fithist){ + printf("No histogram is associated yet, no initial guesses made\n"); + return false; + } + //printf("%s called.\n",__PRETTY_FUNCTION__); fflush(stdout); + //Makes initial guesses at parameters for the fit. Uses the histogram to + Double_t xlow,xhigh; + GetRange(xlow,xhigh); + + Int_t binlow = fithist->GetXaxis()->FindBin(xlow); + Int_t binhigh = fithist->GetXaxis()->FindBin(xhigh); +/* + Double_t highy = fithist->GetBinContent(binlow); + Double_t lowy = fithist->GetBinContent(binhigh); + for(int x=1;x<5;x++) { + highy += fithist->GetBinContent(binlow-x); + lowy += fithist->GetBinContent(binhigh+x); + } + highy = highy/5.0; + lowy = lowy/5.0; + + if(lowy>highy) + std::swap(lowy,highy); +*/ + double largestx=0.0; + double largesty=0.0; + int i = binlow; + for(;i<=binhigh;i++) { + if(fithist->GetBinContent(i) > largesty) { + largesty = fithist->GetBinContent(i); + largestx = fithist->GetXaxis()->GetBinCenter(i); + } + } + + // - par[0]: height of peak1 + // - par[1]: cent of peak1 + // - par[2]: height of peak2 + // - par[3]: cent of peak2 + // - par[4]: shared sigma + // - par[5]: bg offset + // - par[6]: bg slope + + //limits. + TF1::SetParLimits(0,0,largesty*2); + TF1::SetParLimits(1,xlow,cent2); + TF1::SetParLimits(2,0,largesty*2); + TF1::SetParLimits(3,cent1,xhigh); + TF1::SetParLimits(4,0,xhigh-xlow); + + //TF1::SetParLimits(3,0.0,40); + //TF1::SetParLimits(4,0.01,5); + + //Make initial guesses + TF1::SetParameter(0,largesty); //fithist->GetBinContent(bin)); + TF1::SetParameter(1,cent1); //fithist->GetBinContent(bin)); + TF1::SetParameter(2,largesty); //fithist->GetBinContent(bin)); + TF1::SetParameter(3,cent2); //fithist->GetBinContent(bin)); + TF1::SetParameter(2,(largestx*.01)/2.35); //2,(xhigh-xlow)); //2.0/binWidth); // + + + TF1::SetParError(0,0.10 * largesty); + TF1::SetParError(1,0.25); + + TF1::SetParError(2,0.10 * largesty); + TF1::SetParError(3,0.25); + + TF1::SetParError(4,0.10 *((largestx*.01)/2.35)); + + SetInitialized(); + return true; +} + + +Bool_t GDoubleGaus::Fit(TH1 *fithist,double cent1,double cent2,Option_t *opt) { + if(!fithist) + return false; + TString options = opt; + if(!IsInitialized()) + InitParams(fithist,cent1,cent2); + TVirtualFitter::SetMaxIterations(100000); + + bool verbose = !options.Contains("Q"); + bool noprint = options.Contains("no-print"); + if(noprint) { + options.ReplaceAll("no-print",""); + } + + + if(fithist->GetSumw2()->fN!=fithist->GetNbinsX()+2) + fithist->Sumw2(); + + TFitResultPtr fitres = fithist->Fit(this,Form("%sRSME",options.Data())); + + //fitres.Get()->Print(); + if(!fitres.Get()->IsValid()) { + if(!verbose) + printf(RED "fit has failed, trying refit... " RESET_COLOR); + //SetParameter(3,0.1); + //SetParameter(4,0.01); + //SetParameter(5,0.0); + fithist->GetListOfFunctions()->Last()->Delete(); + fitres = fithist->Fit(this,Form("%sRSME",options.Data())); //,Form("%sRSM",options.Data())) + if( fitres.Get()->IsValid() ) { + if(!verbose && !noprint) + printf(DGREEN " refit passed!" RESET_COLOR "\n"); + } else { + if(!verbose && !noprint) + printf(DRED " refit also failed :( " RESET_COLOR "\n"); + } + } + + Double_t xlow,xhigh; + TF1::GetRange(xlow,xhigh); + + + double bgpars[2]; + bgpars[0] = TF1::GetParameters()[5]; + bgpars[1] = TF1::GetParameters()[6]; + //bgpars[5] = TF1::GetParameters()[7]; + + fBGFit.SetParameters(bgpars); + //fithist->GetListOfFunctions()->Print(); + + double gaus1pars[5]; + gaus1pars[0] = TF1::GetParameters()[0]; + gaus1pars[1] = TF1::GetParameters()[1]; + gaus1pars[2] = TF1::GetParameters()[4]; + gaus1pars[3] = TF1::GetParameters()[5]; + gaus1pars[4] = TF1::GetParameters()[6]; + fGaus1.SetParameters(gaus1pars); + fGaus1.SetLineColor(kBlue); + + double gaus2pars[5]; + gaus2pars[0] = TF1::GetParameters()[2]; + gaus2pars[1] = TF1::GetParameters()[3]; + gaus2pars[2] = TF1::GetParameters()[4]; + gaus2pars[3] = TF1::GetParameters()[5]; + gaus2pars[4] = TF1::GetParameters()[6]; + fGaus2.SetParameters(gaus2pars); + fGaus2.SetLineColor(kGreen); + + + fAreaTotal = this->Integral(xlow,xhigh) / fithist->GetBinWidth(1); + double bgArea = fBGFit.Integral(xlow,xhigh) / fithist->GetBinWidth(1);; + fAreaTotal -= bgArea; + + if(xlow>xhigh) + std::swap(xlow,xhigh); + fSumTotal = fithist->Integral(fithist->GetXaxis()->FindBin(xlow), + fithist->GetXaxis()->FindBin(xhigh)); //* fithist->GetBinWidth(1); + printf("sum between markers: %02f\n",fSumTotal); + fDSumTotal = TMath::Sqrt(fSumTotal); + fSumTotal -= bgArea; + printf("sum after subtraction: %02f\n",fSumTotal); + + if(!verbose && !noprint) { + printf("hist: %s\n",fithist->GetName()); + Print();/* + printf("BG Area: %.02f\n",bgArea); + printf("GetChisquared(): %.4f\n", TF1::GetChisquare()); + printf("GetNDF(): %i\n", TF1::GetNDF()); + printf("GetProb(): %.4f\n", TF1::GetProb());*/ + //TF1::Print(); + } + + Copy(*fithist->GetListOfFunctions()->FindObject(GetName())); + fithist->GetListOfFunctions()->Add(fBGFit.Clone()); + fithist->GetListOfFunctions()->Add(fGaus1.Clone()); + fithist->GetListOfFunctions()->Add(fGaus2.Clone()); + + + + + + //delete tmppeak; + return true; +} + + +void GDoubleGaus::Clear(Option_t *opt){ + TString options = opt; + //Clear the GDoubleGaus including functions and histogram + if(options.Contains("all")) + TF1::Clear(); + init_flag = false; + fAreaTotal = 0.0; + fDAreaTotal = 0.0; + fSumTotal = 0.0; + fDSumTotal = 0.0; + fChi2 = 0.0; + fNdf = 0.0; +} + +void GDoubleGaus::Print(Option_t *opt) const { + TString options = opt; + printf(GREEN ); + printf("Name: %s \n", this->GetName()); + printf("Centroid1: %1f +/- %1f \n", this->GetParameter("centroid1"),this->GetParError(GetParNumber("centroid1"))); + printf("Centroid2: %1f +/- %1f \n", this->GetParameter("centroid2"),this->GetParError(GetParNumber("centroid2"))); + printf("AreaTotal: %1f +/- %1f \n", fAreaTotal, fDAreaTotal); + printf("SumTotal: %1f +/- %1f \n", fSumTotal, fDSumTotal); + printf("FWHM: %1f +/- %1f \n",this->GetFWHM(),this->GetFWHMErr()); + printf("Reso: %1f%% \n",this->GetFWHM()/this->GetParameter("centroid")*100.); + printf("Chi^2/NDF: %1f\n",fChi2/fNdf); + if(options.Contains("all")){ + TF1::Print(opt); + } + printf(RESET_COLOR); + printf("\n"); +} + + +void GDoubleGaus::DrawResiduals(TH1 *hist) const{ + if(hist){ + return; + } + if(fChi2<0.000000001){ + printf("No fit performed\n"); + return; + } + Double_t xlow,xhigh; + GetRange(xlow,xhigh); + Int_t nbins = hist->GetXaxis()->GetNbins(); + Double_t *res = new Double_t[nbins]; + Double_t *bin = new Double_t[nbins]; + Int_t points = 0; + for(int i =1;i<=nbins;i++) { + if(hist->GetBinCenter(i) <= xlow || hist->GetBinCenter(i) >= xhigh) + continue; + res[points] = (hist->GetBinContent(i) - this->Eval(hist->GetBinCenter(i)))+ this->GetParameter("Height")/2; + bin[points] = hist->GetBinCenter(i); + points++; + } + new GCanvas(); + TGraph *residuals = new TGraph(points,bin,res); + residuals->Draw("*AC"); + delete[] res; + delete[] bin; +} diff --git a/libraries/GROOT/GGaus.cxx b/libraries/GROOT/GGaus.cxx index 29d8297a..567addd9 100644 --- a/libraries/GROOT/GGaus.cxx +++ b/libraries/GROOT/GGaus.cxx @@ -4,7 +4,7 @@ #include #include #include - +#include #include "Globals.h" #include "GRootFunctions.h" @@ -13,8 +13,8 @@ ClassImp(GGaus) GGaus::GGaus(Double_t xlow,Double_t xhigh,Option_t *opt) - : TF1("gausbg","gaus(0)+pol1(3)",xlow,xhigh), - fBGFit("background","pol1",xlow,xhigh) { + : TF1("gausbg","gaus(0)+pol1(3)",xlow,xhigh,TF1::EAddToList::kNo), + fBGFit("background","pol1",xlow,xhigh,TF1::EAddToList::kNo) { Clear(""); if(xlow>xhigh) std::swap(xlow,xhigh); @@ -43,7 +43,7 @@ GGaus::GGaus(Double_t xlow,Double_t xhigh,TF1 *bg,Option_t *opt) InitNames(); if(bg) { - fBGFit.Clear(); + fBGFit.Clear(); fBGFit.Copy(*bg); } else { fBGFit = TF1("BGFit","pol1",xlow,xhigh); @@ -77,7 +77,7 @@ GGaus::~GGaus() { } //void GGaus::Fcn(Int_t &npar,Double_t *gin,Double_T &f,Double_t *par,Int_t iflag) { - //chisquared calculator + //chisquared calculator // // int i=0; // double chisq = 0; @@ -155,24 +155,24 @@ bool GGaus::InitParams(TH1 *fithist){ // - par[2]: sigma // - par[3]: bg constent // - par[4]: bg slope - - //limits. + + //limits. TF1::SetParLimits(0,0,largesty*2); TF1::SetParLimits(1,xlow,xhigh); TF1::SetParLimits(2,0,xhigh-xlow); //TF1::SetParLimits(3,0.0,40); - //TF1::SetParLimits(4,0.01,5); + //TF1::SetParLimits(4,0.01,5); //Make initial guesses TF1::SetParameter(0,largesty); //fithist->GetBinContent(bin)); TF1::SetParameter(1,largestx); //GetParameter("centroid")); - TF1::SetParameter(2,(largestx*.01)/2.35); //2,(xhigh-xlow)); //2.0/binWidth); // + TF1::SetParameter(2,largestx*.01/2.35); //2,(xhigh-xlow)); //2.0/binWidth); // //TF1::SetParameter(3,5.); //TF1::SetParameter(4,1.); - TF1::SetParError(0,0.10 * largesty); - TF1::SetParError(1,0.25); - TF1::SetParError(2,0.10 *((largestx*.01)/2.35)); +// TF1::SetParError(0,0.10 * largesty); +// TF1::SetParError(1,0.25); + //TF1::SetParError(2,0.10 *((largestx*.01)/2.35)); //TF1::SetParError(3,5); //TF1::SetParError(4,0.5); @@ -196,11 +196,12 @@ Bool_t GGaus::Fit(TH1 *fithist,Option_t *opt) { if(noprint) { options.ReplaceAll("no-print",""); } - - if(fithist->GetSumw2()->fN!=fithist->GetNbinsX()+2) + + if(fithist->GetSumw2()->fN!=fithist->GetNbinsX()+2) fithist->Sumw2(); +// TFitResultPtr fitres = fithist->Fit(this,Form("%sRSME",options.Data())); TFitResultPtr fitres = fithist->Fit(this,Form("%sRSME",options.Data())); //fitres.Get()->Print(); @@ -246,7 +247,7 @@ Bool_t GGaus::Fit(TH1 *fithist,Option_t *opt) { //Intgrate the background. //GGaus *tmppeak = new GGaus; //this->Copy(*tmppeak); - + //tmppeak->SetParameter("bg_offset",0.0); //tmppeak->SetRange(int_low,int_high);//This will help get the true area of the gaussian 200 ~ infinity in a gaus //tmppeak->SetName("tmppeak"); @@ -303,7 +304,7 @@ Bool_t GGaus::Fit(TH1 *fithist,Option_t *opt) { printf("GetProb(): %.4f\n", TF1::GetProb());*/ //TF1::Print(); } - + Copy(*fithist->GetListOfFunctions()->FindObject(GetName())); fithist->GetListOfFunctions()->Add(fBGFit.Clone()); diff --git a/libraries/GROOT/GGraph2D.cxx b/libraries/GROOT/GGraph2D.cxx new file mode 100644 index 00000000..3fe4ee10 --- /dev/null +++ b/libraries/GROOT/GGraph2D.cxx @@ -0,0 +1,106 @@ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +GGraph2D::GGraph2D(const char *filename,Option_t *opt) { + SetNameTitle("GGraph2D",filename); + + SetLineColor(1); + SetLineStyle(1); + SetLineWidth(1); + + SetFillColor(1); + SetFillStyle(1001); + + std::vector vx,vy,vz,vdx,vdy,vdz; + std::vector values; + values.reserve(6); + std::ifstream infile(filename); + if(!infile.is_open()) { + MakeZombie(); + fprintf(stderr,"failed to open, %s! I am now a zombie... mmmmm brains.",filename); + } + std::string line; + while(getline(infile,line)) { + if(!line.length()) + break; + std::stringstream ss(line); + std::string buffer; + int count=0; + int nps=0; + std::fill(values.begin(),values.end(),0.00); + while(ss>>buffer) { + std::stringstream(buffer)>>values[count++];; + } + SetPoint(nps,values.at(0),values.at(1),values.at(2)); + SetPointError(nps,values.at(5),values.at(4),values.at(3)); + nps++; + } + +} + + +GGraph *GGraph2D::ProjectionX(double low, double high,Option_t *opt) const { + if(low>high) std::swap(low,high); + TString sopt = opt; + sopt.ToLower(); + std::vector x; + std::vector dx; + std::vector z; + std::vector dz; + for(int i=0;i=low) && ((*(GetY()+i))<=high) ) { + x.push_back(*(GetX()+i)); + z.push_back(*(GetZ()+i)); + dx.push_back(*(GetEX()+i)); + dz.push_back(*(GetEZ()+i)); + } + } + + GGraph *gr = new GGraph(x.size(),&(x[0]),&(z[0]),&(dz[0]),&(dx[0])); + gr->SetNameTitle(Form("%s_projX",GetName()),Form("projX %.02f - %.02f",low,high)); + if(sopt.Contains("draw")) { + new GCanvas; + gr->Draw("AP"); + if(GetXaxis()) { gr->GetXaxis()->SetTitle(GetXaxis()->GetTitle()); } + } + return gr; +} + +GGraph *GGraph2D::ProjectionY(double low, double high,Option_t *opt) const { + if(low>high) std::swap(low,high); + TString sopt = opt; + sopt.ToLower(); + std::vector y; + std::vector dy; + std::vector z; + std::vector dz; + for(int i=0;i=low) && ((*(GetX()+i))<=high) ) { + y.push_back(*(GetY()+i)); + z.push_back(*(GetZ()+i)); + dy.push_back(*(GetEY()+i)); + dz.push_back(*(GetEZ()+i)); + } + } + + GGraph *gr = new GGraph(y.size(),&(y[0]),&(z[0]),&(dz[0]),&(dy[0])); + gr->SetNameTitle(Form("%s_projY",GetName()),Form("projY %.02f - %.02f",low,high)); + if(sopt.Contains("draw")) { + new GCanvas; + gr->Draw("AP"); + if(GetXaxis()) { gr->GetXaxis()->SetTitle(GetXaxis()->GetTitle()); } + } + return gr; +} + + diff --git a/libraries/GROOT/GH1.cxx b/libraries/GROOT/GH1.cxx new file mode 100644 index 00000000..b5a54576 --- /dev/null +++ b/libraries/GROOT/GH1.cxx @@ -0,0 +1,152 @@ + + +#include +#include + +#include +#include +//#include + + +GH1D *GH1::Project(int low,int high) { + if(!GetHistParent() || !GetHistParent()->InheritsFrom(GH2::Class())) + return 0; + GH2 *p = (GH2*)GetHistParent(); + if(fProjectionAxis==kNoAxis) + return 0; + switch(fProjectionAxis) { + case kXaxis: + return p->ProjectionY("_py",low,high,"keep+"); + case kYaxis: + return p->ProjectionX("_px",low,high,"keep+"); + }; + return 0; +} + +GH1D *GH1::Project(int low,int high,int bg_low,int bg_high,double scale) { + if(!GetHistParent() || !GetHistParent()->InheritsFrom(GH2::Class())) + return 0; + GH2 *p = (GH2*)GetHistParent(); + if(fProjectionAxis==kNoAxis) + return 0; + switch(fProjectionAxis) { + case kXaxis: + return p->ProjectionY_BG("_bg_py",low,high,bg_low,bg_high,scale,"keep+"); + case kYaxis: + return p->ProjectionX_BG("_bg_px",low,high,bg_low,bg_high,scale,"keep+"); + }; + return 0; +} + + + + + +double GH1::FitEval(double *dim,double *par) { + + double x = dim[0]; + //printf("par = 0x%08x\n",par); fflush(stdout); + double scale = par[0]; + + int binNum = GetXaxis()->FindBin(x); //gHist->GetBin() does not respect rebinning. + + int nBins = GetNbinsX(); + int kevPerBin = GetXaxis()->GetXmax()/nBins; + int curBinX = GetBinCenter(binNum); + int nextBinX = GetBinCenter(binNum+1); + int prevBinX = GetBinCenter(binNum-1); + + if (x > prevBinX && x <= curBinX){ + double leftDiff = x - prevBinX; + double rightDiff = curBinX - x; + + leftDiff = 1.0 - leftDiff/(double)kevPerBin; //These numbers are now less than 1 + rightDiff = 1.0 - rightDiff/(double)kevPerBin; //and a measure of how close it is to that bin + double binContentLeft = GetBinContent(binNum-1); + double binContentRight = GetBinContent(binNum); + return scale * (leftDiff*binContentLeft+rightDiff*binContentRight); + } + + else if (x > curBinX && x < nextBinX){ + double leftDiff = x - curBinX; + double rightDiff = nextBinX - x; + + leftDiff = 1.0 - leftDiff/(double)kevPerBin; + rightDiff = 1.0 - rightDiff/(double)kevPerBin; + double binContentLeft = GetBinContent(binNum); + double binContentRight = GetBinContent(binNum+1); + return scale * (leftDiff*binContentLeft+rightDiff*binContentRight); + } + //std::cout << "FAILED IN HISTVALUE!" << std::endl; + return scale * GetBinContent(binNum); +} + + +TF1 *GH1::ConstructTF1() const { + if(GetDimension()!=1) + return 0; + + ROOT::Math::ParamFunctor *f = new ROOT::Math::ParamFunctor((GH1*)this,&GH1::FitEval); + double low = GetXaxis()->GetBinLowEdge(1); + double high = GetXaxis()->GetBinUpEdge(GetXaxis()->GetNbins()); + + TF1 *tf1 = new TF1(Form("%s_tf1",GetName()),*f,low,high,1,1); + tf1->SetParameter(0,1.0); + tf1->SetNpx(GetXaxis()->GetNbins()); + return tf1; + +} + + +bool GH1::WriteDatFile(const char *outFile){ + if(strlen(outFile)<1) return 0; + + std::ofstream out; + out.open(outFile); + + if(!(out.is_open())) return 0; + + for(int i=0;iGetBinCenter(i) << "\t" << GetBinContent(i) << std::endl; + } + out << std::endl; + out.close(); + + return 1; +} + + + +void GH1::Draw(Option_t *opt) { + TString sopt = opt; + if(GetDimension()==2) { + if(sopt.Length()==0) + sopt="colz"; + } + TH1::Draw(sopt.Data()); + return; +} + + + +void GH1::Calibrate(double offset,double gain,int axis) { + if(this->GetDimension()!=1) { + printf("%s currently only works for 1d histograms.\n",__PRETTY_FUNCTION__); + } + double low = this->GetXaxis()->GetBinLowEdge(1)*gain + offset; + double high = this->GetXaxis()->GetBinUpEdge(this->GetNbinsX())*gain + offset; + + this->GetXaxis()->SetLimits(low,high); + + //for(int x=1;x<=this->GetNbinsX();x++) { + // this->GetXaxis()->SetBinLabel(x,Form("%g",(x-1)*gain + offset)); + //} + +} + + + + + + + diff --git a/libraries/GROOT/GH1D.cxx b/libraries/GROOT/GH1D.cxx index e67eb4c6..6983df71 100644 --- a/libraries/GROOT/GH1D.cxx +++ b/libraries/GROOT/GH1D.cxx @@ -1,278 +1,191 @@ -#include "GH1D.h" - -#include -#include -#include - -#include "TVirtualPad.h" -#include "TString.h" -#include "TF1.h" -#include "TFrame.h" -#include "TClass.h" -#include "TFunction.h" -#include "TMethodCall.h" -//#include "TROOT.h" -//#include "TSystem.h" - -#include "GCanvas.h" -#include "GH2I.h" -#include "GH2D.h" -#include "GRootCommands.h" - -GH1D::GH1D(const TH1& source) - : parent(NULL), projection_axis(-1),fFillClass(0),fFillMethod(0) { - source.Copy(*this); -} -GH1D::GH1D(const TF1& function,Int_t nbinsx,Double_t xlow,Double_t xup) : - TH1D(Form("%s_hist",function.GetName()),Form("%s_hist",function.GetName()),nbinsx, xlow, xup), parent(NULL), projection_axis(-1),fFillClass(0),fFillMethod(0) { +#include + +#include +#include - //TF1 *f = (TF1*)function.Clone(); - //f->SetRange(xlow,xup); +ClassImp(GH1D) - for(int i=1;i<=nbinsx;i++) { - double x = GetBinCenter(i); - Fill(x,function.Eval(x)); - } - //f->Delete(); +GH1D::GH1D(): GH1(),TArrayD() { + fDimension=1; + SetBinsLength(3); + if(GH1::fgDefaultSumw2) + Sumw2(); } -bool GH1D::WriteDatFile(const char *outFile){ - if(strlen(outFile)<1) return 0; - - std::ofstream out; - out.open(outFile); - - if(!(out.is_open())) return 0; - - for(int i=0;iGetBinCenter(i) << "\t" << GetBinContent(i) << std::endl; - } - out << std::endl; - out.close(); +GH1D::GH1D(const char *name,const char *title,int nbins,double xlow,double xhigh) : + GH1(name,title,nbins,xlow,xhigh) { + fDimension=1; + TArrayD::Set(fNcells); + if(GH1::fgDefaultSumw2) + Sumw2(); +} - return 1; -} +GH1D::GH1D(const char *name,const char *title,int nbins,const double *bins) : + GH1(name,title,nbins,bins) { + fDimension=1; + TArrayD::Set(fNcells); + if(GH1::fgDefaultSumw2) + Sumw2(); +} +GH1D::GH1D(const char *name,const char *title,int nbins,const float *bins) : + GH1(name,title,nbins,bins) { + fDimension=1; + TArrayD::Set(fNcells); + if(GH1::fgDefaultSumw2) + Sumw2(); +} -/* -GH1D::GH1D(const TH1 *source) - : parent(NULL), projection_axis(-1) { - if(source->GetDiminsion()>1) { - return; +GH1D::GH1D(const TVectorD &v): GH1("TVectorD","",v.GetNrows(),0,v.GetNrows()) { + TArrayD::Set(fNcells); + fDimension=1; + int ivlow=v.GetLwb(); + for(int i=0;iCopy(*this); - - // Force a refresh of any parameters stored in the option string. - SetOption(GetOption()); +GH1D::GH1D(const GH1D &h1d) : GH1(),TArrayD() { + ((GH1D&)h1d).Copy(*this); } -void GH1D::SetOption(Option_t* opt) { - fOption = opt; +GH1D::GH1D(const TH1 &h1d) : GH1(),TArrayD() { + //((GH1D&)h1d).Copy(*this); + ((TH1&)h1d).Copy(*this); +} - TString sopt = opt; - if(sopt.Index("axis:")) { - projection_axis = 0;// TODO - } +void GH1D::Copy(TObject &obj) const { + GH1::Copy(obj); } -*/ -void GH1D::Clear(Option_t* opt) { - TH1D::Clear(opt); - parent = NULL; +void GH1D::Reset(Option_t *opt) { + GH1::Reset(opt); + TArrayD::Reset(); } -void GH1D::Print(Option_t* opt) const { - TH1D::Print(opt); - std::cout << "\tParent: " << parent.GetObject() << std::endl; +void GH1D::SetBinsLength(int n) { + if(n<0) + n=fXaxis.GetNbins()+2; + fNcells = n; + TArrayD::Set(n); } -void GH1D::Copy(TObject& obj) const { - TH1D::Copy(obj); - ((GH1D&)obj).parent = parent; + +//void GH1D::Streamer(TBuffer &r__b) { +// unsigned int r__s,r__c; +// if(r__b.IsReading()) { +// Version_t r__v = r__b.ReadVersion(&r__s,&r__c); +// printf("I AM HEER; version = %i\n",r__v); +// printf("r__b.GetParent()->GetName() = %s\n",r__b.GetParent()->GetName()); +// if(r__v<3) { +// printf("I AM HEER; version = %i\n",r__v); +// TH1D h; +// r__b.ReadClassBuffer(TH1D::Class(),&h); +// h.Copy(*this); +// //printf("h->GetBinContent(80) = %.02f\n",h.GetBinContent(80) ); +// //h.DrawCopy(); +// //h.Streamer(r__b); +// //h.Copy(*this); +// } else { +// //r__b.ReadClassBuffer(GH1::Class(),this); +// r__b.ReadClassBuffer(GH1D::Class(),this); +// //GH1D::Class()->ReadBuffer(r__b, this); +// } +// } else { +// GH1::Class()->WriteBuffer(r__b,this); +// GH1D::Class()->WriteBuffer(r__b,this); +// } +//} + + + +GH1D &GH1D::operator=(const GH1D &h1) { + if(this!=&h1) ((TH1D&)h1).Copy(*this); + return *this; } +GH1D operator*(double c1,const GH1D &h1) { + GH1D hnew = h1; + hnew.Scale(c1); + hnew.SetDirectory(0); + return hnew; +} -void GH1D::Draw(Option_t* opt) { - TString option(opt); - if(option.Contains("new",TString::kIgnoreCase)) { - option.ReplaceAll("new",""); - new GCanvas; - } - TH1D::Draw(option.Data()); - if(gPad) { - gPad->Update(); - gPad->GetFrame()->SetBit(TBox::kCannotMove); - } +GH1D operator*(const GH1D &h1,const GH1D &h2) { + GH1D hnew = h1; + hnew.Multiply(&h2); + hnew.SetDirectory(0); + return hnew; } -TH1 *GH1D::DrawCopy(Option_t *opt) const { - TH1 *h = TH1D::DrawCopy(opt); - if(gPad) { - gPad->Update(); - gPad->GetFrame()->SetBit(TBox::kCannotMove); - } - return h; +GH1D operator/(const GH1D &h1,const GH1D &h2) { + GH1D hnew = h1; + hnew.Divide(&h2); + hnew.SetDirectory(0); + return hnew; +} + +GH1D operator+(const GH1D &h1,const GH1D &h2) { + GH1D hnew = h1; + hnew.Add(&h2); + hnew.SetDirectory(0); + return hnew; } -TH1 *GH1D::DrawNormalized(Option_t *opt,Double_t norm) const { - TH1 *h = TH1D::DrawNormalized(opt,norm); - if(gPad) { - gPad->Update(); - gPad->GetFrame()->SetBit(TBox::kCannotMove); - } - return h; +GH1D operator-(const GH1D &h1,const GH1D &h2) { + GH1D hnew = h1; + hnew.Add(&h2,-1); + hnew.SetDirectory(0); + return hnew; } -GH1D* GH1D::GetPrevious(bool DrawEmpty) const { - if(parent.GetObject() && parent.GetObject()->InheritsFrom(GH2Base::Class())) { - GH2D* gpar = (GH2D*)parent.GetObject(); - int first = GetXaxis()->GetFirst(); - int last = GetXaxis()->GetLast(); - GH1D *prev = gpar->GetPrevious(this,DrawEmpty); - prev->GetXaxis()->SetRange(first,last); - return prev; //gpar->GetPrevious(this,DrawEmpty); - } else { - return NULL; - } -} +//Int_t GH1D::Write(const char *name,Int_t option,Int_t bufsize) const { +// TH1D hist; + //hist.Copy(*this); +// this->Copy(hist); +// hist.SetNameTitle(this->GetName(),this->GetTitle()); +// return hist.Write(); +//} + + + + + + + + + + + + + + + + + + + -GH1D* GH1D::GetNext(bool DrawEmpty) const { - if(parent.GetObject() && parent.GetObject()->InheritsFrom(GH2Base::Class())) { - GH2D* gpar = (GH2D*)parent.GetObject(); - int first = GetXaxis()->GetFirst(); - int last = GetXaxis()->GetLast(); - GH1D *next = gpar->GetNext(this,DrawEmpty); - next->GetXaxis()->SetRange(first,last); - return next; //gpar->GetNext(this,DrawEmpty); - } else { - return NULL; - } -} -GH1D* GH1D::Project(double value_low, double value_high) const { - - if(parent.GetObject() && parent.GetObject()->InheritsFrom(GH2Base::Class()) && - projection_axis!=-1) { - if(value_low > value_high){ - std::swap(value_low, value_high); - } - GH2D* gpar = (GH2D*)parent.GetObject(); - if(projection_axis == 0){ - int bin_low = gpar->GetXaxis()->FindBin(value_low); - int bin_high = gpar->GetXaxis()->FindBin(value_high); - return gpar->ProjectionY("_py", bin_low, bin_high); - } else { - int bin_low = gpar->GetYaxis()->FindBin(value_low); - int bin_high = gpar->GetYaxis()->FindBin(value_high); - return gpar->ProjectionX("_px", bin_low, bin_high); - } - } else { - return NULL; - } -} -GH1D* GH1D::Project_Background(double value_low, double value_high, - double bg_value_low, double bg_value_high, - kBackgroundSubtraction mode) const { - if(parent.GetObject() && parent.GetObject()->InheritsFrom(GH2Base::Class()) && - projection_axis!=-1) { - if(value_low > value_high){ - std::swap(value_low, value_high); - } - if(bg_value_low > bg_value_high){ - std::swap(bg_value_low, bg_value_high); - } - - GH2D* gpar = (GH2D*)parent.GetObject(); - if(projection_axis == 0){ - int bin_low = gpar->GetXaxis()->FindBin(value_low); - int bin_high = gpar->GetXaxis()->FindBin(value_high); - int bg_bin_low = gpar->GetXaxis()->FindBin(bg_value_low); - int bg_bin_high = gpar->GetXaxis()->FindBin(bg_value_high); - - return gpar->ProjectionY_Background(bin_low, bin_high, - bg_bin_low, bg_bin_high, - mode); - } else { - int bin_low = gpar->GetYaxis()->FindBin(value_low); - int bin_high = gpar->GetYaxis()->FindBin(value_high); - int bg_bin_low = gpar->GetYaxis()->FindBin(bg_value_low); - int bg_bin_high = gpar->GetYaxis()->FindBin(bg_value_high); - - return gpar->ProjectionX_Background(bin_low, bin_high, - bg_bin_low, bg_bin_high, - mode); - } - } else { - return NULL; - } -} -GH1D *GH1D::Project(int bins) { - GH1D *proj = 0; - double ymax = GetMinimum(); - double ymin = GetMaximum(); - if(bins==-1) { - bins = abs(ymax-ymin); - if(bins<1) - bins=100; - } - proj = new GH1D(Form("%s_y_axis_projection",GetName()), - Form("%s_y_axis_projection",GetName()), - bins,ymin,ymax); - for(int x=0;xFill(GetBinContent(x)); - } - return proj; -} -void GH1D::SetFillMethod(const char *classname,const char *methodname,const char *param) { - fFillClass = TClass::GetClass(classname); - if(!fFillClass) - return; - fFillMethod = new TMethodCall(fFillClass,methodname,param); - //printf("class: %s\n",fFillClass->GetName()); - //printf("method: %s\n",fFillMethod->GetMethod()->GetPrototype()); -} -Int_t GH1D::Fill(const TObject* obj) { - if(!fFillClass || !fFillMethod) { - //printf("%p \t %p\n",fFillClass,fFillMethod); - return -1; - } - if(obj->IsA()!=fFillClass) { - //printf("%s \t %s\n", obj->Class()->GetName(),fFillClass->GetName()); - return -2; - } - Double_t storage; - fFillMethod->Execute((void*)(obj),storage); - return Fill(storage); -} -GPeak* GH1D::DoPhotoPeakFit(double xlow,double xhigh,Option_t *opt) { - xl_last = xlow; - xh_last = xhigh; - return PhotoPeakFit((TH1*)this,xlow,xhigh,opt); -} -GPeak* GH1D::DoPhotoPeakFitNormBG(double xlow,double xhigh,Option_t *opt) { - xl_last = xlow; - xh_last = xhigh; - return PhotoPeakFitNormBG((TH1*)this,xlow,xhigh,opt); -} diff --git a/libraries/GROOT/GH2.cxx b/libraries/GROOT/GH2.cxx new file mode 100644 index 00000000..e92c8103 --- /dev/null +++ b/libraries/GROOT/GH2.cxx @@ -0,0 +1,3122 @@ +// +// re-implementation of the classic TH2, largely copied form: +// +// // Author: Rene Brun 26/12/94 +// /************************************************************************* +// * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * +// * All rights reserved. * +// * * +// * For the licensing terms see $ROOTSYS/LICENSE. * +// * For the list of contributors see $ROOTSYS/README/CREDITS. * +// *************************************************************************/ +// +// +// +// +// +// +// +// +// +// + + +#include +#include +#include +#include + +#include "TROOT.h" +#include "TVirtualPad.h" +#include "TClass.h" +#include "THashList.h" + +#include "TF2.h" +#include "TProfile.h" + +#include "TRandom.h" +#include "THLimitsFinder.h" +#include "TMath.h" +#include "TVirtualHistPainter.h" + + + +ClassImp(GH2) + +GH2::GH2() { + fDimension = 2; + fScalefactor = 1; + fTsumwy = fTsumwy2 = fTsumwxy = 0; +} + + +GH2::GH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup + ,Int_t nbinsy,Double_t ylow,Double_t yup) + :GH1(name,title,nbinsx,xlow,xup) { + fDimension = 2; + fScalefactor = 1; + fTsumwy = fTsumwy2 = fTsumwxy = 0; + if (nbinsy <= 0) {Warning("GH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; } + fYaxis.Set(nbinsy,ylow,yup); + fNcells = fNcells*(nbinsy+2); // fNCells is set in the GH1 constructor +} + + +GH2::GH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins + ,Int_t nbinsy,Double_t ylow,Double_t yup) + :GH1(name,title,nbinsx,xbins) { + fDimension = 2; + fScalefactor = 1; + fTsumwy = fTsumwy2 = fTsumwxy = 0; + if (nbinsy <= 0) {Warning("GH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; } + fYaxis.Set(nbinsy,ylow,yup); + fNcells = fNcells*(nbinsy+2); // fNCells is set in the GH1 constructor +} + + +GH2::GH2(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup + ,Int_t nbinsy,const Double_t *ybins) + :GH1(name,title,nbinsx,xlow,xup) { + fDimension = 2; + fScalefactor = 1; + fTsumwy = fTsumwy2 = fTsumwxy = 0; + if (nbinsy <= 0) {Warning("GH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; } + if (ybins) fYaxis.Set(nbinsy,ybins); + else fYaxis.Set(nbinsy,0,1); + fNcells = fNcells*(nbinsy+2); // fNCells is set in the GH1 constructor +} + +GH2::GH2(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins + ,Int_t nbinsy,const Double_t *ybins) + :GH1(name,title,nbinsx,xbins) { + fDimension = 2; + fScalefactor = 1; + fTsumwy = fTsumwy2 = fTsumwxy = 0; + if (nbinsy <= 0) {Warning("GH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; } + if (ybins) fYaxis.Set(nbinsy,ybins); + else fYaxis.Set(nbinsy,0,1); + fNcells = fNcells*(nbinsy+2); // fNCells is set in the GH1 constructor +} + +GH2::GH2(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins + ,Int_t nbinsy,const Float_t *ybins) + :GH1(name,title,nbinsx,xbins) { + fDimension = 2; + fScalefactor = 1; + fTsumwy = fTsumwy2 = fTsumwxy = 0; + if (nbinsy <= 0) {Warning("GH2","nbinsy is <=0 - set to nbinsy = 1"); nbinsy = 1; } + if (ybins) fYaxis.Set(nbinsy,ybins); + else fYaxis.Set(nbinsy,0,1); + fNcells = fNcells*(nbinsy+2); // fNCells is set in the GH1 constructor. +} + + +GH2::GH2(const GH2 &h) : GH1() +{ + ((GH2&)h).Copy(*this); +} + + +GH2::~GH2() +{ +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Fill histogram with all entries in the buffer. +/// action = -1 histogram is reset and refilled from the buffer (called by THistPainter::Paint) +/// action = 0 histogram is filled from the buffer +/// action = 1 histogram is filled and buffer is deleted +/// The buffer is automatically deleted when the number of entries +/// in the buffer is greater than the number of entries in the histogram + +Int_t GH2::BufferEmpty(Int_t action) +{ + // do we need to compute the bin size? + if (!fBuffer) return 0; + Int_t nbentries = (Int_t)fBuffer[0]; + + // nbentries correspond to the number of entries of histogram + + if (nbentries == 0) return 0; + if (nbentries < 0 && action == 0) return 0; // case histogram has been already filled from the buffer + + Double_t *buffer = fBuffer; + if (nbentries < 0) { + nbentries = -nbentries; + // a reset might call BufferEmpty() giving an infinite loop + // Protect it by setting fBuffer = 0 + fBuffer=0; + //do not reset the list of functions + Reset("ICES"); + fBuffer = buffer; + } + + if (CanExtendAllAxes() || fXaxis.GetXmax() <= fXaxis.GetXmin() || fYaxis.GetXmax() <= fYaxis.GetXmin()) { + //find min, max of entries in buffer + Double_t xmin = fBuffer[2]; + Double_t xmax = xmin; + Double_t ymin = fBuffer[3]; + Double_t ymax = ymin; + for (Int_t i=1;i xmax) xmax = x; + Double_t y = fBuffer[3*i+3]; + if (y < ymin) ymin = y; + if (y > ymax) ymax = y; + } + if (fXaxis.GetXmax() <= fXaxis.GetXmin() || fYaxis.GetXmax() <= fYaxis.GetXmin()) { + THLimitsFinder::GetLimitsFinder()->FindGoodLimits(this,xmin,xmax,ymin,ymax); + } else { + fBuffer = 0; + Int_t keep = fBufferSize; fBufferSize = 0; + if (xmin < fXaxis.GetXmin()) ExtendAxis(xmin,&fXaxis); + if (xmax >= fXaxis.GetXmax()) ExtendAxis(xmax,&fXaxis); + if (ymin < fYaxis.GetXmin()) ExtendAxis(ymin,&fYaxis); + if (ymax >= fYaxis.GetXmax()) ExtendAxis(ymax,&fYaxis); + fBuffer = buffer; + fBufferSize = keep; + } + } + + fBuffer = 0; + for (Int_t i=0;i 0) { delete [] fBuffer; fBuffer = 0; fBufferSize = 0;} + else { + if (nbentries == (Int_t)fEntries) fBuffer[0] = -nbentries; + else fBuffer[0] = 0; + } + return nbentries; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// accumulate arguments in buffer. When buffer is full, empty the buffer +/// fBuffer[0] = number of entries in buffer +/// fBuffer[1] = w of first entry +/// fBuffer[2] = x of first entry +/// fBuffer[3] = y of first entry + +Int_t GH2::BufferFill(Double_t x, Double_t y, Double_t w) +{ + if (!fBuffer) return -3; + Int_t nbentries = (Int_t)fBuffer[0]; + if (nbentries < 0) { + nbentries = -nbentries; + fBuffer[0] = nbentries; + if (fEntries > 0) { + Double_t *buffer = fBuffer; fBuffer=0; + Reset("ICES"); + fBuffer = buffer; + } + } + if (3*nbentries+3 >= fBufferSize) { + BufferEmpty(1); + return Fill(x,y,w); + } + fBuffer[3*nbentries+1] = w; + fBuffer[3*nbentries+2] = x; + fBuffer[3*nbentries+3] = y; + fBuffer[0] += 1; + return -3; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Copy. + +void GH2::Copy(TObject &obj) const +{ + GH1::Copy(obj); + ((GH2&)obj).fDimension = fDimension; + ((GH2&)obj).fScalefactor = fScalefactor; + ((GH2&)obj).fTsumwy = fTsumwy; + ((GH2&)obj).fTsumwy2 = fTsumwy2; + ((GH2&)obj).fTsumwxy = fTsumwxy; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Invalid Fill method. + +Int_t GH2::Fill(Double_t ) +{ + Error("Fill", "Invalid signature - do nothing"); + return -1; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Increment cell defined by x,y by 1. +/// +/// if x or/and y is less than the low-edge of the corresponding axis first bin, +/// the Underflow cell is incremented. +/// if x or/and y is greater than the upper edge of corresponding axis last bin, +/// the Overflow cell is incremented. +/// +/// If the storage of the sum of squares of weights has been triggered, +/// via the function Sumw2, then the sum of the squares of weights is incremented +/// by 1 in the cell corresponding to x,y. +/// +/// The function returns the corresponding global bin number which has its content +/// incremented by 1 + +Int_t GH2::Fill(Double_t x,Double_t y) +{ + if (fBuffer) return BufferFill(x,y,1); + + Int_t binx, biny, bin; + fEntries++; + binx = fXaxis.FindBin(x); + biny = fYaxis.FindBin(y); + if (binx <0 || biny <0) return -1; + bin = biny*(fXaxis.GetNbins()+2) + binx; + AddBinContent(bin); + if (fSumw2.fN) ++fSumw2.fArray[bin]; + if (binx == 0 || binx > fXaxis.GetNbins()) { + if (!fgStatOverflows) return -1; + } + if (biny == 0 || biny > fYaxis.GetNbins()) { + if (!fgStatOverflows) return -1; + } + ++fTsumw; + ++fTsumw2; + fTsumwx += x; + fTsumwx2 += x*x; + fTsumwy += y; + fTsumwy2 += y*y; + fTsumwxy += x*y; + return bin; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Increment cell defined by x,y by a weight w. +/// +/// if x or/and y is less than the low-edge of the corresponding axis first bin, +/// the Underflow cell is incremented. +/// if x or/and y is greater than the upper edge of corresponding axis last bin, +/// the Overflow cell is incremented. +/// +/// If the weight is not equal to 1, the storage of the sum of squares of +/// weights is automatically triggered and the sum of the squares of weights is incremented +/// by w^2 in the bin corresponding to x,y +/// +/// The function returns the corresponding global bin number which has its content +/// incremented by w + +Int_t GH2::Fill(Double_t x, Double_t y, Double_t w) +{ + if (fBuffer) return BufferFill(x,y,w); + + Int_t binx, biny, bin; + fEntries++; + binx = fXaxis.FindBin(x); + biny = fYaxis.FindBin(y); + if (binx <0 || biny <0) return -1; + bin = biny*(fXaxis.GetNbins()+2) + binx; + if (!fSumw2.fN && w != 1.0 && !TestBit(GH1::kIsNotW)) Sumw2(); // must be called before AddBinContent + if (fSumw2.fN) fSumw2.fArray[bin] += w*w; + AddBinContent(bin,w); + if (binx == 0 || binx > fXaxis.GetNbins()) { + if (!fgStatOverflows) return -1; + } + if (biny == 0 || biny > fYaxis.GetNbins()) { + if (!fgStatOverflows) return -1; + } + Double_t z= w; + fTsumw += z; + fTsumw2 += z*z; + fTsumwx += z*x; + fTsumwx2 += z*x*x; + fTsumwy += z*y; + fTsumwy2 += z*y*y; + fTsumwxy += z*x*y; + return bin; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Increment cell defined by namex,namey by a weight w +/// +/// if x or/and y is less than the low-edge of the corresponding axis first bin, +/// the Underflow cell is incremented. +/// if x or/and y is greater than the upper edge of corresponding axis last bin, +/// the Overflow cell is incremented. +/// +/// If the weight is not equal to 1, the storage of the sum of squares of +/// weights is automatically triggered and the sum of the squares of weights is incremented +/// by w^2 in the bin corresponding to namex,namey +/// +/// The function returns the corresponding global bin number which has its content +/// incremented by w + +Int_t GH2::Fill(const char *namex, const char *namey, Double_t w) +{ + Int_t binx, biny, bin; + fEntries++; + binx = fXaxis.FindBin(namex); + biny = fYaxis.FindBin(namey); + if (binx <0 || biny <0) return -1; + bin = biny*(fXaxis.GetNbins()+2) + binx; + if (!fSumw2.fN && w != 1.0 && !TestBit(GH1::kIsNotW)) Sumw2(); // must be called before AddBinContent + if (fSumw2.fN) fSumw2.fArray[bin] += w*w; + AddBinContent(bin,w); + if (binx == 0 || binx > fXaxis.GetNbins()) return -1; + if (biny == 0 || biny > fYaxis.GetNbins()) return -1; + Double_t x = fXaxis.GetBinCenter(binx); + Double_t y = fYaxis.GetBinCenter(biny); + Double_t z= w; + fTsumw += z; + fTsumw2 += z*z; + fTsumwx += z*x; + fTsumwx2 += z*x*x; + fTsumwy += z*y; + fTsumwy2 += z*y*y; + fTsumwxy += z*x*y; + return bin; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Increment cell defined by namex,y by a weight w +/// +/// if x or/and y is less than the low-edge of the corresponding axis first bin, +/// the Underflow cell is incremented. +/// if x or/and y is greater than the upper edge of corresponding axis last bin, +/// the Overflow cell is incremented. +/// +/// If the weight is not equal to 1, the storage of the sum of squares of +/// weights is automatically triggered and the sum of the squares of weights is incremented +/// by w^2 in the bin corresponding to namex,y +/// +/// The function returns the corresponding global bin number which has its content +/// incremented by w + +Int_t GH2::Fill(const char *namex, Double_t y, Double_t w) +{ + Int_t binx, biny, bin; + fEntries++; + binx = fXaxis.FindBin(namex); + biny = fYaxis.FindBin(y); + if (binx <0 || biny <0) return -1; + bin = biny*(fXaxis.GetNbins()+2) + binx; + if (!fSumw2.fN && w != 1.0 && !TestBit(GH1::kIsNotW)) Sumw2(); // must be called before AddBinContent + if (fSumw2.fN) fSumw2.fArray[bin] += w*w; + AddBinContent(bin,w); + if (binx == 0 || binx > fXaxis.GetNbins()) return -1; + if (biny == 0 || biny > fYaxis.GetNbins()) { + if (!fgStatOverflows) return -1; + } + Double_t x = fXaxis.GetBinCenter(binx); + Double_t z= w; //(w > 0 ? w : -w); + fTsumw += z; + fTsumw2 += z*z; + fTsumwx += z*x; + fTsumwx2 += z*x*x; + fTsumwy += z*y; + fTsumwy2 += z*y*y; + fTsumwxy += z*x*y; + return bin; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Increment cell defined by x,namey by a weight w +/// +/// if x or/and y is less than the low-edge of the corresponding axis first bin, +/// the Underflow cell is incremented. +/// if x or/and y is greater than the upper edge of corresponding axis last bin, +/// the Overflow cell is incremented. +/// +/// If the weight is not equal to 1, the storage of the sum of squares of +/// weights is automatically triggered and the sum of the squares of weights is incremented +/// by w^2 in the bin corresponding to x,y. +/// +/// The function returns the corresponding global bin number which has its content +/// incremented by w + +Int_t GH2::Fill(Double_t x, const char *namey, Double_t w) +{ + Int_t binx, biny, bin; + fEntries++; + binx = fXaxis.FindBin(x); + biny = fYaxis.FindBin(namey); + if (binx <0 || biny <0) return -1; + bin = biny*(fXaxis.GetNbins()+2) + binx; + if (!fSumw2.fN && w != 1.0 && !TestBit(GH1::kIsNotW)) Sumw2(); // must be called before AddBinContent + if (fSumw2.fN) fSumw2.fArray[bin] += w*w; + AddBinContent(bin,w); + if (binx == 0 || binx > fXaxis.GetNbins()) { + if (!fgStatOverflows) return -1; + } + if (biny == 0 || biny > fYaxis.GetNbins()) return -1; + Double_t y = fYaxis.GetBinCenter(biny); + Double_t z= w; //(w > 0 ? w : -w); + fTsumw += z; + fTsumw2 += z*z; + fTsumwx += z*x; + fTsumwx2 += z*x*x; + fTsumwy += z*y; + fTsumwy2 += z*y*y; + fTsumwxy += z*x*y; + return bin; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Fill a 2-D histogram with an array of values and weights. +/// +/// ntimes: number of entries in arrays x and w (array size must be ntimes*stride) +/// x: array of x values to be histogrammed +/// y: array of y values to be histogrammed +/// w: array of weights +/// stride: step size through arrays x, y and w +/// +/// If the weight is not equal to 1, the storage of the sum of squares of +/// weights is automatically triggered and the sum of the squares of weights is incremented +/// by w[i]^2 in the bin corresponding to x[i],y[i]. +/// If w is NULL each entry is assumed a weight=1 +/// +/// NB: function only valid for a GH2x object + +void GH2::FillN(Int_t ntimes, const Double_t *x, const Double_t *y, const Double_t *w, Int_t stride) +{ + Int_t binx, biny, bin, i; + ntimes *= stride; + Int_t ifirst = 0; + + //If a buffer is activated, fill buffer + // (note that this function must not be called from GH2::BufferEmpty) + if (fBuffer) { + for (i=0;i fXaxis.GetNbins()) { + if (!fgStatOverflows) continue; + } + if (biny == 0 || biny > fYaxis.GetNbins()) { + if (!fgStatOverflows) continue; + } + Double_t z= ww; //(ww > 0 ? ww : -ww); + fTsumw += z; + fTsumw2 += z*z; + fTsumwx += z*x[i]; + fTsumwx2 += z*x[i]*x[i]; + fTsumwy += z*y[i]; + fTsumwy2 += z*y[i]*y[i]; + fTsumwxy += z*x[i]*y[i]; + } +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Fill histogram following distribution in function fname. +/// +/// The distribution contained in the function fname (TF2) is integrated +/// over the channel contents. +/// It is normalized to 1. +/// Getting one random number implies: +/// - Generating a random number between 0 and 1 (say r1) +/// - Look in which bin in the normalized integral r1 corresponds to +/// - Fill histogram channel +/// ntimes random numbers are generated +/// +/// One can also call TF2::GetRandom2 to get a random variate from a function. + +void GH2::FillRandom(const char *fname, Int_t ntimes) +{ + Int_t bin, binx, biny, ibin, loop; + Double_t r1, x, y; + //*-*- Search for fname in the list of ROOT defined functions + TObject *fobj = gROOT->GetFunction(fname); + if (!fobj) { Error("FillRandom", "Unknown function: %s",fname); return; } + TF2 * f1 = dynamic_cast(fobj); + if (!f1) { Error("FillRandom", "Function: %s is not a TF2",fname); return; } + + // Allocate temporary space to store the integral and compute integral + Int_t nbinsx = GetNbinsX(); + Int_t nbinsy = GetNbinsY(); + Int_t nbins = nbinsx*nbinsy; + + Double_t *integral = new Double_t[nbins+1]; + ibin = 0; + integral[ibin] = 0; + for (biny=1;biny<=nbinsy;biny++) { + for (binx=1;binx<=nbinsx;binx++) { + ibin++; + Double_t fint = f1->Integral(fXaxis.GetBinLowEdge(binx), fXaxis.GetBinUpEdge(binx), fYaxis.GetBinLowEdge(biny), fYaxis.GetBinUpEdge(biny)); + integral[ibin] = integral[ibin-1] + fint; + } + } + + // Normalize integral to 1 + if (integral[nbins] == 0 ) { + delete [] integral; + Error("FillRandom", "Integral = zero"); return; + } + for (bin=1;bin<=nbins;bin++) integral[bin] /= integral[nbins]; + + // Start main loop ntimes + for (loop=0;loopRndm(loop); + ibin = TMath::BinarySearch(nbins,&integral[0],r1); + biny = ibin/nbinsx; + binx = 1 + ibin - nbinsx*biny; + biny++; + x = fXaxis.GetBinCenter(binx); + y = fYaxis.GetBinCenter(biny); + Fill(x,y); + } + delete [] integral; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Fill histogram following distribution in histogram h. +/// +/// The distribution contained in the histogram h (GH2) is integrated +/// over the channel contents. +/// It is normalized to 1. +/// Getting one random number implies: +/// - Generating a random number between 0 and 1 (say r1) +/// - Look in which bin in the normalized integral r1 corresponds to +/// - Fill histogram channel +/// ntimes random numbers are generated + +void GH2::FillRandom(GH1 *h, Int_t ntimes) +{ + if (!h) { Error("FillRandom", "Null histogram"); return; } + if (fDimension != h->GetDimension()) { + Error("FillRandom", "Histograms with different dimensions"); return; + } + + if (h->ComputeIntegral() == 0) return; + + Int_t loop; + Double_t x,y; + GH2 *h2 = (GH2*)h; + for (loop=0;loopGetRandom2(x,y); + Fill(x,y); + } +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Find first bin with content > threshold for axis (1=x, 2=y, 3=z) +/// if no bins with content > threshold is found the function returns -1. + +Int_t GH2::FindFirstBinAbove(Double_t threshold, Int_t axis) const +{ + if (axis < 1 || axis > 2) { + Warning("FindFirstBinAbove","Invalid axis number : %d, axis x assumed\n",axis); + axis = 1; + } + Int_t nbinsx = fXaxis.GetNbins(); + Int_t nbinsy = fYaxis.GetNbins(); + Int_t binx, biny; + if (axis == 1) { + for (binx=1;binx<=nbinsx;binx++) { + for (biny=1;biny<=nbinsy;biny++) { + if (GetBinContent(binx,biny) > threshold) return binx; + } + } + } else { + for (biny=1;biny<=nbinsy;biny++) { + for (binx=1;binx<=nbinsx;binx++) { + if (GetBinContent(binx,biny) > threshold) return biny; + } + } + } + return -1; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Find last bin with content > threshold for axis (1=x, 2=y, 3=z) +/// if no bins with content > threshold is found the function returns -1. + +Int_t GH2::FindLastBinAbove(Double_t threshold, Int_t axis) const +{ + if (axis < 1 || axis > 2) { + Warning("FindLastBinAbove","Invalid axis number : %d, axis x assumed\n",axis); + axis = 1; + } + Int_t nbinsx = fXaxis.GetNbins(); + Int_t nbinsy = fYaxis.GetNbins(); + Int_t binx, biny; + if (axis == 1) { + for (binx=nbinsx;binx>=1;binx--) { + for (biny=1;biny<=nbinsy;biny++) { + if (GetBinContent(binx,biny) > threshold) return binx; + } + } + } else { + for (biny=nbinsy;biny>=1;biny--) { + for (binx=1;binx<=nbinsx;binx++) { + if (GetBinContent(binx,biny) > threshold) return biny; + } + } + } + return -1; +} + + +//////////////////////////////////////////////////////////////////////////////// + +void GH2::DoFitSlices(bool onX, + TF1 *f1, Int_t firstbin, Int_t lastbin, Int_t cut, Option_t *option, TObjArray* arr) +{ + TAxis& outerAxis = (onX ? fYaxis : fXaxis); + TAxis& innerAxis = (onX ? fXaxis : fYaxis); + + Int_t nbins = outerAxis.GetNbins(); + if (firstbin < 0) firstbin = 0; + if (lastbin < 0 || lastbin > nbins + 1) lastbin = nbins + 1; + if (lastbin < firstbin) {firstbin = 0; lastbin = nbins + 1;} + TString opt = option; + opt.ToLower(); + Int_t ngroup = 1; + if (opt.Contains("g2")) {ngroup = 2; opt.ReplaceAll("g2","");} + if (opt.Contains("g3")) {ngroup = 3; opt.ReplaceAll("g3","");} + if (opt.Contains("g4")) {ngroup = 4; opt.ReplaceAll("g4","");} + if (opt.Contains("g5")) {ngroup = 5; opt.ReplaceAll("g5","");} + + // implement option S sliding merge for each bin using in conjunction with a given Gn + Int_t nstep = ngroup; + if (opt.Contains("s")) nstep = 1; + + //default is to fit with a gaussian + if (f1 == 0) { + f1 = (TF1*)gROOT->GetFunction("gaus"); + if (f1 == 0) f1 = new TF1("gaus","gaus",innerAxis.GetXmin(),innerAxis.GetXmax()); + else f1->SetRange(innerAxis.GetXmin(),innerAxis.GetXmax()); + } + Int_t npar = f1->GetNpar(); + if (npar <= 0) return; + Double_t *parsave = new Double_t[npar]; + f1->GetParameters(parsave); + + if (arr) { + arr->SetOwner(); + arr->Expand(npar + 1); + } + + //Create one histogram for each function parameter + Int_t ipar; + GH1D **hlist = new GH1D*[npar]; + char *name = new char[2000]; + char *title = new char[2000]; + const TArrayD *bins = outerAxis.GetXbins(); + for (ipar=0;iparGetParName(ipar)); + delete gDirectory->FindObject(name); + if (bins->fN == 0) { + hlist[ipar] = new GH1D(name,title, nbins, outerAxis.GetXmin(), outerAxis.GetXmax()); + } else { + hlist[ipar] = new GH1D(name,title, nbins,bins->fArray); + } + hlist[ipar]->GetXaxis()->SetTitle(outerAxis.GetTitle()); + if (arr) + (*arr)[ipar] = hlist[ipar]; + } + snprintf(name,2000,"%s_chi2",GetName()); + delete gDirectory->FindObject(name); + GH1D *hchi2 = 0; + if (bins->fN == 0) { + hchi2 = new GH1D(name,"chisquare", nbins, outerAxis.GetXmin(), outerAxis.GetXmax()); + } else { + hchi2 = new GH1D(name,"chisquare", nbins, bins->fArray); + } + hchi2->GetXaxis()->SetTitle(outerAxis.GetTitle()); + if (arr) + (*arr)[npar] = hchi2; + + //Loop on all bins in Y, generate a projection along X + Int_t bin; + Long64_t nentries; + // in case of sliding merge nstep=1, i.e. do slices starting for every bin + // now do not slices case with overflow (makes more sense) + for (bin=firstbin;bin+ngroup-1<=lastbin;bin += nstep) { + GH1D *hp; + if (onX) + hp= ProjectionX("_temp",bin,bin+ngroup-1,"e"); + else + hp= ProjectionY("_temp",bin,bin+ngroup-1,"e"); + if (hp == 0) continue; + nentries = Long64_t(hp->GetEntries()); + if (nentries == 0 || nentries < cut) {delete hp; continue;} + f1->SetParameters(parsave); + hp->Fit(f1,opt.Data()); + Int_t npfits = f1->GetNumberFitPoints(); + if (npfits > npar && npfits >= cut) { + Int_t binOn = bin + ngroup/2; + for (ipar=0;iparFill(outerAxis.GetBinCenter(binOn),f1->GetParameter(ipar)); + hlist[ipar]->SetBinError(binOn,f1->GetParError(ipar)); + } + hchi2->SetBinContent(binOn,f1->GetChisquare()/(npfits-npar)); + } + delete hp; + } + delete [] parsave; + delete [] name; + delete [] title; + delete [] hlist; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Project slices along X in case of a 2-D histogram, then fit each slice +/// with function f1 and make a histogram for each fit parameter +/// Only bins along Y between firstybin and lastybin are considered. +/// By default (firstybin == 0, lastybin == -1), all bins in y including +/// over- and underflows are taken into account. +/// If f1=0, a gaussian is assumed +/// Before invoking this function, one can set a subrange to be fitted along X +/// via f1->SetRange(xmin,xmax) +/// The argument option (default="QNR") can be used to change the fit options. +/// "Q" means Quiet mode +/// "N" means do not show the result of the fit +/// "R" means fit the function in the specified function range +/// "G2" merge 2 consecutive bins along X +/// "G3" merge 3 consecutive bins along X +/// "G4" merge 4 consecutive bins along X +/// "G5" merge 5 consecutive bins along X +/// "S" sliding merge: merge n consecutive bins along X accordingly to what Gn is given. +/// It makes sense when used together with a Gn option +/// +/// The generated histograms are returned by adding them to arr, if arr is not NULL. +/// arr's SetOwner() is called, to signal that it is the user's respponsability to +/// delete the histograms, possibly by deleting the arrary. +/// TObjArray aSlices; +/// h2->FitSlicesX(func, 0, -1, 0, "QNR", &aSlices); +/// will already delete the histograms once aSlice goes out of scope. aSlices will +/// contain the histogram for the i-th parameter of the fit function at aSlices[i]; +/// aSlices[n] (n being the number of parameters) contains the chi2 distribution of +/// the fits. +/// +/// If arr is NULL, the generated histograms are added to the list of objects +/// in the current directory. It is the user's responsability to delete +/// these histograms. +/// +/// Example: Assume a 2-d histogram h2 +/// Root > h2->FitSlicesX(); produces 4 GH1D histograms +/// with h2_0 containing parameter 0(Constant) for a Gaus fit +/// of each bin in Y projected along X +/// with h2_1 containing parameter 1(Mean) for a gaus fit +/// with h2_2 containing parameter 2(StdDev) for a gaus fit +/// with h2_chi2 containing the chisquare/number of degrees of freedom for a gaus fit +/// +/// Root > h2->FitSlicesX(0,15,22,10); +/// same as above, but only for bins 15 to 22 along Y +/// and only for bins in Y for which the corresponding projection +/// along X has more than cut bins filled. +/// +/// NOTE: To access the generated histograms in the current directory, do eg: +/// GH1D *h2_1 = (GH1D*)gDirectory->Get("h2_1"); + +void GH2::FitSlicesX(TF1 *f1, Int_t firstybin, Int_t lastybin, Int_t cut, Option_t *option, TObjArray* arr) +{ + DoFitSlices(true, f1, firstybin, lastybin, cut, option, arr); + +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Project slices along Y in case of a 2-D histogram, then fit each slice +/// with function f1 and make a histogram for each fit parameter +/// Only bins along X between firstxbin and lastxbin are considered. +/// By default (firstxbin == 0, lastxbin == -1), all bins in x including +/// over- and underflows are taken into account. +/// If f1=0, a gaussian is assumed +/// Before invoking this function, one can set a subrange to be fitted along Y +/// via f1->SetRange(ymin,ymax) +/// The argument option (default="QNR") can be used to change the fit options. +/// "Q" means Quiet mode +/// "N" means do not show the result of the fit +/// "R" means fit the function in the specified function range +/// "G2" merge 2 consecutive bins along Y +/// "G3" merge 3 consecutive bins along Y +/// "G4" merge 4 consecutive bins along Y +/// "G5" merge 5 consecutive bins along Y +/// "S" sliding merge: merge n consecutive bins along Y accordingly to what Gn is given. +/// It makes sense when used together with a Gn option +/// +/// The generated histograms are returned by adding them to arr, if arr is not NULL. +/// arr's SetOwner() is called, to signal that it is the user's respponsability to +/// delete the histograms, possibly by deleting the arrary. +/// TObjArray aSlices; +/// h2->FitSlicesY(func, 0, -1, 0, "QNR", &aSlices); +/// will already delete the histograms once aSlice goes out of scope. aSlices will +/// contain the histogram for the i-th parameter of the fit function at aSlices[i]; +/// aSlices[n] (n being the number of parameters) contains the chi2 distribution of +/// the fits. +/// +/// If arr is NULL, the generated histograms are added to the list of objects +/// in the current directory. It is the user's responsability to delete +/// these histograms. +/// +/// Example: Assume a 2-d histogram h2 +/// Root > h2->FitSlicesY(); produces 4 GH1D histograms +/// with h2_0 containing parameter 0(Constant) for a Gaus fit +/// of each bin in X projected along Y +/// with h2_1 containing parameter 1(Mean) for a gaus fit +/// with h2_2 containing parameter 2(StdDev) for a gaus fit +/// with h2_chi2 containing the chisquare/number of degrees of freedom for a gaus fit +/// +/// Root > h2->FitSlicesY(0,15,22,10); +/// same as above, but only for bins 15 to 22 along X +/// and only for bins in X for which the corresponding projection +/// along Y has more than cut bins filled. +/// +/// NOTE: To access the generated histograms in the current directory, do eg: +/// GH1D *h2_1 = (GH1D*)gDirectory->Get("h2_1"); +/// +/// A complete example of this function is given in begin_html tutorial:fitslicesy.C end_html +/// with the following output: +///Begin_Html + +void GH2::FitSlicesY(TF1 *f1, Int_t firstxbin, Int_t lastxbin, Int_t cut, Option_t *option, TObjArray* arr) +{ + /* + + */ + //End_Html + + DoFitSlices(false, f1, firstxbin, lastxbin, cut, option, arr); + +} + +Int_t GH2::GetBin(Int_t binx, Int_t biny, Int_t) const +{ + // See comments in GH1::GetBin + Int_t ofy = fYaxis.GetNbins() + 1; // overflow bin + if (biny < 0) biny = 0; + if (biny > ofy) biny = ofy; + + return GH1::GetBin(binx) + (fXaxis.GetNbins() + 2) * biny; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// compute first cell (binx,biny) in the range [firstxbin,lastxbin][firstybin,lastybin] for which +/// diff = abs(cell_content-c) <= maxdiff +/// In case several cells in the specified range with diff=0 are found +/// the first cell found is returned in binx,biny. +/// In case several cells in the specified range satisfy diff <=maxdiff +/// the cell with the smallest difference is returned in binx,biny. +/// In all cases the function returns the smallest difference. +/// +/// NOTE1: if firstxbin < 0, firstxbin is set to 1 +/// if (lastxbin < firstxbin then lastxbin is set to the number of bins in X +/// ie if firstxbin=1 and lastxbin=0 (default) the search is on all bins in X except +/// for X's under- and overflow bins. +/// if firstybin < 0, firstybin is set to 1 +/// if (lastybin < firstybin then lastybin is set to the number of bins in Y +/// ie if firstybin=1 and lastybin=0 (default) the search is on all bins in Y except +/// for Y's under- and overflow bins. +/// NOTE2: if maxdiff=0 (default), the first cell with content=c is returned. + +Double_t GH2::GetBinWithContent2(Double_t c, Int_t &binx, Int_t &biny, Int_t firstxbin, Int_t lastxbin, + Int_t firstybin, Int_t lastybin, Double_t maxdiff) const +{ + if (fDimension != 2) { + binx = -1; + biny = -1; + Error("GetBinWithContent2","function is only valid for 2-D histograms"); + return 0; + } + if (firstxbin < 0) firstxbin = 1; + if (lastxbin < firstxbin) lastxbin = fXaxis.GetNbins(); + if (firstybin < 0) firstybin = 1; + if (lastybin < firstybin) lastybin = fYaxis.GetNbins(); + Double_t diff, curmax = 1.e240; + for (Int_t j = firstybin; j <= lastybin; j++) { + for (Int_t i = firstxbin; i <= lastxbin; i++) { + diff = TMath::Abs(GetBinContent(i,j)-c); + if (diff <= 0) {binx = i; biny=j; return diff;} + if (diff < curmax && diff <= maxdiff) {curmax = diff, binx=i; biny=j;} + } + } + return curmax; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Return correlation factor between axis1 and axis2. + +Double_t GH2::GetCorrelationFactor(Int_t axis1, Int_t axis2) const +{ + if (axis1 < 1 || axis2 < 1 || axis1 > 2 || axis2 > 2) { + Error("GetCorrelationFactor","Wrong parameters"); + return 0; + } + if (axis1 == axis2) return 1; + Double_t stddev1 = GetStdDev(axis1); + if (stddev1 == 0) return 0; + Double_t stddev2 = GetStdDev(axis2); + if (stddev2 == 0) return 0; + return GetCovariance(axis1,axis2)/stddev1/stddev2; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Return covariance between axis1 and axis2. + +Double_t GH2::GetCovariance(Int_t axis1, Int_t axis2) const +{ + if (axis1 < 1 || axis2 < 1 || axis1 > 2 || axis2 > 2) { + Error("GetCovariance","Wrong parameters"); + return 0; + } + Double_t stats[kNstat]; + GetStats(stats); + Double_t sumw = stats[0]; + //Double_t sumw2 = stats[1]; + Double_t sumwx = stats[2]; + Double_t sumwx2 = stats[3]; + Double_t sumwy = stats[4]; + Double_t sumwy2 = stats[5]; + Double_t sumwxy = stats[6]; + + if (sumw == 0) return 0; + if (axis1 == 1 && axis2 == 1) { + return TMath::Abs(sumwx2/sumw - sumwx/sumw*sumwx/sumw); + } + if (axis1 == 2 && axis2 == 2) { + return TMath::Abs(sumwy2/sumw - sumwy/sumw*sumwy/sumw); + } + return sumwxy/sumw - sumwx/sumw*sumwy/sumw; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Return 2 random numbers along axis x and y distributed according +/// the cellcontents of a 2-dim histogram +/// return a NaN if the histogram has a bin with negative content + +void GH2::GetRandom2(Double_t &x, Double_t &y) +{ + Int_t nbinsx = GetNbinsX(); + Int_t nbinsy = GetNbinsY(); + Int_t nbins = nbinsx*nbinsy; + Double_t integral; + // compute integral checking that all bins have positive content (see ROOT-5894) + if (fIntegral) { + if (fIntegral[nbins+1] != fEntries) integral = ComputeIntegral(true); + else integral = fIntegral[nbins]; + } else { + integral = ComputeIntegral(true); + } + if (integral == 0 ) { x = 0; y = 0; return;} + // case histogram has negative bins + if (integral == TMath::QuietNaN() ) { x = TMath::QuietNaN(); y = TMath::QuietNaN(); return;} + + Double_t r1 = gRandom->Rndm(); + Int_t ibin = TMath::BinarySearch(nbins,fIntegral,(Double_t) r1); + Int_t biny = ibin/nbinsx; + Int_t binx = ibin - nbinsx*biny; + x = fXaxis.GetBinLowEdge(binx+1); + if (r1 > fIntegral[ibin]) x += + fXaxis.GetBinWidth(binx+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]); + y = fYaxis.GetBinLowEdge(biny+1) + fYaxis.GetBinWidth(biny+1)*gRandom->Rndm(); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Fill the array stats from the contents of this histogram +/// The array stats must be correctly dimensionned in the calling program. +/// stats[0] = sumw +/// stats[1] = sumw2 +/// stats[2] = sumwx +/// stats[3] = sumwx2 +/// stats[4] = sumwy +/// stats[5] = sumwy2 +/// stats[6] = sumwxy +/// +/// If no axis-subranges are specified (via TAxis::SetRange), the array stats +/// is simply a copy of the statistics quantities computed at filling time. +/// If sub-ranges are specified, the function recomputes these quantities +/// from the bin contents in the current axis ranges. +/// +/// Note that the mean value/StdDev is computed using the bins in the currently +/// defined ranges (see TAxis::SetRange). By default the ranges include +/// all bins from 1 to nbins included, excluding underflows and overflows. +/// To force the underflows and overflows in the computation, one must +/// call the static function GH1::StatOverflows(kTRUE) before filling +/// the histogram. + +void GH2::GetStats(Double_t *stats) const +{ + if (fBuffer) ((GH2*)this)->BufferEmpty(); + + if ((fTsumw == 0 && fEntries > 0) || fXaxis.TestBit(TAxis::kAxisRange) || fYaxis.TestBit(TAxis::kAxisRange)) { + std::fill(stats, stats + 7, 0); + + Int_t firstBinX = fXaxis.GetFirst(); + Int_t lastBinX = fXaxis.GetLast(); + Int_t firstBinY = fYaxis.GetFirst(); + Int_t lastBinY = fYaxis.GetLast(); + // include underflow/overflow if GH1::StatOverflows(kTRUE) in case no range is set on the axis + if (fgStatOverflows) { + if ( !fXaxis.TestBit(TAxis::kAxisRange) ) { + if (firstBinX == 1) firstBinX = 0; + if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1; + } + if ( !fYaxis.TestBit(TAxis::kAxisRange) ) { + if (firstBinY == 1) firstBinY = 0; + if (lastBinY == fYaxis.GetNbins() ) lastBinY += 1; + } + } + for (Int_t biny = firstBinY; biny <= lastBinY; ++biny) { + Double_t y = fYaxis.GetBinCenter(biny); + for (Int_t binx = firstBinX; binx <= lastBinX; ++binx) { + Double_t x = fXaxis.GetBinCenter(binx); + //w = TMath::Abs(GetBinContent(bin)); + Int_t bin = GetBin(binx,biny); + Double_t w = RetrieveBinContent(bin); + Double_t wx = w * x; // avoid some extra multiplications at the expense of some clarity + Double_t wy = w * y; + + stats[0] += w; + stats[1] += GetBinErrorSqUnchecked(bin); + stats[2] += wx; + stats[3] += wx * x; + stats[4] += wy; + stats[5] += wy * y; + stats[6] += wx * y; + } + } + } else { + stats[0] = fTsumw; + stats[1] = fTsumw2; + stats[2] = fTsumwx; + stats[3] = fTsumwx2; + stats[4] = fTsumwy; + stats[5] = fTsumwy2; + stats[6] = fTsumwxy; + } +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Return integral of bin contents. Only bins in the bins range are considered. +/// By default the integral is computed as the sum of bin contents in the range. +/// if option "width" is specified, the integral is the sum of +/// the bin contents multiplied by the bin width in x and in y. + +Double_t GH2::Integral(Option_t *option) const +{ + return Integral(fXaxis.GetFirst(),fXaxis.GetLast(), + fYaxis.GetFirst(),fYaxis.GetLast(),option); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Return integral of bin contents in range [firstxbin,lastxbin],[firstybin,lastybin] +/// for a 2-D histogram +/// By default the integral is computed as the sum of bin contents in the range. +/// if option "width" is specified, the integral is the sum of +/// the bin contents multiplied by the bin width in x and in y. + +Double_t GH2::Integral(Int_t firstxbin, Int_t lastxbin, Int_t firstybin, Int_t lastybin, Option_t *option) const +{ + double err = 0; + return DoIntegral(firstxbin,lastxbin,firstybin,lastybin,-1,0,err,option); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Return integral of bin contents in range [firstxbin,lastxbin],[firstybin,lastybin] +/// for a 2-D histogram. Calculates also the integral error using error propagation +/// from the bin errors assumming that all the bins are uncorrelated. +/// By default the integral is computed as the sum of bin contents in the range. +/// if option "width" is specified, the integral is the sum of +/// the bin contents multiplied by the bin width in x and in y. + +Double_t GH2::IntegralAndError(Int_t firstxbin, Int_t lastxbin, Int_t firstybin, Int_t lastybin, Double_t & error, Option_t *option) const +{ + return DoIntegral(firstxbin,lastxbin,firstybin,lastybin,-1,0,error,option,kTRUE); +} + + +//////////////////////////////////////////////////////////////////////////////// +///illegal for a GH2 + +Double_t GH2::Interpolate(Double_t) +{ + Error("Interpolate","This function must be called with 2 arguments for a GH2"); + return 0; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Given a point P(x,y), Interpolate approximates the value via bilinear +/// interpolation based on the four nearest bin centers +/// see Wikipedia, Bilinear Interpolation +/// Andy Mastbaum 10/8/2008 +/// vaguely based on R.Raja 6-Sep-2008 + + Double_t GH2::Interpolate(Double_t x, Double_t y) +{ + Double_t f=0; + Double_t x1=0,x2=0,y1=0,y2=0; + Double_t dx,dy; + Int_t bin_x = fXaxis.FindBin(x); + Int_t bin_y = fYaxis.FindBin(y); + if(bin_x<1 || bin_x>GetNbinsX() || bin_y<1 || bin_y>GetNbinsY()) { + Error("Interpolate","Cannot interpolate outside histogram domain."); + return 0; + } + Int_t quadrant = 0; // CCW from UR 1,2,3,4 + // which quadrant of the bin (bin_P) are we in? + dx = fXaxis.GetBinUpEdge(bin_x)-x; + dy = fYaxis.GetBinUpEdge(bin_y)-y; + if (dx<=fXaxis.GetBinWidth(bin_x)/2 && dy<=fYaxis.GetBinWidth(bin_y)/2) + quadrant = 1; // upper right + if (dx>fXaxis.GetBinWidth(bin_x)/2 && dy<=fYaxis.GetBinWidth(bin_y)/2) + quadrant = 2; // upper left + if (dx>fXaxis.GetBinWidth(bin_x)/2 && dy>fYaxis.GetBinWidth(bin_y)/2) + quadrant = 3; // lower left + if (dx<=fXaxis.GetBinWidth(bin_x)/2 && dy>fYaxis.GetBinWidth(bin_y)/2) + quadrant = 4; // lower right + switch(quadrant) { + case 1: + x1 = fXaxis.GetBinCenter(bin_x); + y1 = fYaxis.GetBinCenter(bin_y); + x2 = fXaxis.GetBinCenter(bin_x+1); + y2 = fYaxis.GetBinCenter(bin_y+1); + break; + case 2: + x1 = fXaxis.GetBinCenter(bin_x-1); + y1 = fYaxis.GetBinCenter(bin_y); + x2 = fXaxis.GetBinCenter(bin_x); + y2 = fYaxis.GetBinCenter(bin_y+1); + break; + case 3: + x1 = fXaxis.GetBinCenter(bin_x-1); + y1 = fYaxis.GetBinCenter(bin_y-1); + x2 = fXaxis.GetBinCenter(bin_x); + y2 = fYaxis.GetBinCenter(bin_y); + break; + case 4: + x1 = fXaxis.GetBinCenter(bin_x); + y1 = fYaxis.GetBinCenter(bin_y-1); + x2 = fXaxis.GetBinCenter(bin_x+1); + y2 = fYaxis.GetBinCenter(bin_y); + break; + } + Int_t bin_x1 = fXaxis.FindBin(x1); + if(bin_x1<1) bin_x1=1; + Int_t bin_x2 = fXaxis.FindBin(x2); + if(bin_x2>GetNbinsX()) bin_x2=GetNbinsX(); + Int_t bin_y1 = fYaxis.FindBin(y1); + if(bin_y1<1) bin_y1=1; + Int_t bin_y2 = fYaxis.FindBin(y2); + if(bin_y2>GetNbinsY()) bin_y2=GetNbinsY(); + Int_t bin_q22 = GetBin(bin_x2,bin_y2); + Int_t bin_q12 = GetBin(bin_x1,bin_y2); + Int_t bin_q11 = GetBin(bin_x1,bin_y1); + Int_t bin_q21 = GetBin(bin_x2,bin_y1); + Double_t q11 = RetrieveBinContent(bin_q11); + Double_t q12 = RetrieveBinContent(bin_q12); + Double_t q21 = RetrieveBinContent(bin_q21); + Double_t q22 = RetrieveBinContent(bin_q22); + Double_t d = 1.0*(x2-x1)*(y2-y1); + f = 1.0*q11/d*(x2-x)*(y2-y)+1.0*q21/d*(x-x1)*(y2-y)+1.0*q12/d*(x2-x)*(y-y1)+1.0*q22/d*(x-x1)*(y-y1); + return f; +} + + +//////////////////////////////////////////////////////////////////////////////// +///illegal for a GH2 + +Double_t GH2::Interpolate(Double_t, Double_t, Double_t) +{ + Error("Interpolate","This function must be called with 2 arguments for a GH2"); + return 0; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Statistical test of compatibility in shape between +/// THIS histogram and h2, using Kolmogorov test. +/// Default: Ignore under- and overflow bins in comparison +/// +/// option is a character string to specify options +/// "U" include Underflows in test +/// "O" include Overflows +/// "N" include comparison of normalizations +/// "D" Put out a line of "Debug" printout +/// "M" Return the Maximum Kolmogorov distance instead of prob +/// +/// The returned function value is the probability of test +/// (much less than one means NOT compatible) +/// +/// The KS test uses the distance between the pseudo-CDF's obtained +/// from the histogram. Since in 2D the order for generating the pseudo-CDF is +/// arbitrary, two pairs of pseudo-CDF are used, one starting from the x axis the +/// other from the y axis and the maximum distance is the average of the two maximum +/// distances obtained. +/// +/// Code adapted by Rene Brun from original HBOOK routine HDIFF + +Double_t GH2::KolmogorovTest(const GH1 *h2, Option_t *option) const +{ + TString opt = option; + opt.ToUpper(); + + Double_t prb = 0; + GH1 *h1 = (GH1*)this; + if (h2 == 0) return 0; + const TAxis *xaxis1 = h1->GetXaxis(); + const TAxis *xaxis2 = h2->GetXaxis(); + const TAxis *yaxis1 = h1->GetYaxis(); + const TAxis *yaxis2 = h2->GetYaxis(); + Int_t ncx1 = xaxis1->GetNbins(); + Int_t ncx2 = xaxis2->GetNbins(); + Int_t ncy1 = yaxis1->GetNbins(); + Int_t ncy2 = yaxis2->GetNbins(); + + // Check consistency of dimensions + if (h1->GetDimension() != 2 || h2->GetDimension() != 2) { + Error("KolmogorovTest","Histograms must be 2-D\n"); + return 0; + } + + // Check consistency in number of channels + if (ncx1 != ncx2) { + Error("KolmogorovTest","Number of channels in X is different, %d and %d\n",ncx1,ncx2); + return 0; + } + if (ncy1 != ncy2) { + Error("KolmogorovTest","Number of channels in Y is different, %d and %d\n",ncy1,ncy2); + return 0; + } + + // Check consistency in channel edges + Bool_t afunc1 = kFALSE; + Bool_t afunc2 = kFALSE; + Double_t difprec = 1e-5; + Double_t diff1 = TMath::Abs(xaxis1->GetXmin() - xaxis2->GetXmin()); + Double_t diff2 = TMath::Abs(xaxis1->GetXmax() - xaxis2->GetXmax()); + if (diff1 > difprec || diff2 > difprec) { + Error("KolmogorovTest","histograms with different binning along X"); + return 0; + } + diff1 = TMath::Abs(yaxis1->GetXmin() - yaxis2->GetXmin()); + diff2 = TMath::Abs(yaxis1->GetXmax() - yaxis2->GetXmax()); + if (diff1 > difprec || diff2 > difprec) { + Error("KolmogorovTest","histograms with different binning along Y"); + return 0; + } + + // Should we include Uflows, Oflows? + Int_t ibeg = 1, jbeg = 1; + Int_t iend = ncx1, jend = ncy1; + if (opt.Contains("U")) {ibeg = 0; jbeg = 0;} + if (opt.Contains("O")) {iend = ncx1+1; jend = ncy1+1;} + + Int_t i,j; + Double_t sum1 = 0; + Double_t sum2 = 0; + Double_t w1 = 0; + Double_t w2 = 0; + for (i = ibeg; i <= iend; i++) { + for (j = jbeg; j <= jend; j++) { + sum1 += h1->GetBinContent(i,j); + sum2 += h2->GetBinContent(i,j); + Double_t ew1 = h1->GetBinError(i,j); + Double_t ew2 = h2->GetBinError(i,j); + w1 += ew1*ew1; + w2 += ew2*ew2; + + } + } + + // Check that both scatterplots contain events + if (sum1 == 0) { + Error("KolmogorovTest","Integral is zero for h1=%s\n",h1->GetName()); + return 0; + } + if (sum2 == 0) { + Error("KolmogorovTest","Integral is zero for h2=%s\n",h2->GetName()); + return 0; + } + // calculate the effective entries. + // the case when errors are zero (w1 == 0 or w2 ==0) are equivalent to + // compare to a function. In that case the rescaling is done only on sqrt(esum2) or sqrt(esum1) + Double_t esum1 = 0, esum2 = 0; + if (w1 > 0) + esum1 = sum1 * sum1 / w1; + else + afunc1 = kTRUE; // use later for calculating z + + if (w2 > 0) + esum2 = sum2 * sum2 / w2; + else + afunc2 = kTRUE; // use later for calculating z + + if (afunc2 && afunc1) { + Error("KolmogorovTest","Errors are zero for both histograms\n"); + return 0; + } + + // Find first Kolmogorov distance + Double_t s1 = 1/sum1; + Double_t s2 = 1/sum2; + Double_t dfmax1 = 0; + Double_t rsum1=0, rsum2=0; + for (i=ibeg;i<=iend;i++) { + for (j=jbeg;j<=jend;j++) { + rsum1 += s1*h1->GetBinContent(i,j); + rsum2 += s2*h2->GetBinContent(i,j); + dfmax1 = TMath::Max(dfmax1, TMath::Abs(rsum1-rsum2)); + } + } + + // Find second Kolmogorov distance + Double_t dfmax2 = 0; + rsum1=0, rsum2=0; + for (j=jbeg;j<=jend;j++) { + for (i=ibeg;i<=iend;i++) { + rsum1 += s1*h1->GetBinContent(i,j); + rsum2 += s2*h2->GetBinContent(i,j); + dfmax2 = TMath::Max(dfmax2, TMath::Abs(rsum1-rsum2)); + } + } + + // Get Kolmogorov probability: use effective entries, esum1 or esum2, for normalizing it + Double_t factnm; + if (afunc1) factnm = TMath::Sqrt(esum2); + else if (afunc2) factnm = TMath::Sqrt(esum1); + else factnm = TMath::Sqrt(esum1*sum2/(esum1+esum2)); + + // take average of the two distances + Double_t dfmax = 0.5*(dfmax1+dfmax2); + Double_t z = dfmax*factnm; + + prb = TMath::KolmogorovProb(z); + + Double_t prb1 = 0, prb2 = 0; + // option N to combine normalization makes sense if both afunc1 and afunc2 are false + if (opt.Contains("N") && !(afunc1 || afunc2 ) ) { + // Combine probabilities for shape and normalization + prb1 = prb; + Double_t d12 = esum1-esum2; + Double_t chi2 = d12*d12/(esum1+esum2); + prb2 = TMath::Prob(chi2,1); + // see Eadie et al., section 11.6.2 + if (prb > 0 && prb2 > 0) prb = prb*prb2*(1-TMath::Log(prb*prb2)); + else prb = 0; + } + + // debug printout + if (opt.Contains("D")) { + printf(" Kolmo Prob h1 = %s, sum1=%g\n",h1->GetName(),sum1); + printf(" Kolmo Prob h2 = %s, sum2=%g\n",h2->GetName(),sum2); + printf(" Kolmo Probabil = %f, Max Dist = %g\n",prb,dfmax); + if (opt.Contains("N")) + printf(" Kolmo Probabil = %f for shape alone, =%f for normalisation alone\n",prb1,prb2); + } + // This numerical error condition should never occur: + if (TMath::Abs(rsum1-1) > 0.002) Warning("KolmogorovTest","Numerical problems with h1=%s\n",h1->GetName()); + if (TMath::Abs(rsum2-1) > 0.002) Warning("KolmogorovTest","Numerical problems with h2=%s\n",h2->GetName()); + + if(opt.Contains("M")) return dfmax; // return avergae of max distance + + return prb; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Add all histograms in the collection to this histogram. +/// This function computes the min/max for the axes, +/// compute a new number of bins, if necessary, +/// add bin contents, errors and statistics. +/// If overflows are present and limits are different the function will fail. +/// The function returns the total number of entries in the result histogram +/// if the merge is successfull, -1 otherwise. +/// +/// IMPORTANT remark. The 2 axis x and y may have different number +/// of bins and different limits, BUT the largest bin width must be +/// a multiple of the smallest bin width and the upper limit must also +/// be a multiple of the bin width. + +Long64_t GH2::Merge(TCollection *list) +{ + if (!list) return 0; + if (list->IsEmpty()) return (Long64_t) GetEntries(); + + TList inlist; + inlist.AddAll(list); + + TAxis newXAxis; + TAxis newYAxis; + Bool_t initialLimitsFound = kFALSE; + Bool_t allSameLimits = kTRUE; + Bool_t sameLimitsX = kTRUE; + Bool_t sameLimitsY = kTRUE; + Bool_t allHaveLimits = kTRUE; + Bool_t firstHistWithLimits = kTRUE; + + TIter next(&inlist); + GH2 * h = this; + do { + + Bool_t hasLimits = h->GetXaxis()->GetXmin() < h->GetXaxis()->GetXmax(); + allHaveLimits = allHaveLimits && hasLimits; + + if (hasLimits) { + h->BufferEmpty(); + + // this is done in case the first histograms are empty and + // the histogram have different limits + if (firstHistWithLimits ) { + // set axis limits in the case the first histogram did not have limits + if (h != this ) { + if (!SameLimitsAndNBins(fXaxis, *(h->GetXaxis())) ) { + if (h->GetXaxis()->GetXbins()->GetSize() != 0) fXaxis.Set(h->GetXaxis()->GetNbins(), h->GetXaxis()->GetXbins()->GetArray()); + else fXaxis.Set(h->GetXaxis()->GetNbins(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax()); + } + if (!SameLimitsAndNBins(fYaxis, *(h->GetYaxis())) ) { + if (h->GetYaxis()->GetXbins()->GetSize() != 0) fYaxis.Set(h->GetYaxis()->GetNbins(), h->GetYaxis()->GetXbins()->GetArray()); + else fYaxis.Set(h->GetYaxis()->GetNbins(), h->GetYaxis()->GetXmin(), h->GetYaxis()->GetXmax()); + } + } + firstHistWithLimits = kFALSE; + } + + if (!initialLimitsFound) { + // this is executed the first time an histogram with limits is found + // to set some initial values on the new axes + initialLimitsFound = kTRUE; + if (h->GetXaxis()->GetXbins()->GetSize() != 0) newXAxis.Set(h->GetXaxis()->GetNbins(), h->GetXaxis()->GetXbins()->GetArray()); + else newXAxis.Set(h->GetXaxis()->GetNbins(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax()); + if (h->GetYaxis()->GetXbins()->GetSize() != 0) newYAxis.Set(h->GetYaxis()->GetNbins(), h->GetYaxis()->GetXbins()->GetArray()); + else newYAxis.Set(h->GetYaxis()->GetNbins(), h->GetYaxis()->GetXmin(), h->GetYaxis()->GetXmax()); + } + else { + // check first if histograms have same bins in X + if (!SameLimitsAndNBins(newXAxis, *(h->GetXaxis()))) { + sameLimitsX = kFALSE; + // recompute in this case the optimal limits + // The condition to works is that the histogram have same bin with + // and one common bin edge + if (!RecomputeAxisLimits(newXAxis, *(h->GetXaxis()))) { + Error("Merge", "Cannot merge histograms - limits are inconsistent:\n " + "first: (%d, %f, %f), second: (%d, %f, %f)", + newXAxis.GetNbins(), newXAxis.GetXmin(), newXAxis.GetXmax(), + h->GetXaxis()->GetNbins(), h->GetXaxis()->GetXmin(), + h->GetXaxis()->GetXmax()); + return -1; + } + } + + // check first if histograms have same bins in Y + if (!SameLimitsAndNBins(newYAxis, *(h->GetYaxis()))) { + sameLimitsY = kFALSE; + // recompute in this case the optimal limits + // The condition to works is that the histogram have same bin with + // and one common bin edge + if (!RecomputeAxisLimits(newYAxis, *(h->GetYaxis()))) { + Error("Merge", "Cannot merge histograms - limits are inconsistent:\n " + "first: (%d, %f, %f), second: (%d, %f, %f)", + newYAxis.GetNbins(), newYAxis.GetXmin(), newYAxis.GetXmax(), + h->GetYaxis()->GetNbins(), h->GetYaxis()->GetXmin(), + h->GetYaxis()->GetXmax()); + return -1; + } + } + allSameLimits = sameLimitsY && sameLimitsX; + } + } + } while ( ( h = dynamic_cast ( next() ) ) != NULL ); + if (!h && (*next) ) { + Error("Merge","Attempt to merge object of class: %s to a %s", + (*next)->ClassName(),this->ClassName()); + return -1; + } + next.Reset(); + + // In the case of histogram with different limits + // newX(Y)Axis will now have the new found limits + // but one needs first to clone this histogram to perform the merge + // The clone is not needed when all histograms have the same limits + GH2 * hclone = 0; + if (!allSameLimits) { + // We don't want to add the clone to gDirectory, + // so remove our kMustCleanup bit temporarily + Bool_t mustCleanup = TestBit(kMustCleanup); + if (mustCleanup) ResetBit(kMustCleanup); + hclone = (GH2*)IsA()->New(); + hclone->SetDirectory(0); + Copy(*hclone); + if (mustCleanup) SetBit(kMustCleanup); + BufferEmpty(1); // To remove buffer. + Reset(); // BufferEmpty sets limits so we can't use it later. + SetEntries(0); + inlist.AddFirst(hclone); + } + + if (!allSameLimits && initialLimitsFound) { + if (!sameLimitsX) { + fXaxis.SetRange(0,0); + if (newXAxis.GetXbins()->GetSize() != 0) fXaxis.Set(newXAxis.GetNbins(),newXAxis.GetXbins()->GetArray()); + else fXaxis.Set(newXAxis.GetNbins(),newXAxis.GetXmin(), newXAxis.GetXmax()); + } + if (!sameLimitsY) { + fYaxis.SetRange(0,0); + if (newYAxis.GetXbins()->GetSize() != 0) fYaxis.Set(newYAxis.GetNbins(),newYAxis.GetXbins()->GetArray()); + else fYaxis.Set(newYAxis.GetNbins(),newYAxis.GetXmin(), newYAxis.GetXmax()); + } + fZaxis.Set(1,0,1); + fNcells = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2); + SetBinsLength(fNcells); + if (fSumw2.fN) { + fSumw2.Set(fNcells); + } + } + + if (!allHaveLimits) { + // fill this histogram with all the data from buffers of histograms without limits + while ( (h = dynamic_cast (next())) ) { + if (h->GetXaxis()->GetXmin() >= h->GetXaxis()->GetXmax() && h->fBuffer) { + // no limits + Int_t nbentries = (Int_t)h->fBuffer[0]; + for (Int_t i = 0; i < nbentries; i++) + Fill(h->fBuffer[3*i + 2], h->fBuffer[3*i + 3], h->fBuffer[3*i + 1]); + // Entries from buffers have to be filled one by one + // because FillN doesn't resize histograms. + } + } + if (!initialLimitsFound) { + if (hclone) { + inlist.Remove(hclone); + delete hclone; + } + return (Long64_t) GetEntries(); // all histograms have been processed + } + next.Reset(); + } + + //merge bin contents and errors + Double_t stats[kNstat], totstats[kNstat]; + for (Int_t i=0;iGetEntries(); + if (h->fTsumw == 0 && histEntries == 0) continue; + + // process only if the histogram has limits; otherwise it was processed before + if (h->GetXaxis()->GetXmin() < h->GetXaxis()->GetXmax()) { + // import statistics + h->GetStats(stats); + for (Int_t i = 0; i < kNstat; i++) + totstats[i] += stats[i]; + nentries += histEntries; + + nx = h->GetXaxis()->GetNbins(); + ny = h->GetYaxis()->GetNbins(); + + for (biny = 0; biny <= ny + 1; biny++) { + if (!allSameLimits) + iy = fYaxis.FindBin(h->GetYaxis()->GetBinCenter(biny)); + else + iy = biny; + for (binx = 0; binx <= nx + 1; binx++) { + bin = binx +(nx+2)*biny; + + cu = h->RetrieveBinContent(bin); + if (!allSameLimits) { + if (cu != 0 && ( (!sameLimitsX && (binx == 0 || binx == nx+1)) || (!sameLimitsY && (biny == 0 || biny == ny+1)) )) { + Error("Merge", "Cannot merge histograms - the histograms have" + " different limits and undeflows/overflows are present." + " The initial histogram is now broken!"); + return -1; + } + ix = fXaxis.FindBin(h->GetXaxis()->GetBinCenter(binx)); + } + else { + // case histograms with the same limits + ix = binx; + } + ibin = ix +(nbix+2)*iy; + + if (ibin < 0) continue; + AddBinContent(ibin,cu); + if (fSumw2.fN) { + Double_t error1 = h->GetBinError(bin); + fSumw2.fArray[ibin] += error1*error1; + } + } + } + } + } + SetCanExtend(canExtend); + + //copy merged stats + PutStats(totstats); + SetEntries(nentries); + if (hclone) { + inlist.Remove(hclone); + delete hclone; + } + return (Long64_t)nentries; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Rebin only the X axis +/// see Rebin2D + +GH2 *GH2::RebinX(Int_t ngroup, const char *newname) +{ + return Rebin2D(ngroup, 1, newname); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Rebin only the Y axis +/// see Rebin2D + +GH2 *GH2::RebinY(Int_t ngroup, const char *newname) +{ + return Rebin2D(1, ngroup, newname); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Rebin this histogram grouping nxgroup/nygroup bins along the xaxis/yaxis together. +/// +/// if newname is not blank a new temporary histogram hnew is created. +/// else the current histogram is modified (default) +/// The parameter nxgroup/nygroup indicate how many bins along the xaxis/yaxis of this +/// have to me merged into one bin of hnew +/// If the original histogram has errors stored (via Sumw2), the resulting +/// histograms has new errors correctly calculated. +/// +/// examples: if hpxpy is an existing GH2 histogram with 40 x 40 bins +/// hpxpy->Rebin2D(); // merges two bins along the xaxis and yaxis in one in hpxpy +/// // Carefull: previous contents of hpxpy are lost +/// hpxpy->RebinX(5); //merges five bins along the xaxis in one in hpxpy +/// GH2 *hnew = hpxpy->RebinY(5,"hnew"); // creates a new histogram hnew +/// // merging 5 bins of h1 along the yaxis in one bin +/// +/// NOTE : If nxgroup/nygroup is not an exact divider of the number of bins, +/// along the xaxis/yaxis the top limit(s) of the rebinned histogram +/// is changed to the upper edge of the xbin=newxbins*nxgroup resp. +/// ybin=newybins*nygroup and the corresponding bins are added to +/// the overflow bin. +/// Statistics will be recomputed from the new bin contents. + +GH2 *GH2::Rebin2D(Int_t nxgroup, Int_t nygroup, const char *newname) +{ + Int_t nxbins = fXaxis.GetNbins(); + Int_t nybins = fYaxis.GetNbins(); + Int_t nx = nxbins + 2; // normal bins + underflow and overflow + Int_t ny = nybins + 2; + Double_t xmin = fXaxis.GetXmin(); + Double_t xmax = fXaxis.GetXmax(); + Double_t ymin = fYaxis.GetXmin(); + Double_t ymax = fYaxis.GetXmax(); + + if (GetDimension() != 2) { + Error("Rebin2D", "Histogram must be GH2. This histogram has %d dimensions.", GetDimension()); + return 0; + } + if ((nxgroup <= 0) || (nxgroup > nxbins)) { + Error("Rebin2D", "Illegal value of nxgroup=%d",nxgroup); + return 0; + } + if ((nygroup <= 0) || (nygroup > nybins)) { + Error("Rebin2D", "Illegal value of nygroup=%d",nygroup); + return 0; + } + + Int_t newxbins = nxbins / nxgroup; + Int_t newybins = nybins / nygroup; + Int_t newnx = newxbins + 2; // regular bins + overflow / underflow + Int_t newny = newybins + 2; // regular bins + overflow / underflow + + // Save old bin contents into a new array + Double_t *oldBins = new Double_t[fNcells]; + for (Int_t i = 0; i < fNcells; ++i) oldBins[i] = RetrieveBinContent(i); + + Double_t* oldErrors = NULL; + if (fSumw2.fN) { + oldErrors = new Double_t[fNcells]; + for (Int_t i = 0; i < fNcells; ++i) oldErrors[i] = GetBinErrorSqUnchecked(i); + } + + // create a clone of the old histogram if newname is specified + GH2* hnew = this; + if (newname && strlen(newname)) { + hnew = (GH2*)Clone(); + hnew->SetName(newname); + } + + bool resetStat = false; + + // change axis specs and rebuild bin contents array + if(newxbins * nxgroup != nxbins) { + xmax = fXaxis.GetBinUpEdge(newxbins * nxgroup); + resetStat = true; // stats must be reset because top bins will be moved to overflow bin + } + if(newybins * nygroup != nybins) { + ymax = fYaxis.GetBinUpEdge(newybins * nygroup); + resetStat = true; // stats must be reset because top bins will be moved to overflow bin + } + + // save the TAttAxis members (reset by SetBins) for x axis + Int_t nXdivisions = fXaxis.GetNdivisions(); + Color_t xAxisColor = fXaxis.GetAxisColor(); + Color_t xLabelColor = fXaxis.GetLabelColor(); + Style_t xLabelFont = fXaxis.GetLabelFont(); + Float_t xLabelOffset = fXaxis.GetLabelOffset(); + Float_t xLabelSize = fXaxis.GetLabelSize(); + Float_t xTickLength = fXaxis.GetTickLength(); + Float_t xTitleOffset = fXaxis.GetTitleOffset(); + Float_t xTitleSize = fXaxis.GetTitleSize(); + Color_t xTitleColor = fXaxis.GetTitleColor(); + Style_t xTitleFont = fXaxis.GetTitleFont(); + // save the TAttAxis members (reset by SetBins) for y axis + Int_t nYdivisions = fYaxis.GetNdivisions(); + Color_t yAxisColor = fYaxis.GetAxisColor(); + Color_t yLabelColor = fYaxis.GetLabelColor(); + Style_t yLabelFont = fYaxis.GetLabelFont(); + Float_t yLabelOffset = fYaxis.GetLabelOffset(); + Float_t yLabelSize = fYaxis.GetLabelSize(); + Float_t yTickLength = fYaxis.GetTickLength(); + Float_t yTitleOffset = fYaxis.GetTitleOffset(); + Float_t yTitleSize = fYaxis.GetTitleSize(); + Color_t yTitleColor = fYaxis.GetTitleColor(); + Style_t yTitleFont = fYaxis.GetTitleFont(); + + + // copy merged bin contents (ignore under/overflows) + if (nxgroup != 1 || nygroup != 1) { + if(fXaxis.GetXbins()->GetSize() > 0 || fYaxis.GetXbins()->GetSize() > 0){ + // variable bin sizes in x or y, don't treat both cases separately + Double_t *xbins = new Double_t[newxbins + 1]; + for(Int_t i = 0; i <= newxbins; ++i) xbins[i] = fXaxis.GetBinLowEdge(1 + i * nxgroup); + Double_t *ybins = new Double_t[newybins + 1]; + for(Int_t i = 0; i <= newybins; ++i) ybins[i] = fYaxis.GetBinLowEdge(1 + i * nygroup); + hnew->SetBins(newxbins, xbins, newybins, ybins); // changes also errors array (if any) + delete [] xbins; + delete [] ybins; + } else { + hnew->SetBins(newxbins, xmin, xmax, newybins, ymin, ymax); //changes also errors array + } + + // (0, 0): x - underflow; y - underflow + hnew->UpdateBinContent(0, oldBins[0]); + if (oldErrors) hnew->fSumw2[0] = 0; + + // (x, 0): x - regular / overflow; y - underflow + for(Int_t binx = 1, oldbinx = 1; binx < newnx; ++binx, oldbinx += nxgroup){ + Double_t binContent = 0.0, binErrorSq = 0.0; + for (Int_t i = 0; i < nxgroup && (oldbinx + i) < nx; ++i) { + Int_t bin = oldbinx + i; + binContent += oldBins[bin]; + if(oldErrors) binErrorSq += oldErrors[bin]; + } + Int_t newbin = binx; + hnew->UpdateBinContent(newbin, binContent); + if (oldErrors) hnew->fSumw2[newbin] = binErrorSq; + } + + // (0, y): x - underflow; y - regular / overflow + for(Int_t biny = 1, oldbiny = 1; biny < newny; ++biny, oldbiny += nygroup){ + Double_t binContent = 0.0, binErrorSq = 0.0; + for (Int_t j = 0; j < nygroup && (oldbiny + j) < ny; ++j) { + Int_t bin = (oldbiny + j) * nx; + binContent += oldBins[bin]; + if(oldErrors) binErrorSq += oldErrors[bin]; + } + Int_t newbin = biny * newnx; + hnew->UpdateBinContent(newbin, binContent); + if (oldErrors) hnew->fSumw2[newbin] = binErrorSq; + } + + // (x, y): x - regular / overflow; y - regular / overflow + for (Int_t binx = 1, oldbinx = 1; binx < newnx; ++binx, oldbinx += nxgroup) { + for (Int_t biny = 1, oldbiny = 1; biny < newny; ++biny, oldbiny += nygroup) { + Double_t binContent = 0.0, binErrorSq = 0.0; + for (Int_t i = 0; i < nxgroup && (oldbinx + i) < nx; ++i) { + for (Int_t j = 0; j < nygroup && (oldbiny + j) < ny; ++j) { + Int_t bin = oldbinx + i + (oldbiny + j) * nx; + binContent += oldBins[bin]; + if (oldErrors) binErrorSq += oldErrors[bin]; + } + } + Int_t newbin = binx + biny * newnx; + hnew->UpdateBinContent(newbin, binContent); + if (oldErrors) hnew->fSumw2[newbin] = binErrorSq; + } + } + } + + // Restore x axis attributes + fXaxis.SetNdivisions(nXdivisions); + fXaxis.SetAxisColor(xAxisColor); + fXaxis.SetLabelColor(xLabelColor); + fXaxis.SetLabelFont(xLabelFont); + fXaxis.SetLabelOffset(xLabelOffset); + fXaxis.SetLabelSize(xLabelSize); + fXaxis.SetTickLength(xTickLength); + fXaxis.SetTitleOffset(xTitleOffset); + fXaxis.SetTitleSize(xTitleSize); + fXaxis.SetTitleColor(xTitleColor); + fXaxis.SetTitleFont(xTitleFont); + // Restore y axis attributes + fYaxis.SetNdivisions(nYdivisions); + fYaxis.SetAxisColor(yAxisColor); + fYaxis.SetLabelColor(yLabelColor); + fYaxis.SetLabelFont(yLabelFont); + fYaxis.SetLabelOffset(yLabelOffset); + fYaxis.SetLabelSize(yLabelSize); + fYaxis.SetTickLength(yTickLength); + fYaxis.SetTitleOffset(yTitleOffset); + fYaxis.SetTitleSize(yTitleSize); + fYaxis.SetTitleColor(yTitleColor); + fYaxis.SetTitleFont(yTitleFont); + + if (resetStat) hnew->ResetStats(); + + delete [] oldBins; + if (oldErrors) delete [] oldErrors; + return hnew; +} + + +//////////////////////////////////////////////////////////////////////////////// + +TProfile *GH2::DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const +{ + TString opt = option; + // extract cut infor + TString cut; + Int_t i1 = opt.Index("["); + if (i1>=0) { + Int_t i2 = opt.Index("]"); + cut = opt(i1,i2-i1+1); + } + opt.ToLower(); + bool originalRange = opt.Contains("o"); + + const TAxis& outAxis = ( onX ? fXaxis : fYaxis ); + const TAxis& inAxis = ( onX ? fYaxis : fXaxis ); + Int_t inN = inAxis.GetNbins(); + const char *expectedName = ( onX ? "_pfx" : "_pfy" ); + + Int_t firstOutBin, lastOutBin; + firstOutBin = outAxis.GetFirst(); + lastOutBin = outAxis.GetLast(); + if (firstOutBin == 0 && lastOutBin == 0) { + firstOutBin = 1; lastOutBin = outAxis.GetNbins(); + } + + if ( lastbin < firstbin && inAxis.TestBit(TAxis::kAxisRange) ) { + firstbin = inAxis.GetFirst(); + lastbin = inAxis.GetLast(); + // For special case of TAxis::SetRange, when first == 1 and last + // = N and the range bit has been set, the TAxis will return 0 + // for both. + if (firstbin == 0 && lastbin == 0) + { + firstbin = 1; + lastbin = inAxis.GetNbins(); + } + } + if (firstbin < 0) firstbin = 1; + if (lastbin < 0) lastbin = inN; + if (lastbin > inN+1) lastbin = inN; + + // Create the profile histogram + char *pname = (char*)name; + if (name && strcmp(name, expectedName) == 0) { + Int_t nch = strlen(GetName()) + 5; + pname = new char[nch]; + snprintf(pname,nch,"%s%s",GetName(),name); + } + TProfile *h1=0; + //check if a profile with identical name exist + // if compatible reset and re-use previous histogram + TObject *h1obj = gROOT->FindObject(pname); + if (h1obj && h1obj->InheritsFrom(GH1::Class())) { + if (h1obj->IsA() != TProfile::Class() ) { + Error("DoProfile","Histogram with name %s must be a TProfile and is a %s",name,h1obj->ClassName()); + return 0; + } + h1 = (TProfile*)h1obj; + // reset the existing histogram and set always the new binning for the axis + // This avoid problems when the histogram already exists and the histograms is rebinned or its range has changed + // (see https://savannah.cern.ch/bugs/?94101 or https://savannah.cern.ch/bugs/?95808 ) + h1->Reset(); + const TArrayD *xbins = outAxis.GetXbins(); + if (xbins->fN == 0) { + if ( originalRange ) + h1->SetBins(outAxis.GetNbins(),outAxis.GetXmin(),outAxis.GetXmax()); + else + h1->SetBins(lastOutBin-firstOutBin+1,outAxis.GetBinLowEdge(firstOutBin),outAxis.GetBinUpEdge(lastOutBin)); + } else { + // case variable bins + if (originalRange ) + h1->SetBins(outAxis.GetNbins(),xbins->fArray); + else + h1->SetBins(lastOutBin-firstOutBin+1,&xbins->fArray[firstOutBin-1]); + } + } + + Int_t ncuts = 0; + if (opt.Contains("[")) { + ((GH2 *)this)->GetPainter(); + if (fPainter) ncuts = fPainter->MakeCuts((char*)cut.Data()); + } + + if (!h1) { + const TArrayD *bins = outAxis.GetXbins(); + if (bins->fN == 0) { + if ( originalRange ) + h1 = new TProfile(pname,GetTitle(),outAxis.GetNbins(),outAxis.GetXmin(),outAxis.GetXmax(),opt); + else + h1 = new TProfile(pname,GetTitle(),lastOutBin-firstOutBin+1, + outAxis.GetBinLowEdge(firstOutBin), + outAxis.GetBinUpEdge(lastOutBin), opt); + } else { + // case variable bins + if (originalRange ) + h1 = new TProfile(pname,GetTitle(),outAxis.GetNbins(),bins->fArray,opt); + else + h1 = new TProfile(pname,GetTitle(),lastOutBin-firstOutBin+1,&bins->fArray[firstOutBin-1],opt); + } + } + if (pname != name) delete [] pname; + + // Copy attributes + h1->GetXaxis()->ImportAttributes( &outAxis); + h1->SetLineColor(this->GetLineColor()); + h1->SetFillColor(this->GetFillColor()); + h1->SetMarkerColor(this->GetMarkerColor()); + h1->SetMarkerStyle(this->GetMarkerStyle()); + + // check if histogram is weighted + // in case need to store sum of weight square/bin for the profile + bool useWeights = (GetSumw2N() > 0); + if (useWeights) h1->Sumw2(); + // we need to set this bit because we fill the profile using a single Fill for many entries + // This is needed for the changes applied to make automaticall y hthe histogram weighted in ROOT 6 versions + else h1->SetBit(GH1::kIsNotW); + + // Fill the profile histogram + // no entries/bin is available so can fill only using bin content as weight + Double_t totcont = 0; + TArrayD & binSumw2 = *(h1->GetBinSumw2()); + + // implement filling of projected histogram + // outbin is bin number of outAxis (the projected axis). Loop is done on all bin of GH2 histograms + // inbin is the axis being integrated. Loop is done only on the selected bins + for ( Int_t outbin = 0; outbin <= outAxis.GetNbins() + 1; ++outbin) { + if (outAxis.TestBit(TAxis::kAxisRange) && ( outbin < firstOutBin || outbin > lastOutBin )) continue; + + // find corresponding bin number in h1 for outbin (binOut) + Double_t xOut = outAxis.GetBinCenter(outbin); + Int_t binOut = h1->GetXaxis()->FindBin( xOut ); + if (binOut <0) continue; + + for (Int_t inbin = firstbin ; inbin <= lastbin ; ++inbin) { + Int_t binx, biny; + if (onX) { binx = outbin; biny=inbin; } + else { binx = inbin; biny=outbin; } + + if (ncuts) { + if (!fPainter->IsInside(binx,biny)) continue; + } + Int_t bin = GetBin(binx, biny); + Double_t cxy = RetrieveBinContent(bin); + + + if (cxy) { + Double_t tmp = 0; + // the following fill update wrongly the fBinSumw2- need to save it before + if ( useWeights ) tmp = binSumw2.fArray[binOut]; + h1->Fill( xOut, inAxis.GetBinCenter(inbin), cxy ); + if ( useWeights ) binSumw2.fArray[binOut] = tmp + fSumw2.fArray[bin]; + totcont += cxy; + } + + } + } + + // the statistics must be recalculated since by using the Fill method the total sum of weight^2 is + // not computed correctly + // for a profile does not much sense to re-use statistics of original GH2 + h1->ResetStats(); + // Also we need to set the entries since they have not been correctly calculated during the projection + // we can only set them to the effective entries + h1->SetEntries( h1->GetEffectiveEntries() ); + + + if (opt.Contains("d")) { + TVirtualPad *padsav = gPad; + TVirtualPad *pad = gROOT->GetSelectedPad(); + if (pad) pad->cd(); + opt.Remove(opt.First("d"),1); + if (!gPad || !gPad->FindObject(h1)) { + h1->Draw(opt); + } else { + h1->Paint(opt); + } + if (padsav) padsav->cd(); + } + return h1; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Project a 2-D histogram into a profile histogram along X. +/// +/// The projection is made from the channels along the Y axis +/// ranging from firstybin to lastybin included. +/// By default, bins 1 to ny are included +/// When all bins are included, the number of entries in the projection +/// is set to the number of entries of the 2-D histogram, otherwise +/// the number of entries is incremented by 1 for all non empty cells. +/// +/// if option "d" is specified, the profile is drawn in the current pad. +/// +/// if option "o" original axis range of the target axes will be +/// kept, but only bins inside the selected range will be filled. +/// +/// The option can also be used to specify the projected profile error type. +/// Values which can be used are 's', 'i', or 'g'. See TProfile::BuildOptions for details +/// +/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram. +/// One must create a graphical cut (mouse or C++) and specify the name +/// of the cut between [] in the option. +/// For example, with a TCutG named "cutg", one can call: +/// myhist->ProfileX(" ",firstybin,lastybin,"[cutg]"); +/// To invert the cut, it is enough to put a "-" in front of its name: +/// myhist->ProfileX(" ",firstybin,lastybin,"[-cutg]"); +/// It is possible to apply several cuts ("," means logical AND): +/// myhist->ProfileX(" ",firstybin,lastybin,"[cutg1,cutg2]"); +/// +/// NOTE that if a TProfile named "name" exists in the current directory or pad with +/// a compatible axis the profile is reset and filled again with the projected contents of the GH2. +/// In the case of axis incompatibility an error is reported and a NULL pointer is returned. +/// +/// NOTE that the X axis attributes of the GH2 are copied to the X axis of the profile. +/// +/// NOTE that the default under- / overflow behavior differs from what ProjectionX +/// does! Profiles take the bin center into account, so here the under- and overflow +/// bins are ignored by default. + +TProfile *GH2::ProfileX(const char *name, Int_t firstybin, Int_t lastybin, Option_t *option) const +{ + return DoProfile(true, name, firstybin, lastybin, option); + +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Project a 2-D histogram into a profile histogram along Y. +/// +/// The projection is made from the channels along the X axis +/// ranging from firstxbin to lastxbin included. +/// By default, bins 1 to nx are included +/// When all bins are included, the number of entries in the projection +/// is set to the number of entries of the 2-D histogram, otherwise +/// the number of entries is incremented by 1 for all non empty cells. +/// +/// if option "d" is specified, the profile is drawn in the current pad. +/// +/// if option "o" , the original axis range of the target axis will be +/// kept, but only bins inside the selected range will be filled. +/// +/// The option can also be used to specify the projected profile error type. +/// Values which can be used are 's', 'i', or 'g'. See TProfile::BuildOptions for details +/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram. +/// +/// One must create a graphical cut (mouse or C++) and specify the name +/// of the cut between [] in the option. +/// For example, with a TCutG named "cutg", one can call: +/// myhist->ProfileY(" ",firstybin,lastybin,"[cutg]"); +/// To invert the cut, it is enough to put a "-" in front of its name: +/// myhist->ProfileY(" ",firstybin,lastybin,"[-cutg]"); +/// It is possible to apply several cuts: +/// myhist->ProfileY(" ",firstybin,lastybin,"[cutg1,cutg2]"); +/// +/// NOTE that if a TProfile named "name" exists in the current directory or pad with +/// a compatible axis the profile is reset and filled again with the projected contents of the GH2. +/// In the case of axis incompatibility an error is reported and a NULL pointer is returned. +/// +/// NOTE that the Y axis attributes of the GH2 are copied to the X axis of the profile. +/// +/// NOTE that the default under- / overflow behavior differs from what ProjectionX +/// does! Profiles take the bin center into account, so here the under- and overflow +/// bins are ignored by default. + +TProfile *GH2::ProfileY(const char *name, Int_t firstxbin, Int_t lastxbin, Option_t *option) const +{ + return DoProfile(false, name, firstxbin, lastxbin, option); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Internal (protected) method for performing projection on the X or Y axis +/// called by ProjectionX or ProjectionY + +GH1D *GH2::DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbin, Option_t *option) const +{ + const char *expectedName = 0; + Int_t inNbin; + Int_t firstOutBin, lastOutBin; + const TAxis* outAxis; + const TAxis* inAxis; + + TString opt = option; + TString cut; + Int_t i1 = opt.Index("["); + if (i1>=0) { + Int_t i2 = opt.Index("]"); + cut = opt(i1,i2-i1+1); + } + opt.ToLower(); //must be called after having parsed the cut name + bool originalRange = opt.Contains("o"); + + if ( onX ) + { + expectedName = "_px"; + inNbin = fYaxis.GetNbins(); + outAxis = GetXaxis(); + inAxis = GetYaxis(); + } + else + { + expectedName = "_py"; + inNbin = fXaxis.GetNbins(); + outAxis = GetYaxis(); + inAxis = GetXaxis(); + } + + firstOutBin = outAxis->GetFirst(); + lastOutBin = outAxis->GetLast(); + if (firstOutBin == 0 && lastOutBin == 0) { + firstOutBin = 1; lastOutBin = outAxis->GetNbins(); + } + + if ( lastbin < firstbin && inAxis->TestBit(TAxis::kAxisRange) ) { + firstbin = inAxis->GetFirst(); + lastbin = inAxis->GetLast(); + // For special case of TAxis::SetRange, when first == 1 and last + // = N and the range bit has been set, the TAxis will return 0 + // for both. + if (firstbin == 0 && lastbin == 0) + { + firstbin = 1; + lastbin = inAxis->GetNbins(); + } + } + if (firstbin < 0) firstbin = 0; + if (lastbin < 0) lastbin = inNbin + 1; + if (lastbin > inNbin+1) lastbin = inNbin + 1; + + // Create the projection histogram + char *pname = (char*)name; + if (name && strcmp(name,expectedName) == 0) { + Int_t nch = strlen(GetName()) + 4; + pname = new char[nch]; + snprintf(pname,nch,"%s%s",GetName(),name); + } + GH1D *h1=0; + //check if histogram with identical name exist + // if compatible reset and re-use previous histogram + // (see https://savannah.cern.ch/bugs/?54340) + TObject *h1obj = gROOT->FindObject(pname); + if (h1obj && h1obj->InheritsFrom(GH1::Class())) { + if (h1obj->IsA() != GH1D::Class() ) { + Error("DoProjection","Histogram with name %s must be a GH1D and is a %s",name,h1obj->ClassName()); + return 0; + } + h1 = (GH1D*)h1obj; + // reset the existing histogram and set always the new binning for the axis + // This avoid problems when the histogram already exists and the histograms is rebinned or its range has changed + // (see https://savannah.cern.ch/bugs/?94101 or https://savannah.cern.ch/bugs/?95808 ) + h1->Reset(); + const TArrayD *xbins = outAxis->GetXbins(); + if (xbins->fN == 0) { + if ( originalRange ) + h1->SetBins(outAxis->GetNbins(),outAxis->GetXmin(),outAxis->GetXmax()); + else + h1->SetBins(lastOutBin-firstOutBin+1,outAxis->GetBinLowEdge(firstOutBin),outAxis->GetBinUpEdge(lastOutBin)); + } else { + // case variable bins + if (originalRange ) + h1->SetBins(outAxis->GetNbins(),xbins->fArray); + else + h1->SetBins(lastOutBin-firstOutBin+1,&xbins->fArray[firstOutBin-1]); + } + } + + Int_t ncuts = 0; + if (opt.Contains("[")) { + ((GH2 *)this)->GetPainter(); + if (fPainter) ncuts = fPainter->MakeCuts((char*)cut.Data()); + } + + if (!h1) { + const TArrayD *bins = outAxis->GetXbins(); + if (bins->fN == 0) { + if ( originalRange ) + h1 = new GH1D(pname,GetTitle(),outAxis->GetNbins(),outAxis->GetXmin(),outAxis->GetXmax()); + else + h1 = new GH1D(pname,GetTitle(),lastOutBin-firstOutBin+1, + outAxis->GetBinLowEdge(firstOutBin),outAxis->GetBinUpEdge(lastOutBin)); + } else { + // case variable bins + if (originalRange ) + h1 = new GH1D(pname,GetTitle(),outAxis->GetNbins(),bins->fArray); + else + h1 = new GH1D(pname,GetTitle(),lastOutBin-firstOutBin+1,&bins->fArray[firstOutBin-1]); + } + if (opt.Contains("e") || GetSumw2N() ) h1->Sumw2(); + } + if (pname != name) delete [] pname; + + // Copy the axis attributes and the axis labels if needed. + h1->GetXaxis()->ImportAttributes(outAxis); + THashList* labels=outAxis->GetLabels(); + if (labels) { + TIter iL(labels); + TObjString* lb; + Int_t i = 1; + while ((lb=(TObjString*)iL())) { + h1->GetXaxis()->SetBinLabel(i,lb->String().Data()); + i++; + } + } + + h1->SetLineColor(this->GetLineColor()); + h1->SetFillColor(this->GetFillColor()); + h1->SetMarkerColor(this->GetMarkerColor()); + h1->SetMarkerStyle(this->GetMarkerStyle()); + + // Fill the projected histogram + Double_t cont,err2; + Double_t totcont = 0; + Bool_t computeErrors = h1->GetSumw2N(); + + // implement filling of projected histogram + // outbin is bin number of outAxis (the projected axis). Loop is done on all bin of GH2 histograms + // inbin is the axis being integrated. Loop is done only on the selected bins + for ( Int_t outbin = 0; outbin <= outAxis->GetNbins() + 1; ++outbin) { + err2 = 0; + cont = 0; + if (outAxis->TestBit(TAxis::kAxisRange) && ( outbin < firstOutBin || outbin > lastOutBin )) continue; + + for (Int_t inbin = firstbin ; inbin <= lastbin ; ++inbin) { + Int_t binx, biny; + if (onX) { binx = outbin; biny=inbin; } + else { binx = inbin; biny=outbin; } + + if (ncuts) { + if (!fPainter->IsInside(binx,biny)) continue; + } + // sum bin content and error if needed + cont += GetBinContent(binx,biny); + if (computeErrors) { + Double_t exy = GetBinError(binx,biny); + err2 += exy*exy; + } + } + // find corresponding bin number in h1 for outbin + Int_t binOut = h1->GetXaxis()->FindBin( outAxis->GetBinCenter(outbin) ); + h1->SetBinContent(binOut ,cont); + if (computeErrors) h1->SetBinError(binOut,TMath::Sqrt(err2)); + // sum all content + totcont += cont; + } + + // check if we can re-use the original statistics from the previous histogram + bool reuseStats = false; + if ( ( fgStatOverflows == false && firstbin == 1 && lastbin == inNbin ) || + ( fgStatOverflows == true && firstbin == 0 && lastbin == inNbin + 1 ) ) + reuseStats = true; + else { + // also if total content match we can re-use + double eps = 1.E-12; + //if (IsA() == GH2F::Class() ) eps = 1.E-6; //gh2f doesn't exist yet, pcb. + if (fTsumw != 0 && TMath::Abs( fTsumw - totcont) < TMath::Abs(fTsumw) * eps) + reuseStats = true; + } + if (ncuts) reuseStats = false; + // retrieve the statistics and set in projected histogram if we can re-use it + bool reuseEntries = reuseStats; + // can re-use entries if underflow/overflow are included + reuseEntries &= (firstbin==0 && lastbin == inNbin+1); + if (reuseStats) { + Double_t stats[kNstat]; + GetStats(stats); + if (!onX) { // case of projection on Y + stats[2] = stats[4]; + stats[3] = stats[5]; + } + h1->PutStats(stats); + } + else { + // the statistics is automatically recalulated since it is reset by the call to SetBinContent + // we just need to set the entries since they have not been correctly calculated during the projection + // we can only set them to the effective entries + h1->SetEntries( h1->GetEffectiveEntries() ); + } + if (reuseEntries) { + h1->SetEntries(fEntries); + } + else { + // re-compute the entries + // in case of error calculation (i.e. when Sumw2() is set) + // use the effective entries for the entries + // since this is the only way to estimate them + Double_t entries = TMath::Floor( totcont + 0.5); // to avoid numerical rounding + if (h1->GetSumw2N()) entries = h1->GetEffectiveEntries(); + h1->SetEntries( entries ); + } + + if (opt.Contains("d")) { + TVirtualPad *padsav = gPad; + TVirtualPad *pad = gROOT->GetSelectedPad(); + if (pad) pad->cd(); + opt.Remove(opt.First("d"),1); + // remove also other options + if (opt.Contains("e")) opt.Remove(opt.First("e"),1); + if (!gPad || !gPad->FindObject(h1)) { + h1->Draw(opt); + } else { + h1->Paint(opt); + } + if (padsav) padsav->cd(); + } + + return h1; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Project a 2-D histogram into a 1-D histogram along X. +/// +/// The projection is always of the type GH1D. +/// The projection is made from the channels along the Y axis +/// ranging from firstybin to lastybin included. +/// By default, all bins including under- and overflow are included. +/// The number of entries in the projection is estimated from the +/// number of effective entries for all the cells included in the projection. +/// +/// To exclude the underflow bins in Y, use firstybin=1. +/// To exclude the overflow bins in Y, use lastybin=nx. +/// +/// if option "e" is specified, the errors are computed. +/// if option "d" is specified, the projection is drawn in the current pad. +/// if option "o" original axis range of the taget axes will be +/// kept, but only bins inside the selected range will be filled. +/// +/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram. +/// One must create a graphical cut (mouse or C++) and specify the name +/// of the cut between [] in the option. +/// For example, with a TCutG named "cutg", one can call: +/// myhist->ProjectionX(" ",firstybin,lastybin,"[cutg]"); +/// To invert the cut, it is enough to put a "-" in front of its name: +/// myhist->ProjectionX(" ",firstybin,lastybin,"[-cutg]"); +/// It is possible to apply several cuts: +/// myhist->ProjectionX(" ",firstybin,lastybin,"[cutg1,cutg2]"); +/// +/// NOTE that if a GH1D named "name" exists in the current directory or pad +/// the histogram is reset and filled again with the projected contents of the GH2. +/// +/// NOTE that the X axis attributes of the GH2 are copied to the X axis of the projection. + +GH1D *GH2::ProjectionX(const char *name, Int_t firstybin, Int_t lastybin, Option_t *opt) const +{ + std::string title; + TString options(opt); + options.ToLower(); + bool add_to_proj_list = options.Contains("+"); + if(add_to_proj_list) options.ReplaceAll("+",""); + bool keep = options.Contains("keep"); + if(add_to_proj_list) options.ReplaceAll("keep",""); + + double xlow = fYaxis.GetBinLowEdge(firstybin); + double xhigh = fYaxis.GetBinUpEdge(lastybin); + bool total = false; + if(firstybin==0 && lastybin==-1){ + total = true; + title = Form("%s_totalx",GetName()); + } else { + title = Form("%s_px_%d[%.02f]_%d[%.02f]",GetName(), + firstybin,xlow,lastybin,xhigh); + } + std::string actual_name = name; + if( !actual_name.compare("_px") || !actual_name.length()){ + if(total) + actual_name = title; + else + actual_name = Form("%s_px_%d_%d",GetName(),firstybin,lastybin); + } + GH1D *project = DoProjection(true, actual_name.c_str(), firstybin, lastybin, options.Data()); + project->SetNameTitle(actual_name.c_str(),title.c_str()); + //project->SetProjectionAxis(kXaxis); + + if(add_to_proj_list) { + if(project->Integral()>0 || keep) { + project->SetParent((TObject*)this); + AddToProjections(project); + } + } + + project->SetProjectionAxis(GH1::kXaxis); + return project; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Project a 2-D histogram into a 1-D histogram along Y. +/// +/// The projection is always of the type GH1D. +/// The projection is made from the channels along the X axis +/// ranging from firstxbin to lastxbin included. +/// By default, all bins including under- and overflow are included. +/// The number of entries in the projection is estimated from the +/// number of effective entries for all the cells included in the projection +/// +/// To exclude the underflow bins in X, use firstxbin=1. +/// To exclude the oveerflow bins in X, use lastxbin=nx. +/// +/// if option "e" is specified, the errors are computed. +/// if option "d" is specified, the projection is drawn in the current pad. +/// if option "o" original axis range of the taget axes will be +/// kept, but only bins inside the selected range will be filled. +/// +/// Using a TCutG object, it is possible to select a sub-range of a 2-D histogram. +/// One must create a graphical cut (mouse or C++) and specify the name +/// of the cut between [] in the option. +/// For example, with a TCutG named "cutg", one can call: +/// myhist->ProjectionY(" ",firstxbin,lastxbin,"[cutg]"); +/// To invert the cut, it is enough to put a "-" in front of its name: +/// myhist->ProjectionY(" ",firstxbin,lastxbin,"[-cutg]"); +/// It is possible to apply several cuts: +/// myhist->ProjectionY(" ",firstxbin,lastxbin,"[cutg1,cutg2]"); +/// +/// NOTE that if a GH1D named "name" exists in the current directory or pad and having +/// a compatible axis, the histogram is reset and filled again with the projected contents of the GH2. +/// In the case of axis incompatibility, an error is reported and a NULL pointer is returned. +/// +/// NOTE that the Y axis attributes of the GH2 are copied to the X axis of the projection. + +GH1D *GH2::ProjectionY(const char *name, Int_t firstxbin, Int_t lastxbin, Option_t *opt) const +{ + std::string title; + TString options(opt); + options.ToLower(); + bool add_to_proj_list = options.Contains("+"); + if(add_to_proj_list) options.ReplaceAll("+",""); + bool keep = options.Contains("keep"); + if(add_to_proj_list) options.ReplaceAll("keep",""); + + double xlow = fXaxis.GetBinLowEdge(firstxbin); + double xhigh = fXaxis.GetBinUpEdge(lastxbin); + bool total = false; + if(firstxbin==0 && lastxbin==-1){ + total = true; + title = Form("%s_totaly",GetName()); + } else { + title = Form("%s_py_%d[%.02f]_%d[%.02f]",GetName(), + firstxbin,xlow,lastxbin,xhigh); + } + std::string actual_name = name; + if(!actual_name.compare("_py") || !actual_name.length()){ + if(total) + actual_name = title; + else + actual_name = Form("%s_py_%d_%d",GetName(),firstxbin,lastxbin); + } + GH1D *project = DoProjection(false, actual_name.c_str(), firstxbin, lastxbin, options.Data()); + project->SetNameTitle(actual_name.c_str(),title.c_str()); + //project->SetProjectionAxis(kXaxis); + if(add_to_proj_list) { + if(project->Integral()>0 || keep) { + project->SetParent((TObject*)this); + AddToProjections(project); + } + } + + project->SetProjectionAxis(GH1::kYaxis); + return project; + //return DoProjection(false, name, firstxbin, lastxbin, option); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Replace current statistics with the values in array stats + +void GH2::PutStats(Double_t *stats) +{ + GH1::PutStats(stats); + fTsumwy = stats[4]; + fTsumwy2 = stats[5]; + fTsumwxy = stats[6]; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Compute the X distribution of quantiles in the other variable Y +/// name is the name of the returned histogram +/// prob is the probability content for the quantile (0.5 is the default for the median) +/// An approximate error for the quantile is computed assuming that the distribution in +/// the other variable is normal. + +GH1D* GH2::QuantilesX( Double_t prob, const char * name) const +{ + return DoQuantiles(true, name, prob); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Compute the Y distribution of quantiles in the other variable X +/// name is the name of the returned histogram +/// prob is the probability content for the quantile (0.5 is the default for the median) +/// An approximate error for the quantile is computed assuming that the distribution in +/// the other variable is normal. + +GH1D* GH2::QuantilesY( Double_t prob, const char * name) const +{ + return DoQuantiles(false, name, prob); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Implementation of quantiles for x or y + +GH1D* GH2::DoQuantiles(bool onX, const char * name, Double_t prob) const +{ + const TAxis *outAxis = 0; + const TAxis *inAxis = 0; + if ( onX ) { + outAxis = GetXaxis(); + inAxis = GetYaxis(); + } else { + outAxis = GetYaxis(); + inAxis = GetXaxis(); + } + + // build first name of returned histogram + TString qname = name; + if (qname.IsNull() || qname == "_qx" || qname == "_qy") { + const char * qtype = (onX) ? "qx" : "qy"; + qname = TString::Format("%s_%s_%3.2f",GetName(),qtype, prob); + } + // check if the histogram is already existing + GH1D *h1=0; + //check if histogram with identical name exist + TObject *h1obj = gROOT->FindObject(qname); + if (h1obj) { + h1 = dynamic_cast(h1obj); + if (!h1) { + Error("DoQuantiles","Histogram with name %s must be a GH1D and is a %s",qname.Data(),h1obj->ClassName()); + return 0; + } + } + if (h1) { + h1->Reset(); + } else { + // create the histogram + h1 = new GH1D(qname, GetTitle(), 1, 0, 1); + } + // set the bin content + Int_t firstOutBin = outAxis->GetFirst(); + Int_t lastOutBin = outAxis->GetLast(); + const TArrayD *xbins = outAxis->GetXbins(); + if (xbins->fN == 0) + h1->SetBins(lastOutBin-firstOutBin+1,outAxis->GetBinLowEdge(firstOutBin),outAxis->GetBinUpEdge(lastOutBin)); + else + h1->SetBins(lastOutBin-firstOutBin+1,&xbins->fArray[firstOutBin-1]); + + // set the bin content of the histogram + Double_t pp[1]; + pp[0] = prob; + + GH1D * slice = 0; + for (int ibin = inAxis->GetFirst() ; ibin <= inAxis->GetLast() ; ++ibin) { + Double_t qq[1]; + // do a projection on the opposite axis + slice = DoProjection(!onX, "tmp",ibin,ibin,""); + if (!slice) break; + if (slice->GetSum() == 0) continue; + slice->GetQuantiles(1,qq,pp); + h1->SetBinContent(ibin,qq[0]); + // compute error using normal approximation + // quantile error ~ sqrt (q*(1-q)/ *( n * f(xq) ) from Kendall + // where f(xq) is the p.d.f value at the quantile xqp + Double_t n = slice->GetEffectiveEntries(); + Double_t f = TMath::Gaus(qq[0], slice->GetStdDev(), kTRUE); + Double_t error = TMath::Sqrt( prob*(1.-prob)/ ( n * f) ); + h1->SetBinError(ibin, error); + } + if (slice) delete slice; + return h1; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Reset this histogram: contents, errors, etc. + +void GH2::Reset(Option_t *option) +{ + GH1::Reset(option); + TString opt = option; + opt.ToUpper(); + + if (opt.Contains("ICE") && !opt.Contains("S")) return; + fTsumwy = 0; + fTsumwy2 = 0; + fTsumwxy = 0; +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Set bin content + +void GH2::SetBinContent(Int_t bin, Double_t content) +{ + fEntries++; + fTsumw = 0; + if (bin < 0) return; + if (bin >= fNcells) return; + UpdateBinContent(bin, content); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// When the mouse is moved in a pad containing a 2-d view of this histogram +/// a second canvas shows the projection along X corresponding to the +/// mouse position along Y. +/// To stop the generation of the projections, delete the canvas +/// containing the projection. + +void GH2::SetShowProjectionX(Int_t nbins) +{ + GetPainter(); + + if (fPainter) fPainter->SetShowProjection("x",nbins); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// When the mouse is moved in a pad containing a 2-d view of this histogram +/// a second canvas shows the projection along Y corresponding to the +/// mouse position along X. +/// To stop the generation of the projections, delete the canvas +/// containing the projection. + +void GH2::SetShowProjectionY(Int_t nbins) +{ + GetPainter(); + + if (fPainter) fPainter->SetShowProjection("y",nbins); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// This function calculates the background spectrum in this histogram. +/// The background is returned as a histogram. +/// to be implemented (may be) + +GH1 *GH2::ShowBackground(Int_t niter, Option_t *option) +{ + + return (GH1*)gROOT->ProcessLineFast(Form("TSpectrum2::StaticBackground((GH1*)0x%lx,%d,\"%s\")", + (ULong_t)this, niter, option)); +} + + +//////////////////////////////////////////////////////////////////////////////// +///Interface to TSpectrum2::Search +///the function finds peaks in this histogram where the width is > sigma +///and the peak maximum greater than threshold*maximum bin content of this. +///for more detauils see TSpectrum::Search. +///note the difference in the default value for option compared to TSpectrum2::Search +///option="" by default (instead of "goff") + +Int_t GH2::ShowPeaks(Double_t sigma, Option_t *option, Double_t threshold) +{ + + return (Int_t)gROOT->ProcessLineFast(Form("TSpectrum2::StaticSearch((GH1*)0x%lx,%g,\"%s\",%g)", + (ULong_t)this, sigma, option, threshold)); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// Smooth bin contents of this 2-d histogram using kernel algorithms +/// similar to the ones used in the raster graphics community. +/// Bin contents in the active range are replaced by their smooth values. +/// If Errors are defined via Sumw2, they are also scaled and computed. +/// However, note the resulting errors will be correlated between different-bins, so +/// the errors should not be used blindly to perform any calculation involving several bins, +/// like fitting the histogram. One would need to compute also the bin by bin correlation matrix. +/// +/// 3 kernels are proposed k5a, k5b and k3a. +/// k5a and k5b act on 5x5 cells (i-2,i-1,i,i+1,i+2, and same for j) +/// k5b is a bit more stronger in smoothing +/// k3a acts only on 3x3 cells (i-1,i,i+1, and same for j). +/// By default the kernel "k5a" is used. You can select the kernels "k5b" or "k3a" +/// via the option argument. +/// If TAxis::SetRange has been called on the x or/and y axis, only the bins +/// in the specified range are smoothed. +/// In the current implementation if the first argument is not used (default value=1). +/// +/// implementation by David McKee (dmckee@bama.ua.edu). Extended by Rene Brun + +void GH2::Smooth(Int_t ntimes, Option_t *option) +{ + Double_t k5a[5][5] = { { 0, 0, 1, 0, 0 }, + { 0, 2, 2, 2, 0 }, + { 1, 2, 5, 2, 1 }, + { 0, 2, 2, 2, 0 }, + { 0, 0, 1, 0, 0 } }; + Double_t k5b[5][5] = { { 0, 1, 2, 1, 0 }, + { 1, 2, 4, 2, 1 }, + { 2, 4, 8, 4, 2 }, + { 1, 2, 4, 2, 1 }, + { 0, 1, 2, 1, 0 } }; + Double_t k3a[3][3] = { { 0, 1, 0 }, + { 1, 2, 1 }, + { 0, 1, 0 } }; + + if (ntimes > 1) { + Warning("Smooth","Currently only ntimes=1 is supported"); + } + TString opt = option; + opt.ToLower(); + Int_t ksize_x=5; + Int_t ksize_y=5; + Double_t *kernel = &k5a[0][0]; + if (opt.Contains("k5b")) kernel = &k5b[0][0]; + if (opt.Contains("k3a")) { + kernel = &k3a[0][0]; + ksize_x=3; + ksize_y=3; + } + + // find i,j ranges + Int_t ifirst = fXaxis.GetFirst(); + Int_t ilast = fXaxis.GetLast(); + Int_t jfirst = fYaxis.GetFirst(); + Int_t jlast = fYaxis.GetLast(); + + // Determine the size of the bin buffer(s) needed + Double_t nentries = fEntries; + Int_t nx = GetNbinsX(); + Int_t ny = GetNbinsY(); + Int_t bufSize = (nx+2)*(ny+2); + Double_t *buf = new Double_t[bufSize]; + Double_t *ebuf = 0; + if (fSumw2.fN) ebuf = new Double_t[bufSize]; + + // Copy all the data to the temporary buffers + Int_t i,j,bin; + for (i=ifirst; i<=ilast; i++){ + for (j=jfirst; j<=jlast; j++){ + bin = GetBin(i,j); + buf[bin] = RetrieveBinContent(bin); + if (ebuf) ebuf[bin]=GetBinError(bin); + } + } + + // Kernel tail sizes (kernel sizes must be odd for this to work!) + Int_t x_push = (ksize_x-1)/2; + Int_t y_push = (ksize_y-1)/2; + + // main work loop + for (i=ifirst; i<=ilast; i++){ + for (j=jfirst; j<=jlast; j++) { + Double_t content = 0.0; + Double_t error = 0.0; + Double_t norm = 0.0; + + for (Int_t n=0; n= 1) && (xb <= nx) && (yb >= 1) && (yb <= ny) ) { + bin = GetBin(xb,yb); + Double_t k = kernel[n*ksize_y +m]; + //if ( (k != 0.0 ) && (buf[bin] != 0.0) ) { // General version probably does not want the second condition + if ( k != 0.0 ) { + norm += k; + content += k*buf[bin]; + if (ebuf) error += k*k*ebuf[bin]*ebuf[bin]; + } + } + } + } + + if ( norm != 0.0 ) { + SetBinContent(i,j,content/norm); + if (ebuf) { + error /= (norm*norm); + SetBinError(i,j,sqrt(error)); + } + } + } + } + fEntries = nentries; + + delete [] buf; + delete [] ebuf; +} + + +GH1D *GH2::ProjectionX_BG(const char *name,Int_t ylowbin,Int_t yhighbin, + Int_t ylowbgbin,Int_t yhighbgbin,double scale,Option_t *opt) const { + GH1D *add = ProjectionX("_px",ylowbin,yhighbin); + GH1D *sub = ProjectionX("_px",ylowbgbin,yhighbgbin); + if(scale>0) + scale*=-1; + add->Add(sub,scale); + + add->SetName(Form("%s_bg",add->GetName())); + add->SetTitle(Form("%s - %s",add->GetTitle(),sub->GetTitle())); + + sub->Delete(); + + return add; +} + +GH1D *GH2::ProjectionY_BG(const char *name,Int_t xlowbin,Int_t xhighbin, + Int_t xlowbgbin,Int_t xhighbgbin,double scale,Option_t *opt) const { + GH1D *add = ProjectionX("_py",xlowbin,xhighbin); + GH1D *sub = ProjectionX("_py",xlowbgbin,xhighbgbin); + if(scale>0) + scale*=-1; + add->Add(sub,scale); + + add->SetName(Form("%s_bg",add->GetName())); + add->SetTitle(Form("%s - %s",add->GetTitle(),sub->GetTitle())); + + sub->Delete(); + + return add; +} + +GH1D *GH2::SummaryProjection(GH1 *hist,int axis,int direction,bool show_empty) const { + if(hist && !hist->IsSummary()) { + //printf("not a summary spectrum!\n"); + return 0; + } + //printf("is a summary spectrum! axis = %i\n",axis); + int binnum=1; + std::string name; + if(hist) { + name = hist->GetName(); + size_t underscore_pos = name.rfind('_'); + binnum = std::atoi(name.c_str() + underscore_pos + 1); + if(direction==kForward) + binnum ++; + else + binnum --;; + } + int max_binnum; + if(axis == kXaxis){ + max_binnum = GetYaxis()->GetNbins(); + name = Form("%s_py",GetName()); + } else { + max_binnum = GetXaxis()->GetNbins(); + name = Form("%s_px",GetName()); + } + if(binnum > max_binnum){ + binnum = 1; + } else if(binnum<1) { + binnum = max_binnum; + } + GH1D *g=0; + int start_bin=binnum; + switch(axis) { + case kXaxis: + while(true) { + name = Form("%s_%d",name.c_str(),binnum); + //g = (GH1D*)fProjections.FindObject(name.c_str()); + //if(g && g->Integral() > 0) { + // g->SetParent((TObject*)this); + // g->SetSummary(); + // return g; + //} + g = ProjectionX(name.c_str(),binnum,binnum,""); + if(g && g->Integral()>0) { + g->SetParent((TObject*)this); + g->SetSummary(); + return g; + } + if(direction==kForward) { + binnum++; + } else { + binnum--; + } + if(binnum==start_bin) { + break; + } else if(binnum >max_binnum) { + binnum=1; + } else if(binnum==0) { + binnum=max_binnum; + } + //std::cout << "binnum " << binnum <<"\tmaxbinnum " << max_binnum << std::endl; + } + break; + case kYaxis: + while(true) { + name = Form("%s_%d",name.c_str(),binnum); + //g = (GH1D*)fProjections.FindObject(name.c_str()); + //if(g && g->Integral() > 0) { + // g->SetParent((TObject*)this); + // g->SetSummary(); + // return g; + //} + g = ProjectionY(name.c_str(),binnum,binnum,""); + if(g && g->Integral()>0) { + g->SetParent((TObject*)this); + g->SetSummary(); + return g; + } + if(direction==kForward) { + binnum++; + } else { + binnum--; + } + if(binnum==start_bin) { + break; + } else if(binnum >max_binnum) { + binnum=1; + } else if(binnum==0) { + binnum=max_binnum; + } + //std::cout << "binnum " << binnum <<"\tmaxbinnum " << max_binnum << std::endl; + } + break; + } + if(g) { + g->SetParent((TObject*)this); + g->SetSummary(); + } + return g; +} + + + + +GH1 *GH2::GetNext(TObject *obj,int direction) const { + GH1 *next=0; + if(fProjections.GetSize()<2 || (!fProjections.FindObject(obj))) + return next; + switch(direction) { + case GH2::kForward: + next = (GH1*)(fProjections.After(obj)); + if(!next) + next = (GH1*)(fProjections.First()); + break; + case GH2::kBackward: + next = (GH1*)(fProjections.Before(obj)); + if(!next) + next = (GH1*)(fProjections.Last()); + break; + }; + return next; +} + + +std::map GH2::FitSummary(double low,double high,int axis,Option_t *opt) const { + std::map chan_area; + int binlow,binhigh; + if(low>high) + std::swap(low,high); + + //switch on option + //TF1 *fit = PhotoPeakFitNormBG(h,low,high,""); + + switch(axis) { + case kXaxis: + printf(" project onto x...\n"); + binlow = this->GetXaxis()->FindBin(low); + binhigh = this->GetXaxis()->FindBin(high); + for(int y=1;y<=this->GetNbinsY();y++) { + GH1D *p = this->ProjectionX("_px",y,y);//binlow,binhigh); + if(p->Integral(binlow,binhigh)<10) + continue; + GPeak *peak = PhotoPeakFitNormBG(p,low,high,""); + chan_area[y] = peak->GetSum(); + } + break; + case kYaxis: + printf(" project onto y...\n"); + binlow = this->GetYaxis()->FindBin(low); + binhigh = this->GetYaxis()->FindBin(high); + for(int x=1;x<=this->GetNbinsY();x++) { + GH1D *p = this->ProjectionY("_py",x,x);//binlow,binhigh); + if(p->Integral(binlow,binhigh)<10) + continue; + GPeak *peak = PhotoPeakFitNormBG(p,low,high,""); + chan_area[x] = peak->GetSum(); + } + break; + } + + std::map::iterator it; + printf("\n %s sum for %.02f to %.02f \n\n",this->GetName(),low,high); + for(it=chan_area.begin();it!=chan_area.end();it++) { + printf("\t% 4i\t\t% 8.2f\n",it->first,it->second); + } + printf("\n\n"); + return chan_area; +} + + + + + + + + diff --git a/libraries/GROOT/GH2Base.cxx b/libraries/GROOT/GH2Base.cxx deleted file mode 100644 index cc255976..00000000 --- a/libraries/GROOT/GH2Base.cxx +++ /dev/null @@ -1,459 +0,0 @@ -#include "GH2Base.h" - -#include - -#include - -#include "GH1D.h" - -ClassImp(GH2Base) - - - -GH2Base::~GH2Base() { - fProjections->Delete(); - fSummaryProjections->Delete(); -} - - -void GH2Base::Init() { - fProjections = new TList(); - fSummaryProjections = new TList(); - fIsSummary = false; - fSummaryDirection = kXDirection; -} - - -void GH2Base::GH2Clear(Option_t *opt) { - TString sopt(opt); - fProjections->Clear(); - fSummaryProjections->Clear(); -} - - -GH1D* GH2Base::Projection_Background(int axis, - int firstbin, - int lastbin, - int first_bg_bin, - int last_bg_bin, - kBackgroundSubtraction mode) { - std::string title; - std::string name; - std::string sproj; - TH1D* proj = NULL; - TH1D* bg_proj = NULL; - - double xlow,xhigh,bg_xlow,bg_xhigh; - - if(axis==0){ - xlow = GetTH2()->GetXaxis()->GetBinLowEdge(firstbin); - xhigh = GetTH2()->GetXaxis()->GetBinUpEdge(lastbin); - bg_xlow = GetTH2()->GetXaxis()->GetBinLowEdge(first_bg_bin); - bg_xhigh = GetTH2()->GetXaxis()->GetBinUpEdge(last_bg_bin); - sproj = "projx"; - proj = GetTH2()->ProjectionX("temp1", firstbin, lastbin); - bg_proj = GetTH2()->ProjectionX("temp2", first_bg_bin, last_bg_bin); - } else if (axis==1){ - xlow = GetTH2()->GetYaxis()->GetBinLowEdge(firstbin); - xhigh = GetTH2()->GetYaxis()->GetBinUpEdge(lastbin); - bg_xlow = GetTH2()->GetYaxis()->GetBinLowEdge(first_bg_bin); - bg_xhigh = GetTH2()->GetYaxis()->GetBinUpEdge(last_bg_bin); - sproj = "projy"; - proj = GetTH2()->ProjectionY("temp1", firstbin, lastbin); - bg_proj = GetTH2()->ProjectionY("temp2", first_bg_bin, last_bg_bin); - } else { - return NULL; - } - double scale = (xhigh-xlow) / (bg_xhigh = bg_xlow) ; - - - name = Form("%s_%s_%d_%d_bg_%d_%d",GetTH2()->GetName(),sproj.c_str() - ,firstbin,lastbin, - first_bg_bin,last_bg_bin); - title = Form("%s_%s_%d[%.02f]_%d[%.02f]_bg_%d[%.02f]_%d[%.02f]",GetTH2()->GetName(),sproj.c_str(), - firstbin,xlow,lastbin,xhigh, - first_bg_bin,bg_xlow,last_bg_bin,bg_xhigh); - - double bg_scaling = double(lastbin-firstbin)/double(last_bg_bin-first_bg_bin); - if(mode == kNoBackground){ - bg_scaling = 0; - } - - proj->Add(bg_proj, -bg_scaling); - GH1D* output = new GH1D(*proj); - proj->Delete(); - bg_proj->Delete(); - - output->SetName(name.c_str()); - output->SetTitle(title.c_str()); - output->SetParent(GetTH2()); - output->SetProjectionAxis(axis); - output->SetDirectory(0); - fProjections->Add(output); - return output; -} - -GH1D* GH2Base::GH2ProjectionX(const char* name, - int firstbin, - int lastbin, - Option_t* option,bool KeepEmpty) { - std::string title; - double xlow = GetTH2()->GetYaxis()->GetBinLowEdge(firstbin); - double xhigh = GetTH2()->GetYaxis()->GetBinUpEdge(lastbin); - bool total = false; - if(firstbin==0 && lastbin==-1){ - total = true; - title = Form("%s_totalx",GetTH2()->GetName()); - } else { - title = Form("%s_projx_%d[%.02f]_%d[%.02f]",GetTH2()->GetName(), - firstbin,xlow,lastbin,xhigh); - } - - std::string actual_name = name; - if(actual_name == "_px"){ - if(total) - actual_name = title; - else - actual_name = Form("%s_projx_%d_%d",GetTH2()->GetName(),firstbin,lastbin); - } - - TH1D* proj = GetTH2()->ProjectionX("temp", firstbin, lastbin, option); - GH1D* output = new GH1D(*proj); - proj->Delete(); - - output->SetName(actual_name.c_str()); - output->SetTitle(title.c_str()); - output->SetParent(GetTH2()); - output->SetProjectionAxis(0); - output->SetDirectory(0); - - if(fIsSummary){ - if(KeepEmpty || output->Integral()>0) - fSummaryProjections->Add(output); - } else { - if(KeepEmpty || output->Integral()>0) - fProjections->Add(output); - } - return output; -} - -GH1D* GH2Base::ProjectionX_Background(int firstbin, - int lastbin, - int first_bg_bin, - int last_bg_bin, - kBackgroundSubtraction mode) { - return Projection_Background(0, firstbin, lastbin, - first_bg_bin, last_bg_bin, - mode); -} - - -GH1D* GH2Base::GH2ProjectionY(const char* name, - int firstbin, - int lastbin, - Option_t* option, bool KeepEmpty) { - std::string title; - double ylow = GetTH2()->GetXaxis()->GetBinLowEdge(firstbin); - double yhigh = GetTH2()->GetXaxis()->GetBinUpEdge(lastbin); - bool total = false; - if(firstbin==0 && lastbin==-1){ - total = true; - title = Form("%s_totaly",GetTH2()->GetName()); - } else { - title = Form("%s_projy_%d[%.02f]_%d[%.02f]",GetTH2()->GetName(), - firstbin,ylow,lastbin,yhigh); - } - - std::string actual_name = name; - if(actual_name == "_py"){ - if(total) - actual_name = title; - else - actual_name = Form("%s_projy_%d_%d",GetTH2()->GetName(),firstbin,lastbin); - - } - - TH1D* proj = GetTH2()->ProjectionY("temp", firstbin, lastbin, option); - GH1D* output = new GH1D(*proj); - proj->Delete(); - output->SetName(actual_name.c_str()); - output->SetTitle(title.c_str()); - output->SetParent(GetTH2()); - output->SetProjectionAxis(1); - output->SetDirectory(0); - - if(fIsSummary){ - if(KeepEmpty || output->Integral()>0) - fSummaryProjections->Add(output); - } else { - if(KeepEmpty || output->Integral()>0) - fProjections->Add(output); - } - return output; -} - -GH1D* GH2Base::ProjectionY_Background(int firstbin, - int lastbin, - int first_bg_bin, - int last_bg_bin, - kBackgroundSubtraction mode) { - return Projection_Background(1, firstbin, lastbin, - first_bg_bin, last_bg_bin, - mode); -} - - -GH1D* GH2Base::GetPrevious(const GH1D* curr,bool DrawEmpty) { - if(fIsSummary){ - return GetPrevSummary(curr, false); - } - - TObjLink* link = fProjections->FirstLink(); - while(link){ - if(link->GetObject() == curr){ - break; - } - link = link->Next(); - } - if(!link){ - return 0; - } - - if(link->Prev()){ - return (GH1D*)link->Prev()->GetObject(); - } else { - return (GH1D*)fProjections->Last(); - } -} - -GH1D* GH2Base::GetNext(const GH1D* curr,bool DrawEmpty) { - if(fIsSummary){ - return GetNextSummary(curr,false); - } - - TObjLink* link = fProjections->FirstLink(); - while(link){ - if(link->GetObject() == curr){ - break; - } - link = link->Next(); - } - if(!link){ - return 0; - } - - if(link->Next()){ - return (GH1D*)link->Next()->GetObject(); - } else { - return (GH1D*)fProjections->First(); - } -} - -GH1D* GH2Base::GetNextSummary(const GH1D* curr,bool DrawEmpty) { - int binnum=1; - std::string name; - if(curr) { - name = curr->GetName(); - size_t underscore_pos = name.rfind('_'); - binnum = std::atoi(name.c_str() + underscore_pos + 1); - binnum++; - } - - int max_binnum; - if(fSummaryDirection == kXDirection){ - max_binnum = GetTH2()->GetXaxis()->GetNbins(); - } else { - max_binnum = GetTH2()->GetYaxis()->GetNbins(); - } - - if(binnum > max_binnum){ - binnum = 1; - } - GH1D *g =0; - int start_bin = binnum; - switch(fSummaryDirection) { - case kXDirection: - while(true) { - std::string hist_name = Form("%s_%d",GetTH2()->GetName(),binnum); - g = (GH1D*)fSummaryProjections->FindObject(hist_name.c_str()); - if(g && g->Integral() > 0) { - return g; - } - - g = GH2ProjectionY(hist_name.c_str(),binnum,binnum,"",DrawEmpty); - if(g && g->Integral()>0) - return g; - binnum++; - if(binnum==start_bin) { - break; - } else if(binnum >max_binnum) { - binnum=1; - } - } - break; - case kYDirection: - while(true) { - std::string hist_name = Form("%s_%d",GetTH2()->GetName(),binnum); - - g = (GH1D*)fSummaryProjections->FindObject(hist_name.c_str()); - if(g && g->Integral() > 0) { - return g; - } - - g = GH2ProjectionX(hist_name.c_str(),binnum,binnum,"",DrawEmpty); - if(g && g->Integral()>0) - return g; - binnum++; - if(binnum==start_bin) { - break; - } else if(binnum >max_binnum) { - binnum=1; - } - } - break; - } - return g; - //return SummaryProject(binnum); -} - -GH1D* GH2Base::GetPrevSummary(const GH1D* curr,bool DrawEmpty) { - int binnum=1; - std::string name; - if(curr) { - name = curr->GetName(); - size_t underscore_pos = name.rfind('_'); - binnum = std::atoi(name.c_str() + underscore_pos + 1); - binnum--; - } - - int max_binnum; - if(fSummaryDirection == kXDirection){ - max_binnum = GetTH2()->GetXaxis()->GetNbins(); - } else { - max_binnum = GetTH2()->GetYaxis()->GetNbins(); - } - - if(binnum <= 0){ - binnum = max_binnum; - } - - std::string hist_name = Form("%s_%d",GetTH2()->GetName(),binnum); - TObject* obj = fSummaryProjections->FindObject(hist_name.c_str()); - if(obj) { - return (GH1D*)obj; - } - - int start_bin = binnum; - switch(fSummaryDirection) { - case kXDirection: - while(true) { - std::string hist_name = Form("%s_%d",GetTH2()->GetName(),binnum); - GH1D *g = GH2ProjectionY(hist_name.c_str(),binnum,binnum,"",DrawEmpty); - if(g && g->Integral()>0) - return g; - binnum--; - if(binnum==start_bin) { - break; - } else if(binnum <=0) { - binnum=max_binnum; - } - } - break; - case kYDirection: - while(true) { - std::string hist_name = Form("%s_%d",GetTH2()->GetName(),binnum); - GH1D *g = GH2ProjectionX(hist_name.c_str(),binnum,binnum,"",DrawEmpty); - if(g && g->Integral()>0) - return g; - binnum--; - if(binnum==start_bin) { - break; - } else if(binnum <=0) { - binnum=max_binnum; - } - } - break; - } - return 0; - //return SummaryProject(binnum); -} - - -/* -GH1D* GH2Base::SummaryProject(int binnum,bool DrawEmpty) { - std::string hist_name = Form("%s_%d",GetTH2()->GetName(),binnum); - TObject* obj = fSummaryProjections->FindObject(hist_name.c_str()); - if(obj) { - return (GH1D*)obj; - } - - int start_bin = binnum; - int max_binnum; - - switch(fSummaryDirection) { - case kXDirection: - max_binnum = GetTH2()->GetXaxis()->GetNbins(); - while(true) { - GH1D *g = GH2ProjectionY(hist_name.c_str(),binnum,binnum,DrawEmpty); - if(g && g->Integral()>0) - return g; - else if(binnum< - } - return GH2ProjectionY(hist_name.c_str(), binnum, binnum); - case kYDirection: - max_binnum = GetTH2()->GetYaxis()->GetNbins(); - return GH2ProjectionX(hist_name.c_str(), binnum, binnum); - } - - return NULL; -} -*/ - - - -/* -void GH2I::Streamer(TBuffer &b) { - if(b.IsReading()) { - Version_t v = b.ReadVersion(); - TH2I::Streamer(b); - TDirectory *current = gDirectory; - if(TDirectory::Cd(Form("%s_projections",this->GetName()))) { - TList *list = gDirectory->GetList(); - TIter iter(list); - while(TObject *obj = iter.Next()) { - if(obj->InheritsFrom(TH1::Class())) { - GH1D *h = new GH1D(*obj); - h->SetParent(this); - fProjections.Add(h); - } - } - } - current->cd(); - } else { - b.WriteVersion(GH2I::IsA()); - TH2I::Streamer(b); - if(fProjections.GetEntries()) { - TDirectory *current = gDirectory; - TDirectory *newdir = current->mkdir(Form("%s_projections",this->GetName()); - newdir->cd(); - fProjections->Write(); - current->cd(); - } - - } -} -*/ - - -/* -GH2Base::iterator& GH2Base::iterator::operator++() { - curr = mat->GetNext(curr); - std::cout << "Incrementing: curr=" << curr << ", first=" << first << std::endl; - std::cout << "First's name = " << first->GetName() << std::endl; - if(curr==first) { - curr = 0; - std::cout << "Found the beginning" << std::endl; - } - return *this; -} -*/ diff --git a/libraries/GROOT/GH2D.cxx b/libraries/GROOT/GH2D.cxx index 542bb1b2..16f0a152 100644 --- a/libraries/GROOT/GH2D.cxx +++ b/libraries/GROOT/GH2D.cxx @@ -1,64 +1,157 @@ #include "GH2D.h" -#include -#include -#include -#include - -#include "GH1D.h" ClassImp(GH2D) -GH2D::GH2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins,Int_t nbinsy, const Double_t *ybins) : - TH2D(name,title,nbinsx,xbins,nbinsy,ybins), GH2Base(), - fXFillClass(0),fYFillClass(0),fXFillMethod(0),fYFillMethod(0) { +GH2D::GH2D(): GH2(),TArrayI() { + SetBinsLength(9); + if(GH1::fgDefaultSumw2) Sumw2(); } +GH2D::GH2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins, + Int_t nbinsy, const Double_t *ybins) : + GH2(name,title,nbinsx,xbins,nbinsy,ybins) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); +} -GH2D::GH2D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins,Int_t nbinsy, const Float_t *ybins) : - TH2D(name,title,nbinsx,xbins,nbinsy,ybins), GH2Base(), - fXFillClass(0),fYFillClass(0),fXFillMethod(0),fYFillMethod(0) { + +GH2D::GH2D(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins, + Int_t nbinsy, const Float_t *ybins) : + GH2(name,title,nbinsx,xbins,nbinsy,ybins) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); } GH2D::GH2D(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins, - Int_t nbinsy, Double_t ylow, Double_t yup) : - TH2D(name,title,nbinsx,xbins,nbinsy,ylow,yup), GH2Base(), - fXFillClass(0),fYFillClass(0),fXFillMethod(0),fYFillMethod(0) { + Int_t nbinsy, Double_t ylow, Double_t yup) : + GH2(name,title,nbinsx,xbins,nbinsy,ylow,yup) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); } GH2D::GH2D(const char *name,const char *title,Int_t nbinsx, Double_t xlow, Double_t xup, - Int_t nbinsy, Double_t *ybins) : - TH2D(name,title,nbinsx,xlow,xup,nbinsy,ybins), GH2Base(), - fXFillClass(0),fYFillClass(0),fXFillMethod(0),fYFillMethod(0) { + Int_t nbinsy, Double_t *ybins) : + GH2(name,title,nbinsx,xlow,xup,nbinsy,ybins) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); } GH2D::GH2D(const char *name,const char *title,Int_t nbinsx, Double_t xlow, Double_t xup, - Int_t nbinsy, Double_t ylow, Double_t yup) : - TH2D(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup), GH2Base(), - fXFillClass(0),fYFillClass(0),fXFillMethod(0),fYFillMethod(0) { + Int_t nbinsy, Double_t ylow, Double_t yup) : + GH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); + if(xlow>=xup||ylow>=yup) SetBuffer(fgBufferSize); } -GH2D::GH2D(const TObject &obj) { - if(obj.InheritsFrom(TH2::Class())){ - obj.Copy(*this); - } +GH2D::GH2D(const GH2D &obj) : GH2(), TArrayI() { + ((GH2D&)obj).Copy(*this); } +GH2D::GH2D(const TH1 &h2d) : GH2(), TArrayI() { + ((TH1&)h2d).Copy(*this); +} + + GH2D::~GH2D() { } +void GH2D::AddBinContent(int bin) { + if(fArray[bin] < 2147483647) fArray[bin]++; +} + +void GH2D::AddBinContent(int bin,double w) { + long newvalue = fArray[bin] + int(w); + if(newvalue > -2147483647 && newvalue < 2147483647) { + fArray[bin] = int(newvalue); + return; + } + if(newvalue<-2147483647) fArray[bin] = -2147483647; + if(newvalue>2147483647) fArray[bin] = 2147483647; +} + +void GH2D::Copy(TObject &obj) const { + GH2::Copy((GH2D&)obj); +} + +void GH2D::Reset(Option_t *opt) { + GH2::Reset(opt); + TArrayI::Reset(); +} + +void GH2D::SetBinsLength(int n) { + if(n<0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2); + fNcells = n; + TArrayI::Set(n); +} + +GH2D& GH2D::operator=(const GH2D &h1) { + if(this!=&h1) ((GH2D&)h1).Copy(*this); + return *this; +} + +GH2D operator*(float c1,GH2D &h1) { + GH2D hnew = h1; + hnew.Scale(c1); + hnew.SetDirectory(0); + return hnew; +} + +GH2D operator*(GH2D &h1,GH2D &h2) { + GH2D hnew = h1; + hnew.Multiply(&h2); + hnew.SetDirectory(0); + return hnew; +} + +GH2D operator/(GH2D &h1,GH2D &h2) { + GH2D hnew = h1; + hnew.Divide(&h2); + hnew.SetDirectory(0); + return hnew; +} + +GH2D operator+(GH2D &h1,GH2D &h2) { + GH2D hnew = h1; + hnew.Add(&h2); + hnew.SetDirectory(0); + return hnew; +} + +GH2D operator-(GH2D &h1,GH2D &h2) { + GH2D hnew = h1; + hnew.Add(&h2,-1); + hnew.SetDirectory(0); + return hnew; +} + + + + + + + + + + + + + + + + + +/* + + void GH2D::Copy(TObject &obj) const { TH2::Copy(obj); - GH2D& g = (GH2D&)obj; - g.fXFillClass = fXFillClass; - g.fYFillClass = fYFillClass; - g.fXFillMethod = fXFillMethod; - g.fYFillMethod = fYFillMethod; - //fProjections->Copy(*(((GH2D&)obj).fProjections)); + //fProjections->Copy(*(((GH2D&)obj).fProjections)); //fSummaryProjections->Copy(*(((GH2D&)obj).fSummaryProjections)); } @@ -72,7 +165,7 @@ TObject *GH2D::Clone(const char *newname) const { void GH2D::Clear(Option_t *opt) { TString sopt(opt); if(!sopt.Contains("projonly")){ - TH2D::Clear(opt); + TH2I::Clear(opt); } GH2Clear(); } @@ -84,25 +177,15 @@ void GH2D::Draw(Option_t *opt) { if(option == ""){ option = "colz"; } - TH2D::Draw(option.c_str()); + TH2I::Draw(option.c_str()); if(gPad) { gPad->Update(); gPad->GetFrame()->SetBit(TBox::kCannotMove); } } - -//void GH2D::Draw(TCutG *cut) { -// if(!cut) -// return; -// std::string option = Form("colz [%s]",cut->GetName()); -// TH2D::Draw(option.c_str()); -//} - - - TH1 *GH2D::DrawCopy(Option_t *opt) const { - TH1 *h = TH2D::DrawCopy(opt); + TH1 *h = TH2I::DrawCopy(opt); if(gPad) { gPad->Update(); gPad->GetFrame()->SetBit(TBox::kCannotMove); @@ -111,7 +194,7 @@ TH1 *GH2D::DrawCopy(Option_t *opt) const { } TH1 *GH2D::DrawNormalized(Option_t *opt,Double_t norm) const { - TH1 *h = TH2D::DrawNormalized(opt,norm); + TH1 *h = TH2I::DrawNormalized(opt,norm); if(gPad) { gPad->Update(); gPad->GetFrame()->SetBit(TBox::kCannotMove); @@ -121,6 +204,13 @@ TH1 *GH2D::DrawNormalized(Option_t *opt,Double_t norm) const { + + + + + + + GH1D* GH2D::ProjectionX(const char* name, int firstbin, int lastbin, @@ -137,11 +227,11 @@ GH1D* GH2D::ProjectionY(const char* name, return GH2ProjectionY(name,firstbin,lastbin,option); } -/* + void GH2D::Streamer(TBuffer &b) { if(b.IsReading()) { Version_t v = b.ReadVersion(); - TH2D::Streamer(b); + TH2I::Streamer(b); TDirectory *current = gDirectory; if(TDirectory::Cd(Form("%s_projections",this->GetName()))) { TList *list = gDirectory->GetList(); @@ -157,7 +247,7 @@ void GH2D::Streamer(TBuffer &b) { current->cd(); } else { b.WriteVersion(GH2D::IsA()); - TH2D::Streamer(b); + TH2I::Streamer(b); if(fProjections.GetEntries()) { TDirectory *current = gDirectory; TDirectory *newdir = current->mkdir(Form("%s_projections",this->GetName()); @@ -171,39 +261,15 @@ void GH2D::Streamer(TBuffer &b) { */ -void GH2D::SetFillMethod(const char *classnamex,const char *methodnamex,const char *paramx, - const char *classnamey,const char *methodnamey,const char *paramy) { - fXFillClass = TClass::GetClass(classnamex); - if(!fXFillClass) - return; - fYFillClass = TClass::GetClass(classnamey); - if(!fYFillClass) - return; - fXFillMethod = new TMethodCall(fXFillClass,methodnamex,paramx); - fYFillMethod = new TMethodCall(fYFillClass,methodnamey,paramy); - //printf("class: %s\n",fFillClass->GetName()); - //printf("method: %s\n",fFillMethod->GetMethod()->GetPrototype()); -} - - -Int_t GH2D::Fill(const TObject* objx,const TObject *objy) { - if(!fXFillClass || !fXFillMethod || !fYFillClass || !fYFillMethod) { - //printf("%p \t %p\n",fFillClass,fFillMethod); - return -1; - } - if(!objy) { - objy=objx; - } - if(objx->IsA()!=fXFillClass || objy->IsA()!=fYFillClass ) { - //printf("%s \t %s\n", obj->Class()->GetName(),fFillClass->GetName()); - return -2; - } - Double_t storagex; - Double_t storagey; - fXFillMethod->Execute((void*)(objx),storagex); - fYFillMethod->Execute((void*)(objy),storagey); - return TH2D::Fill(storagex,storagey); -} +//Int_t GH2D::Write(const char *name,Int_t option,Int_t bufsize) const { +// TH2D hist; + //hist.Copy(*this); +// this->Copy(hist); +// hist.SetNameTitle(this->GetName(),this->GetTitle()); + //return +// hist.Write(); +// return bufsize; +//} diff --git a/libraries/GROOT/GH2I.cxx b/libraries/GROOT/GH2I.cxx index 44da32a0..3b6dba37 100644 --- a/libraries/GROOT/GH2I.cxx +++ b/libraries/GROOT/GH2I.cxx @@ -1,48 +1,153 @@ #include "GH2I.h" -#include -#include - -#include "GH1D.h" ClassImp(GH2I) -GH2I::GH2I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins,Int_t nbinsy, const Double_t *ybins) : - TH2I(name,title,nbinsx,xbins,nbinsy,ybins), GH2Base() { +GH2I::GH2I(): GH2(),TArrayI() { + SetBinsLength(9); + if(GH1::fgDefaultSumw2) Sumw2(); +} + +GH2I::GH2I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins, + Int_t nbinsy, const Double_t *ybins) : + GH2(name,title,nbinsx,xbins,nbinsy,ybins) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); } -GH2I::GH2I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins,Int_t nbinsy, const Float_t *ybins) : - TH2I(name,title,nbinsx,xbins,nbinsy,ybins), GH2Base() { +GH2I::GH2I(const char *name,const char *title,Int_t nbinsx,const Float_t *xbins, + Int_t nbinsy, const Float_t *ybins) : + GH2(name,title,nbinsx,xbins,nbinsy,ybins) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); } GH2I::GH2I(const char *name,const char *title,Int_t nbinsx,const Double_t *xbins, - Int_t nbinsy, Double_t ylow, Double_t yup) : - TH2I(name,title,nbinsx,xbins,nbinsy,ylow,yup), GH2Base() { + Int_t nbinsy, Double_t ylow, Double_t yup) : + GH2(name,title,nbinsx,xbins,nbinsy,ylow,yup) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); } GH2I::GH2I(const char *name,const char *title,Int_t nbinsx, Double_t xlow, Double_t xup, - Int_t nbinsy, Double_t *ybins) : - TH2I(name,title,nbinsx,xlow,xup,nbinsy,ybins), GH2Base() { + Int_t nbinsy, Double_t *ybins) : + GH2(name,title,nbinsx,xlow,xup,nbinsy,ybins) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); } GH2I::GH2I(const char *name,const char *title,Int_t nbinsx, Double_t xlow, Double_t xup, - Int_t nbinsy, Double_t ylow, Double_t yup) : - TH2I(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup), GH2Base() { + Int_t nbinsy, Double_t ylow, Double_t yup) : + GH2(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup) { + TArrayI::Set(fNcells); + if(GH1::fgDefaultSumw2) Sumw2(); + if(xlow>=xup||ylow>=yup) SetBuffer(fgBufferSize); } -GH2I::GH2I(const TObject &obj) { - if(obj.InheritsFrom(TH2::Class())){ - obj.Copy(*this); - } +GH2I::GH2I(const GH2I &obj) : GH2(), TArrayI() { + ((GH2I&)obj).Copy(*this); +} + +GH2I::GH2I(const TH1 &h2d) : GH2(), TArrayI() { + ((TH1&)h2d).Copy(*this); } + GH2I::~GH2I() { } +void GH2I::AddBinContent(int bin) { + if(fArray[bin] < 2147483647) fArray[bin]++; +} + +void GH2I::AddBinContent(int bin,double w) { + long newvalue = fArray[bin] + int(w); + if(newvalue > -2147483647 && newvalue < 2147483647) { + fArray[bin] = int(newvalue); + return; + } + if(newvalue<-2147483647) fArray[bin] = -2147483647; + if(newvalue>2147483647) fArray[bin] = 2147483647; +} + +void GH2I::Copy(TObject &obj) const { + GH2::Copy((GH2I&)obj); +} + +void GH2I::Reset(Option_t *opt) { + GH2::Reset(opt); + TArrayI::Reset(); +} + +void GH2I::SetBinsLength(int n) { + if(n<0) n = (fXaxis.GetNbins()+2)*(fYaxis.GetNbins()+2); + fNcells = n; + TArrayI::Set(n); +} + +GH2I& GH2I::operator=(const GH2I &h1) { + if(this!=&h1) ((GH2I&)h1).Copy(*this); + return *this; +} + +GH2I operator*(float c1,GH2I &h1) { + GH2I hnew = h1; + hnew.Scale(c1); + hnew.SetDirectory(0); + return hnew; +} + +GH2I operator*(GH2I &h1,GH2I &h2) { + GH2I hnew = h1; + hnew.Multiply(&h2); + hnew.SetDirectory(0); + return hnew; +} + +GH2I operator/(GH2I &h1,GH2I &h2) { + GH2I hnew = h1; + hnew.Divide(&h2); + hnew.SetDirectory(0); + return hnew; +} + +GH2I operator+(GH2I &h1,GH2I &h2) { + GH2I hnew = h1; + hnew.Add(&h2); + hnew.SetDirectory(0); + return hnew; +} + +GH2I operator-(GH2I &h1,GH2I &h2) { + GH2I hnew = h1; + hnew.Add(&h2,-1); + hnew.SetDirectory(0); + return hnew; +} + + + + + + + + + + + + + + + + + +/* + + void GH2I::Copy(TObject &obj) const { TH2::Copy(obj); @@ -122,7 +227,7 @@ GH1D* GH2I::ProjectionY(const char* name, return GH2ProjectionY(name,firstbin,lastbin,option); } -/* + void GH2I::Streamer(TBuffer &b) { if(b.IsReading()) { Version_t v = b.ReadVersion(); diff --git a/libraries/GROOT/GHistPopup.cxx b/libraries/GROOT/GHistPopup.cxx new file mode 100644 index 00000000..b11d79d0 --- /dev/null +++ b/libraries/GROOT/GHistPopup.cxx @@ -0,0 +1,76 @@ + +#include + +#include + +GHistPopup::GHistPopup(GH2 *parent,int w,int h) : + GPopup(gClient->GetDefaultRoot(),gClient->GetDefaultRoot(),w,h),listv(0),listc(0) { + SetFrames(); + AddEntry(parent->GetProjections()); + Init(); + PrintSelected(); +} + +void GHistPopup::SetFrames() { + TGVerticalFrame *vframe = new TGVerticalFrame(this,500,200); + listv = new TGListView(vframe,500,200); + listc = new TGLVContainer(listv->GetViewPort(),500,200, + kHorizontalFrame,fgWhitePixel); + listc->Associate(this); + listv->SetContainer(listc); + listv->GetViewPort()->SetBackgroundColor(fgWhitePixel); + listv->SetViewMode(kLVList); + //listv->SetIncremental(1,19); + ///////////////////////////////// + ///////////////////////////////// + + //TGLVEntry *myentry= new TGLVEntry(listc,"name1","name2"); + //myentry->Connect("Clicked()","GPopup",this,"Print"); + //myentry->SetItemName("Iamname"); + //listc->AddItem(myentry); + + ///////////////////////////////// + ///////////////////////////////// + + vframe->AddFrame(listv,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); + + TGHorizontalFrame *hframe = new TGHorizontalFrame(vframe,500,20); + TGTextButton *b1 = new TGTextButton(hframe,"&button1"); + TGTextButton *b2 = new TGTextButton(hframe,"&button2"); + b1->Connect("Clicked()","GHistPopup",this,"PrintSelected()"); + b2->Connect("Clicked()","GPopup",this,"Print()"); + hframe->AddFrame(b1,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); + hframe->AddFrame(b2,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); + + vframe->AddFrame(hframe,new TGLayoutHints(kLHintsExpandX)); + this->AddFrame(vframe,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); +} + + +void GHistPopup::AddEntry(const char *name) { + //printf("%s\t0x%08x\n",__PRETTY_FUNCTION__,listc); + if(!listc) return; + TGLVEntry *myentry= new TGLVEntry(listc,"name","name"); + listc->AddItem(myentry); +} + +void GHistPopup::AddEntry(TList *list) { + //printf("%s\t0x%08x\n",__PRETTY_FUNCTION__,listc); + if(!listc || list) return; + TIter iter(list); + while(TObject *obj=iter.Next()) + AddEntry(obj->GetName()); +} + +void GHistPopup::PrintSelected() const { + //printf("%s\t0x%08x\n",__PRETTY_FUNCTION__,listc); + if(!listc) return; + TList *list = listc->GetSelectedItems(); + if(list) { + printf("list->GetSize() = %i\n",list->GetSize()); + list->Print(); + } + +} + + diff --git a/libraries/GROOT/GPeak.cxx b/libraries/GROOT/GPeak.cxx index 89f741ec..918d5d7d 100644 --- a/libraries/GROOT/GPeak.cxx +++ b/libraries/GROOT/GPeak.cxx @@ -4,6 +4,7 @@ #include #include #include +#include #include "Globals.h" @@ -39,8 +40,7 @@ GPeak::GPeak(Double_t cent,Double_t xlow,Double_t xhigh,Option_t *opt) SetParent(0); //TF1::SetDirectory(0); - fBGFit.SetParent(0); - fBGFit.SetBit(TObject::kCanDelete,false); + DetachBackground(); //fBGFit.SetDirectory(0); } @@ -74,8 +74,8 @@ GPeak::GPeak(Double_t cent,Double_t xlow,Double_t xhigh,TF1 *bg,Option_t *opt) fBGFit.SetLineColor(kBlack); SetParent(0); + DetachBackground(); //SetDirectory(0); - fBGFit.SetParent(0); //fBGFit.SetDirectory(0); } @@ -92,7 +92,7 @@ GPeak::GPeak() SetParent(0); //SetDirectory(0); - fBGFit.SetParent(0); + DetachBackground(); //fBGFit.SetDirectory(0); } @@ -101,7 +101,7 @@ GPeak::GPeak(const GPeak &peak) SetParent(0); //SetDirectory(0); - fBGFit.SetParent(0); + DetachBackground(); //fBGFit.SetDirectory(0); peak.Copy(*this); } @@ -157,6 +157,7 @@ void GPeak::Copy(TObject &obj) const { ((GPeak&)obj).fNdf = fNdf; fBGFit.Copy((((GPeak&)obj).fBGFit)); + ((GPeak&)obj).DetachBackground(); } bool GPeak::InitParams(TH1 *fithist){ @@ -385,6 +386,8 @@ Bool_t GPeak::Fit(TH1 *fithist,Option_t *opt) { fithist->GetListOfFunctions()->Add(fBGFit.Clone()); //use to be a clone. SetParent(0); //fithist); + DetachBackground(); + //delete tmppeak; return true; @@ -463,6 +466,8 @@ Bool_t GPeak::FitExclude(TH1 *fithist,double xlow,double xhigh,Option_t *opt) { //Copy(*fithist->GetListOfFunctions()->FindObject(GetName())); //fithist->GetListOfFunctions()->Remove(fBGFit.GetName()); fithist->GetListOfFunctions()->Add(fBGFit.Clone()); //use to be a clone. + DetachBackground(); + return true; @@ -534,3 +539,8 @@ void GPeak::DrawResiduals(TH1 *hist) const{ delete[] res; delete[] bin; } + +void GPeak::DetachBackground() { + fBGFit.SetParent(0); + fBGFit.SetBit(TObject::kCanDelete,false); +} diff --git a/libraries/GROOT/GPopup.cxx b/libraries/GROOT/GPopup.cxx index 4c1f8ee4..59605e44 100644 --- a/libraries/GROOT/GPopup.cxx +++ b/libraries/GROOT/GPopup.cxx @@ -15,42 +15,55 @@ GPopup::GPopup(const TGWindow *p,const TGWindow *main, UInt_t w, : TGTransientFrame(p,main,w,h,options) { SetCleanup(kDeepCleanup); - TGVerticalFrame *vframe = new TGVerticalFrame(this,500,200); + //TGVerticalFrame *vframe = new TGVerticalFrame(this,500,200); - TGListView *listv = new TGListView(vframe,500,200); - TGLVContainer *listc = new TGLVContainer(listv->GetViewPort(),500,200, - kHorizontalFrame,fgWhitePixel); + //TGListView *listv = new TGListView(vframe,500,200); + //TGLVContainer *listc = new TGLVContainer(listv->GetViewPort(),500,200, + // kHorizontalFrame,fgWhitePixel); //listc->Associate(this); - listv->SetContainer(listc); - listv->GetViewPort()->SetBackgroundColor(fgWhitePixel); - listv->SetViewMode(kLVList); + //listv->SetContainer(listc); + //listv->GetViewPort()->SetBackgroundColor(fgWhitePixel); + //listv->SetViewMode(kLVList); //listv->SetIncremental(1,19); - vframe->AddFrame(listv,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); + //SetFrames(); + //Init(); + + //vframe->AddFrame(listv,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); - TGHorizontalFrame *hframe = new TGHorizontalFrame(vframe,500,20); - TGTextButton *b1 = new TGTextButton(hframe,"&button1"); - TGTextButton *b2 = new TGTextButton(hframe,"&button2"); - b1->Connect("Clicked()","GPopup",this,"Print()"); - b2->Connect("Clicked()","GPopup",this,"Print()"); + //TGHorizontalFrame *hframe = new TGHorizontalFrame(vframe,500,20); + //TGTextButton *b1 = new TGTextButton(hframe,"&button1"); + //TGTextButton *b2 = new TGTextButton(hframe,"&button2"); + //b1->Connect("Clicked()","GPopup",this,"Print()"); + //b2->Connect("Clicked()","GPopup",this,"Print()"); + + //hframe->AddFrame(b1,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); + //hframe->AddFrame(b2,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); - hframe->AddFrame(b1,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); - hframe->AddFrame(b2,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); + //vframe->AddFrame(hframe,new TGLayoutHints(kLHintsExpandX)); - vframe->AddFrame(hframe,new TGLayoutHints(kLHintsExpandX)); + //this->AddFrame(vframe,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); - this->AddFrame(vframe,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY)); + //MapSubwindows(); + //Resize(); // resize to default size + // position relative to the parent's window + //CenterOnParent(); + //SetWindowName("Dialog"); + //MapWindow(); + //fClient->WaitFor(this); // otherwise canvas contextmenu does not work +} +void GPopup::Init() { + MapSubwindows(); Resize(); // resize to default size // position relative to the parent's window CenterOnParent(); //SetWindowName("Dialog"); MapWindow(); - //fClient->WaitFor(this); // otherwise canvas contextmenu does not work -} +} GPopup::~GPopup() { diff --git a/libraries/GROOT/GRootCanvas.cxx b/libraries/GROOT/GRootCanvas.cxx index b188ee60..5de90e82 100644 --- a/libraries/GROOT/GRootCanvas.cxx +++ b/libraries/GROOT/GRootCanvas.cxx @@ -345,7 +345,12 @@ void GRootCanvas::CreateCanvas(const char *name) if (!img) { Int_t sav = gErrorIgnoreLevel; gErrorIgnoreLevel = kFatal; - img = TImage::Create() ? 1 : -1; + TImage* itmp = TImage::Create(); + img = itmp ? 1 : -1; + if (itmp) { + delete itmp; + itmp=NULL; + } gErrorIgnoreLevel = sav; } if (img > 0) { @@ -1496,19 +1501,23 @@ void GRootCanvas::ShowEditor(Bool_t show) if (show && (!fEditor || !((TGedEditor *)fEditor)->IsMapped())) { printf("I am here GRootCanvas 1476.\n"); if (!browser->GetTabLeft()->GetTabTab("Pad Editor")) { - browser->StartEmbedding(TRootBrowser::kLeft); - if (!fEditor) - fEditor = TVirtualPadEditor::GetPadEditor(kTRUE); - else { - ((TGedEditor *)fEditor)->ReparentWindow(fClient->GetRoot()); - ((TGedEditor *)fEditor)->MapWindow(); - } - browser->StopEmbedding("Pad Editor"); - fEditor->SetGlobal(kFALSE); - gROOT->GetListOfCleanups()->Remove((TGedEditor *)fEditor); - if (fEditor) { - ((TGedEditor *)fEditor)->SetCanvas(fCanvas); - ((TGedEditor *)fEditor)->SetModel(fCanvas, fCanvas, kButton1Down); + if (browser->GetActFrame()) { //already in edit mode + TTimer::SingleShot(200, "TRootCanvas", this, "ShowEditor(=kTRUE)"); + } else { + browser->StartEmbedding(TRootBrowser::kLeft); + if (!fEditor) + fEditor = TVirtualPadEditor::GetPadEditor(kTRUE); + else { + ((TGedEditor *)fEditor)->ReparentWindow(fClient->GetRoot()); + ((TGedEditor *)fEditor)->MapWindow(); + } + browser->StopEmbedding("Pad Editor"); + if (fEditor) { + fEditor->SetGlobal(kFALSE); + gROOT->GetListOfCleanups()->Remove((TGedEditor *)fEditor); + ((TGedEditor *)fEditor)->SetCanvas(fCanvas); + ((TGedEditor *)fEditor)->SetModel(fCanvas, fCanvas, kButton1Down); + } } } else diff --git a/libraries/GROOT/GRootCommands.cxx b/libraries/GROOT/GRootCommands.cxx index 89b9dd5a..ab73cecd 100644 --- a/libraries/GROOT/GRootCommands.cxx +++ b/libraries/GROOT/GRootCommands.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include //#include @@ -57,6 +58,8 @@ void Version() { system(Form("%s/bin/grutinizer-config --version", getenv("GRUTSYS"))); } + +/* bool GetProjectionX(GH2D *hist,double low, double high, double bg_low,double bg_high){ if(!hist) return 0; GCanvas *C_projections = 0; @@ -78,7 +81,7 @@ bool GetProjectionX(GH2D *hist,double low, double high, double bg_low,double bg_ C_projections->cd(1); GH1D *Proj_y = hist->ProjectionX("Gamma_Gamma_xProjection"); - GH1D *Proj_y_Clone = (GH1D*)Proj_y->Clone(); + GH1D *Proj_y_Clone = (GH1D*)Proj_y->Clone(); GH1D *Proj_gated = 0; if(bg_high>0 && bg_low>0){ @@ -89,7 +92,7 @@ bool GetProjectionX(GH2D *hist,double low, double high, double bg_low,double bg_ Proj_y->GetXaxis()->SetTitle("Energy [keV]"); Proj_y->GetYaxis()->SetTitle("Counts"); - + double Grace = 300; @@ -104,7 +107,7 @@ bool GetProjectionX(GH2D *hist,double low, double high, double bg_low,double bg_ Proj_y->Draw(); double Projy_Max = Proj_y->GetMaximum(); double Projy_Min = Proj_y->GetMinimum(); - + TLine *CutLow = new TLine(low,Projy_Min,low,Projy_Max); TLine *CutHigh = new TLine(high,Projy_Min,high,Projy_Max); TLine *BGLow = new TLine(bg_low,Projy_Min,bg_low,Projy_Max); @@ -124,13 +127,11 @@ bool GetProjectionX(GH2D *hist,double low, double high, double bg_low,double bg_ if(bg_low>0 && bg_high>0){ BGHigh->Draw("same"); BGLow->Draw("same"); - Proj_gated = Proj_y_Clone->Project_Background(low,high, - bg_low,bg_high, - kRegionBackground); + Proj_gated = Proj_y_Clone->Project(low,high,bg_low,bg_high,kRegionBackground); }else{ Proj_gated = Proj_y_Clone->Project(low,high); } - + if(bg_high>0 && bg_low>0){ Proj_gated->SetTitle(Form("Gate From [%.01f,%.01f] with Background [%.01f,%.01f]",low,high,bg_low,bg_high)); }else{ @@ -138,28 +139,31 @@ bool GetProjectionX(GH2D *hist,double low, double high, double bg_low,double bg_ } Proj_gated->GetXaxis()->SetTitle("Energy [keV]"); Proj_gated->GetYaxis()->SetTitle("Counts"); - + C_projections->cd(2); Proj_gated->Draw(); return 1; } +*/ -bool GetProjectionX(GH2D *hist,GH2D *hist2, + +/* +bool GetProjectionX(GH2D *hist,GH2D *hist2, double low, double high, double bg_low,double bg_high, - bool overlay, + bool overlay, double back_low,double back_high, double back_bg_low, double back_bg_high, bool back_overlay){ - /* Note -> The first histogram, ie hist, is used to draw the total projection. - The second histogram, ie hist2, is used to draw the background - subtracted spectrum. This way you can have different bins. - - */ + //Note -> The first histogram, ie hist, is used to draw the total projection. + // The second histogram, ie hist2, is used to draw the background + // subtracted spectrum. This way you can have different bins. + // + // if(!hist || !hist2) return 0; gStyle->SetOptStat(0); - + GCanvas *C_projections = 0; GCanvas *C_gammagamma = 0; if(gROOT->GetListOfCanvases()->FindObject("C_projections")){ @@ -169,7 +173,7 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, C_projections->Divide(2,2); else C_projections->Divide(1,2); - + } else{ C_projections = new GCanvas("C_projections","Projection Canvas",0,0,1675,900); @@ -186,11 +190,11 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, C_gammagamma->cd(); hist->Draw(); - + C_projections->cd(1); GH1D *Proj_y = hist->ProjectionX("Gamma_Gamma_xProjection"); GH1D *Proj_y2 = hist2->ProjectionX("Gamma_Gamma_xProjection2"); - + GH2D *hist_Clone = (GH2D*)hist->Clone(); GH2D *hist2_Clone = (GH2D*)hist2->Clone(); @@ -226,7 +230,7 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, Proj_y->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize)); Proj_back_y->GetXaxis()->SetTitle("Energy [keV]"); Proj_back_y->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize)); - + double Grace = 300; @@ -241,7 +245,7 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, Proj_y->Draw(); double Projy_Max = Proj_y->GetMaximum(); double Projy_Min = Proj_y->GetMinimum(); - + TLine *CutLow = new TLine(low,Projy_Min,low,Projy_Max); TLine *CutHigh = new TLine(high,Projy_Min,high,Projy_Max); TLine *BGLow = new TLine(bg_low,Projy_Min,bg_low,Projy_Max); @@ -271,7 +275,7 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, Proj_gated2 = Proj_y2_Clone2->Project(low,high); Proj_gated2->SetLineColor(2); } - + if(bg_high>0 && bg_low>0){ Proj_gated->SetTitle(Form("Gate From [%.01f,%.01f] with Background [%.01f,%.01f]",low,high,bg_low,bg_high)); if(overlay) @@ -284,8 +288,8 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, double binsize_gated = (Proj_gated->GetXaxis()->GetXmax()-Proj_gated->GetXaxis()->GetXmin())/Proj_gated->GetXaxis()->GetNbins(); Proj_gated->GetXaxis()->SetTitle("Energy [keV]"); Proj_gated->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize_gated)); - - + + C_projections->cd(2); if(overlay){ Proj_gated2->GetXaxis()->SetTitle("Energy [keV]"); @@ -305,7 +309,7 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, gPad->Clear(); C_projections->cd(4); gPad->Clear(); - + if(back_low>0 && back_high>0){ C_projections->cd(3); double back_ZoomHigh = back_high+Grace; @@ -320,7 +324,7 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, Proj_back_y->Draw(); double Proj_back_y_Max = Proj_back_y->GetMaximum(); double Proj_back_y_Min = Proj_back_y->GetMinimum(); - + TLine *back_CutLow = new TLine(back_low,Proj_back_y_Min,back_low,Proj_back_y_Max); TLine *back_CutHigh = new TLine(back_high,Proj_back_y_Min,back_high,Proj_back_y_Max); TLine *back_BGLow = new TLine(back_bg_low,Proj_back_y_Min,back_bg_low,Proj_back_y_Max); @@ -346,12 +350,12 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, }else{ Proj_gated_back = Proj_back_y2_Clone->Project(back_low,back_high); } - + if(back_overlay){ Proj_gated_back2 = Proj_back_y2_Clone2->Project(back_low,back_high); Proj_gated_back2->SetLineColor(2); } - + if(back_bg_high>0 && back_bg_low>0){ Proj_gated_back->SetTitle(Form("Gate From [%.01f,%.01f] with Background [%.01f,%.01f]", back_low,back_high,back_bg_low,back_bg_high)); @@ -369,7 +373,7 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, double binsize_back_gated = (Proj_gated_back->GetXaxis()->GetXmax()-Proj_gated_back->GetXaxis()->GetXmin())/Proj_gated_back->GetXaxis()->GetNbins(); Proj_gated_back->GetXaxis()->SetTitle("Energy [keV]"); Proj_gated_back->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize_back_gated)); - + C_projections->cd(4); if(back_overlay){ Proj_gated_back2->GetXaxis()->SetTitle("Energy [keV]"); @@ -388,8 +392,8 @@ bool GetProjectionX(GH2D *hist,GH2D *hist2, return 1; } - - +*/ +/* bool GetProjectionY(GH2D *hist,double low, double high, double bg_low,double bg_high){ if(!hist) return 0; GCanvas *C_projections = 0; @@ -408,10 +412,10 @@ bool GetProjectionY(GH2D *hist,double low, double high, double bg_low,double bg_ C_gammagamma->cd(); hist->Draw(); - + C_projections->cd(1); GH1D *Proj_y = hist->ProjectionY("Gamma_Gamma_yProjection"); - GH1D *Proj_y_Clone = (GH1D*)Proj_y->Clone(); + GH1D *Proj_y_Clone = (GH1D*)Proj_y->Clone(); GH1D *Proj_gated = 0; if(bg_high>0 && bg_low>0){ @@ -422,7 +426,7 @@ bool GetProjectionY(GH2D *hist,double low, double high, double bg_low,double bg_ Proj_y->GetXaxis()->SetTitle("Energy [keV]"); Proj_y->GetYaxis()->SetTitle("Counts"); - + double Grace = 300; double ZoomHigh = high+Grace; double ZoomLow = low-Grace; @@ -435,7 +439,7 @@ bool GetProjectionY(GH2D *hist,double low, double high, double bg_low,double bg_ Proj_y->Draw(); double Projy_Max = Proj_y->GetMaximum(); double Projy_Min = Proj_y->GetMinimum(); - + TLine *CutLow = new TLine(low,Projy_Min,low,Projy_Max); TLine *CutHigh = new TLine(high,Projy_Min,high,Projy_Max); TLine *BGLow = new TLine(bg_low,Projy_Min,bg_low,Projy_Max); @@ -475,22 +479,23 @@ bool GetProjectionY(GH2D *hist,double low, double high, double bg_low,double bg_ return 1; } -bool GetProjectionY(GH2D *hist,GH2D *hist2, +bool GetProjectionY(GH2D *hist,GH2D *hist2, + double low, double high, double bg_low,double bg_high, - bool overlay, + bool overlay, double back_low,double back_high, double back_bg_low, double back_bg_high, bool back_overlay){ - /* Note -> The first histogram, ie hist, is used to draw the total projection. - The second histogram, ie hist2, is used to draw the background - subtracted spectrum. This way you can have different bins. - - */ + // Note -> The first histogram, ie hist, is used to draw the total projection. + // The second histogram, ie hist2, is used to draw the background + // subtracted spectrum. This way you can have different bins. + // + // if(!hist || !hist2) return 0; gStyle->SetOptStat(0); - + GCanvas *C_projections = 0; GCanvas *C_gammagamma = 0; if(gROOT->GetListOfCanvases()->FindObject("C_projections")){ @@ -500,7 +505,7 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, C_projections->Divide(2,2); else C_projections->Divide(1,2); - + } else{ C_projections = new GCanvas("C_projections","Projection Canvas",0,0,1675,900); @@ -517,11 +522,11 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, C_gammagamma->cd(); hist->Draw(); - + C_projections->cd(1); GH1D *Proj_y = hist->ProjectionY("Gamma_Gamma_yProjection"); GH1D *Proj_y2 = hist2->ProjectionY("Gamma_Gamma_yProjection2"); - + GH2D *hist_Clone = (GH2D*)hist->Clone(); GH2D *hist2_Clone = (GH2D*)hist2->Clone(); @@ -557,7 +562,7 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, Proj_y->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize)); Proj_back_y->GetXaxis()->SetTitle("Energy [keV]"); Proj_back_y->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize)); - + double Grace = 300; @@ -572,7 +577,7 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, Proj_y->Draw(); double Projy_Max = Proj_y->GetMaximum(); double Projy_Min = Proj_y->GetMinimum(); - + TLine *CutLow = new TLine(low,Projy_Min,low,Projy_Max); TLine *CutHigh = new TLine(high,Projy_Min,high,Projy_Max); TLine *BGLow = new TLine(bg_low,Projy_Min,bg_low,Projy_Max); @@ -602,7 +607,7 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, Proj_gated2 = Proj_y2_Clone2->Project(low,high); Proj_gated2->SetLineColor(2); } - + if(bg_high>0 && bg_low>0){ Proj_gated->SetTitle(Form("Gate From [%.01f,%.01f] with Background [%.01f,%.01f]",low,high,bg_low,bg_high)); if(overlay) @@ -615,8 +620,8 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, double binsize_gated = (Proj_gated->GetXaxis()->GetXmax()-Proj_gated->GetXaxis()->GetXmin())/Proj_gated->GetXaxis()->GetNbins(); Proj_gated->GetXaxis()->SetTitle("Energy [keV]"); Proj_gated->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize_gated)); - - + + C_projections->cd(2); if(overlay){ Proj_gated2->GetXaxis()->SetTitle("Energy [keV]"); @@ -636,7 +641,7 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, gPad->Clear(); C_projections->cd(4); gPad->Clear(); - + if(back_low>0 && back_high>0){ C_projections->cd(3); double back_ZoomHigh = back_high+Grace; @@ -651,7 +656,7 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, Proj_back_y->Draw(); double Proj_back_y_Max = Proj_back_y->GetMaximum(); double Proj_back_y_Min = Proj_back_y->GetMinimum(); - + TLine *back_CutLow = new TLine(back_low,Proj_back_y_Min,back_low,Proj_back_y_Max); TLine *back_CutHigh = new TLine(back_high,Proj_back_y_Min,back_high,Proj_back_y_Max); TLine *back_BGLow = new TLine(back_bg_low,Proj_back_y_Min,back_bg_low,Proj_back_y_Max); @@ -677,12 +682,12 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, }else{ Proj_gated_back = Proj_back_y2_Clone->Project(back_low,back_high); } - + if(back_overlay){ Proj_gated_back2 = Proj_back_y2_Clone2->Project(back_low,back_high); Proj_gated_back2->SetLineColor(2); } - + if(back_bg_high>0 && back_bg_low>0){ Proj_gated_back->SetTitle(Form("Gate From [%.01f,%.01f] with Background [%.01f,%.01f]", back_low,back_high,back_bg_low,back_bg_high)); @@ -700,7 +705,7 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, double binsize_back_gated = (Proj_gated_back->GetXaxis()->GetXmax()-Proj_gated_back->GetXaxis()->GetXmin())/Proj_gated_back->GetXaxis()->GetNbins(); Proj_gated_back->GetXaxis()->SetTitle("Energy [keV]"); Proj_gated_back->GetYaxis()->SetTitle(Form("Counts / %.0f keV",binsize_back_gated)); - + C_projections->cd(4); if(back_overlay){ Proj_gated_back2->GetXaxis()->SetTitle("Energy [keV]"); @@ -719,6 +724,8 @@ bool GetProjectionY(GH2D *hist,GH2D *hist2, return 1; } +*/ + int LabelPeaks(TH1 *hist,double sigma,double thresh,Option_t *opt) { TSpectrum::StaticSearch(hist,sigma,"Qnodraw",thresh); @@ -819,18 +826,18 @@ GGaus *GausFit(TH1 *hist,double xlow, double xhigh,Option_t *opt) { } -TF1 *DoubleGausFit(TH1 *hist,double cent1,double cent2,double xlow, double xhigh,Option_t *opt) { +GDoubleGaus *DoubleGausFit(TH1 *hist,double cent1,double cent2,double xlow, double xhigh,Option_t *opt) { if(!hist) return 0; if(xlow>xhigh) std::swap(xlow,xhigh); //std::cout << "here." << std::endl; - - GGaus *mypeak= new GGaus(xlow,xhigh); + + GDoubleGaus *mypeak= new GDoubleGaus(cent1,cent2,xlow,xhigh); std::string options = opt; options.append("Q+"); - mypeak->Fit(hist,options.c_str()); + mypeak->Fit(hist,cent1,cent2,options.c_str()); //mypeak->Background()->Draw("SAME"); TF1 *bg = new TF1(*mypeak->Background()); hist->GetListOfFunctions()->Add(bg); @@ -847,10 +854,10 @@ TF1 *DoubleGausFit(TH1 *hist,double cent1,double cent2,double xlow, double xhigh -/* - - - +/* + + + ======= @@ -1037,8 +1044,13 @@ void StartGUI() { std::istreambuf_iterator()); TPython::Exec(script_text.c_str()); - TTimer* gui_timer = new TTimer("TPython::Exec(\"update()\");", 10, true); - gui_timer->TurnOn(); + // TTimer* gui_timer = new TTimer("TPython::Exec(\"update()\");", 10, true); + // gui_timer->TurnOn(); + TTimer* gui_timer = new TTimer(); + DummyGuiCaller* dummy_gui_caller = new DummyGuiCaller; + gui_timer->Connect("Timeout()", "DummyGuiCaller", + dummy_gui_caller, "CallUpdate()"); + gui_timer->Start(10, false); gui_is_running = true; for(int i=0;iGetListOfFiles()->GetSize();i++) { @@ -1051,7 +1063,14 @@ bool GUIIsRunning() { return gui_is_running; } +void DummyGuiCaller::CallUpdate() { + TPython::Exec("update()"); +} + + + +/* TH2 *AddOffset(TH2 *mat,double offset,EAxis axis) { TH2 *toreturn = 0; @@ -1060,32 +1079,6 @@ TH2 *AddOffset(TH2 *mat,double offset,EAxis axis) { //int dim = mat->GetDimension(); int xmax = mat->GetXaxis()->GetNbins()+1; int ymax = mat->GetYaxis()->GetNbins()+1; - /* - switch(dim) { - case 3: - xmax = mat->GetXaxis()->GetNbins()+1; - ymax = mat->GetYaxis()->GetNbins()+1; - zmax = mat->GetZaxis()->GetNbins()+1; - break; - case 2: - if(axis>3) { - fprintf(stderr,"%s z-axis offest called on %s but has no z-axis", - __PRETTY_FUNCTION__,mat->GetName()) - return toreturn; - } - xmax = mat->GetXaxis()->GetNbins()+1; - ymax = mat->GetYaxis()->GetNbins()+1; - break; - case 1: - if(axis!=1) { - fprintf(stderr,"%s offest called on %s with an axis it doesn't have.", - __PRETTY_FUNCTION__,mat->GetName()) - return toreturn; - } - xmax = mat->GetXaxis()->GetNbins()+1; - break; - }; - */ toreturn = (TH2*)mat->Clone(Form("%s_offset",mat->GetName())); toreturn->Reset(); @@ -1103,12 +1096,4 @@ TH2 *AddOffset(TH2 *mat,double offset,EAxis axis) { } return toreturn; } - - - - - - - - - +*/ diff --git a/libraries/GROOT/GRootFunctions.cxx b/libraries/GROOT/GRootFunctions.cxx index cece21b7..360f7715 100644 --- a/libraries/GROOT/GRootFunctions.cxx +++ b/libraries/GROOT/GRootFunctions.cxx @@ -2,6 +2,10 @@ #include "GRootFunctions.h" #include "TF1.h" +#include +#include + + NamespaceImp(GRootFunctions) @@ -85,6 +89,36 @@ Double_t GRootFunctions::Gaus(Double_t *dim, Double_t *par) { return height*(1.0-R/100.0)*TMath::Gaus(x,cent,sigma); } + +Double_t GRootFunctions::DoubleGaus(Double_t *dim, Double_t *par) { + // - dim[0]: channels to fit + // - par[0]: height of peak1 + // - par[1]: cent of peak1 + // - par[2]: height of peak2 + // - par[3]: cent of peak2 + // - par[4]: shared sigma + // - par[5]: bg offset + // - par[6]: bg slope + + Double_t x = dim[0]; + Double_t height1 = par[0]; + Double_t cent1 = par[1]; + + Double_t height2 = par[2]; + Double_t cent2 = par[3]; + + Double_t sigma = par[4]; + + + + return height1*TMath::Gaus(x,cent1,sigma) + height2*TMath::Gaus(x,cent2,sigma) + PolyBg(dim,(par+5),2); +} + + + + + + Double_t GRootFunctions::SkewedGaus(Double_t *dim,Double_t *par) { // StepFunction(dim,par) + PolyBg @@ -249,20 +283,148 @@ Double_t GRootFunctions::GammaEff(Double_t *x,Double_t *par) { } +Double_t GRootFunctions::AlignedAD(Double_t *x,Double_t *par) { + double p2 = ::ROOT::Math::legendre(2,TMath::Cos(TMath::DegToRad()*x[0])); + double p4 = ::ROOT::Math::legendre(4,TMath::Cos(TMath::DegToRad()*x[0])); + return par[0] + par[1]*p2 + par[2]*p4; +} -Double_t GRootFunctions::ComptonFormula(Double_t *x,Double_t *par) { +Double_t GRootFunctions::AlignedAD_Norm(Double_t *x,Double_t *par) { + double p2 = ::ROOT::Math::legendre(2,TMath::Cos(TMath::DegToRad()*x[0])); + double p4 = ::ROOT::Math::legendre(4,TMath::Cos(TMath::DegToRad()*x[0])); + return par[0] * (1 + par[1]*p2 + par[2]*p4); +} - //par[0] = inital gamma energy; in keV. +Double_t GRootFunctions::AlignedADPol_Norm(Double_t *x,Double_t *par) { + + double p2 = ::ROOT::Math::legendre(2,TMath::Cos(TMath::DegToRad()*x[0])); + double p4 = ::ROOT::Math::legendre(4,TMath::Cos(TMath::DegToRad()*x[0])); + double ap2 = ::ROOT::Math::assoc_legendre(2,2,TMath::Cos(TMath::DegToRad()*x[0])); + double ap4 = ::ROOT::Math::assoc_legendre(4,2,TMath::Cos(TMath::DegToRad()*x[0])); + + double phi = TMath::DegToRad()*x[1]; + + double part2 = par[1]*(p2 +(1./2.)*TMath::Cos(2*phi)*ap2); + double part4 = par[2]*(p4 -(1./12.)*TMath::Cos(2*phi)*ap4); + + return par[0] * (1 + part2 + part4); +} + + + +Double_t GRootFunctions::Polarization(Double_t *x,Double_t *par) { + + //par[0] = Ao + //par[1] = a2 + //par[2] = a4 + + double p2 = ::ROOT::Math::legendre(2,TMath::Cos(TMath::DegToRad()*x[0])); + double p4 = ::ROOT::Math::legendre(4,TMath::Cos(TMath::DegToRad()*x[0])); + double ap2 = ::ROOT::Math::assoc_legendre(2,2,TMath::Cos(TMath::DegToRad()*x[0])); + double ap4 = ::ROOT::Math::assoc_legendre(4,2,TMath::Cos(TMath::DegToRad()*x[0])); + + + double k2 = (1./2.); + double k4 = (-1./12); + + return (1/par[0]) * ( par[1]*k2*ap2 + par[2]*k4*ap4 ) / ( 1 + par[1]*p2 + par[2]*p4 ); + +} + + + +Double_t GRootFunctions::ComptonEnergy(Double_t *x,Double_t *par) { + //par[0] = inital gamma energy; in keV. double lower = 1 + (par[0]/511.)*(1-TMath::Cos(TMath::DegToRad()*x[0])); return par[0]/lower; } +Double_t GRootFunctions::ComptonAngle(Double_t *x,Double_t *par) { + //par[0] = inital gamma energy; in keV. + if(x[0]>par[0]) + return 0.00; + + double inside = (1./x[0] - 1./par[0]); + inside*=511.; + inside+= -1; + //printf("inside[%.02f] = %.023f\n",x[0],inside); + return TMath::ACos(inside)*TMath::RadToDeg(); + +} + +Double_t GRootFunctions::ComptonRatio(Double_t *x,Double_t *par) { + //no parameters + //x[0] = Initial Energy + //x[1] = Scattering Angle (deg) + //returns E'/E + + double temp = 1 + (x[0]/511.)*(1-TMath::Cos(x[1]*TMath::DegToRad())); + return 1/temp; +} + +Double_t GRootFunctions::KN_unpol(Double_t *x,Double_t *par) { + + //par[0] = energy of the intial gamma; + //x[0] = compton scattering angle; + + double e0 = 8.854187817620E-12; + double J2KeV = 6.242e+12; + double me = 0.511046 / J2KeV; + double re = (1/(4.*TMath::Pi()*e0)) * (TMath::Qe()*TMath::Qe())/me; + + double y[2] = {par[0],x[0]}; + double cr = ComptonRatio(y,0); + + return 0.5*re * (cr)*(cr) * ( (1/cr) + cr - TMath::Power(TMath::Sin(x[0]*TMath::DegToRad()),2) ); + //return 0.5*((4.*TMath::Pi()))* (cr)*(cr) * ( (1/cr) + cr - TMath::Power(TMath::Sin(x[0]*TMath::DegToRad()),2) ); + +} + +Double_t GRootFunctions::KN_unpol_norm(Double_t *x,Double_t *par) { + + //par[0] = energy of the intial gamma; + //par[1] = energy of the normalization gamma; + //x[0] = compton scattering angle; + + return KN_unpol(x,&par[0]) / KN_unpol(x,&par[1]); + +} + + + + + + +Double_t GRootFunctions::KN_pol(Double_t *x,Double_t *par) { + + //par[0] = energy of the intial gamma; + //x[0] = compton scattering angle; + //x[1] = angle between electric field vector and scattering plane + + double e0 = 8.854187817620E-12; + double J2KeV = 6.242e+12; + double me = 0.511046 / J2KeV; + double re = (1/(4.*TMath::Pi()*e0)) * (TMath::Qe()*TMath::Qe())/me; + + double y[2] = {par[0],x[0]}; + double cr = ComptonRatio(y,0); + + return 0.5*re * (cr)*(cr) * ( (1/cr) + cr - + 2 * TMath::Power(TMath::Sin(x[0]*TMath::DegToRad()),2) + * TMath::Power(TMath::Cos(x[1]*TMath::DegToRad()),2) ); + +} + + + + Double_t GRootFunctions::AnalyzingPower(Double_t *x,Double_t *par) { //par[0] = inital gamma energy; in keV. - double scattered = ComptonFormula(x,par); + //x[0] = compton scattering angle. + double scattered = ComptonEnergy(x,par); double sin2 = (TMath::Sin(TMath::DegToRad()*x[0]))*(TMath::Sin(TMath::DegToRad()*x[0])); double lower = scattered/par[0] + par[0]/scattered - sin2; @@ -270,4 +432,293 @@ Double_t GRootFunctions::AnalyzingPower(Double_t *x,Double_t *par) { } +Double_t GRootFunctions::W_pol(Double_t *x, Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + + //x[0] theta, from beam axis; + //x[1] compton scattering angle; + //x[2] angle between the reaction plane and the compton scattering plane; zeta + + + double w = AlignedAD_Norm(&x[0],par); + double kn = KN_unpol(&x[1],&par[3]); + kn = 1.0; + double an = AnalyzingPower(&x[1],&par[3]); + double p = Polarization(&x[0],par); + + return w*kn*(1-0.5*an*p*TMath::Cos(2*x[2]*TMath::DegToRad())); + +} + +Double_t GRootFunctions::W_pol_norm(Double_t *x, Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] Normalizedd gamma energy; + + //x[0] theta, from beam axis; + //x[1] compton scattering angle; + //x[2] angle between the reaction plane and the compton scattering plane; zeta + + + double w = AlignedAD_Norm(&x[0],par); + double kn = KN_unpol(&x[1],&par[3]); + double kn_norm = KN_unpol(&x[1],&par[4]); + double an = AnalyzingPower(&x[1],&par[3]); + double p = Polarization(&x[0],par); + + return w*kn*(1-0.5*an*p*TMath::Cos(2*x[2]*TMath::DegToRad())); + +} + +Double_t GRootFunctions::Q_pol(Double_t *x, Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] Compton Scattering Angle; + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; zeta + + double y[3] = { x[0],par[4],x[1] }; + double w = W_pol(y,par); + double w_unpol = AlignedAD_Norm(&x[0],par); + double p = Polarization(&y[0],par); + + return (1-w/w_unpol)/p; +} + + +Double_t GRootFunctions::W_pol2(Double_t *x, Double_t *par) { + + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] compton scattering angle; + //par[5] scaling. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + //return 1e15*par[5]*GRootFunctions::W_pol(y,par); + return par[5]*GRootFunctions::W_pol(y,par); +} + +Double_t GRootFunctions::W_pol_dirk(Double_t *x, Double_t *par) { + + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] compton scattering angle; + //par[5] phi - shift. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + double y2[3] = { x[0],par[4],x[1]+par[5] }; + + return (GRootFunctions::W_pol(y,par) - GRootFunctions::W_pol(y2,par)) / + (GRootFunctions::W_pol(y,par) + GRootFunctions::W_pol(y2,par)); + + //return 1e15*par[5]*GRootFunctions::W_pol(y,par); + //return par[5]*GRootFunctions::W_pol(y,par); +} + +Double_t GRootFunctions::W_pol_dirk2(Double_t *x, Double_t *par) { + + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] compton scattering angle; + //par[5] phi - shift. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + double y2[3] = { x[0],par[4],x[1]+par[5] }; + + return (GRootFunctions::W_pol(y,par) / + GRootFunctions::W_pol(y2,par)); + + //return 1e15*par[5]*GRootFunctions::W_pol(y,par); + //return par[5]*GRootFunctions::W_pol(y,par); +} + + + + + + +Double_t GRootFunctions::W_pol3(Double_t *x,Double_t *par) { + + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] compton scattering angle; + //par[5] scaling on cos(2*zeta) term.. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + + double w = AlignedAD_Norm(&y[0],par); + double kn = KN_unpol(&y[1],&par[3]); + double an = AnalyzingPower(&y[1],&par[3]); + double p = Polarization(&y[0],par); + + return w*kn*(1-0.5*an*p*par[5]*TMath::Cos(2*y[2]*TMath::DegToRad())); + + +} + +Double_t GRootFunctions::W_pol4(Double_t *x,Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] overall scaling. compton scattering angle; + //par[5] scaling on cos(2*zeta) term.. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + + double w = AlignedAD_Norm(&y[0],par); + //double kn = KN_unpol(&y[1],&par[3]); + double kn = par[4]; + //double an = AnalyzingPower(&y[1],&par[3]); + double p = Polarization(&y[0],par); + + return w*kn*(1-0.5*p*par[5]*TMath::Cos(2*y[2]*TMath::DegToRad())); + +} + +Double_t GRootFunctions::W_pol5(Double_t *x,Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] compton scattering angle; + // //par[5] scaling on cos(2*zeta) term.. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + + double w = AlignedAD_Norm(&y[0],par); + double kn = KN_unpol(&y[1],&par[3]); + kn = 1.0; + double an = AnalyzingPower(&y[1],&par[3]); + double p = Polarization(&y[0],par); + + return par[5]*w*kn*(1-0.5*p*an*TMath::Cos(2*y[2]*TMath::DegToRad())); + +} + +Double_t GRootFunctions::W_pol6(Double_t *x,Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] compton scattering angle; + // //par[5] scaling on cos(2*zeta) term.. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + + //double //w = AlignedAD_Norm(&y[0],par); + //double w = 1.0; + //double //kn = KN_unpol(&y[1],&par[3]); + //double kn = 1.0; + //double //an = AnalyzingPower(&y[1],&par[3]); + double p = Polarization(&x[0],par); + + //return par[5]*w*kn*(1-0.5*p*an*TMath::Cos(2*y[2]*TMath::DegToRad())); + return par[5]*(1-0.5*p*par[4]*TMath::Cos(2*x[1]*TMath::DegToRad())); + +} + + +Double_t GRootFunctions::W_pol_test(Double_t *x,Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] analizing power scale; + //par[5] overall scale. + + //par[6] turn off angular distribution. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double y[3] = { x[0],par[4],x[1] }; + + double w = AlignedAD_Norm(&y[0],par); + if(par[6]>0) w =1.0; + double kn = 1.0; // KN_unpol(&y[1],&par[3]); + double an = par[4]; //AnalyzingPower(&y[1],&par[3]); + double p = Polarization(&y[0],par); + + return par[5]*w*kn*(1-0.5*p*an*TMath::Cos(2*y[2]*TMath::DegToRad())); +} + +Double_t GRootFunctions::W_pol_diff(Double_t *x,Double_t *par) { + //par[0] A0 + //par[1] a2 + //par[2] a4 + //par[3] Inital gamma energy; + //par[4] analizing power scale; + //par[5] overall scale. + //par[6] turn off angular distribution. + + //x[0] theta, from beam axis; + //x[1] angle between the reaction plane and the compton scattering plane; + + double par2[7]; + par2[0] = par[0]; + par2[1] = par[1]; + par2[2] = par[2]; + par2[3] = par[3]; + par2[4] = -par[4]; + par2[5] = par[5]; + par2[6] = par[6]; + + return W_pol_test(x,par) - W_pol_test(x,par2); +} + + + + + +Double_t GRootFunctions::PolarizationAsymmetry(Double_t *x,Double_t *par) { + // par[0] -> overall constant ( includes integral of the analyizing power over the observed compton scattering angle) + // par[1] -> Ao + // par[2] -> a2 + // par[3] -> a4 + + // x[0] = theta; + // x[1] = angle between the reaction plane and the compton scattered plane. + + return par[0] * Polarization(&x[0],&(par[1])) * TMath::Cos(2*TMath::DegToRad()*x[1]); + +} + diff --git a/libraries/GROOT/GValue.cxx b/libraries/GROOT/GValue.cxx index d2425638..8b53041e 100644 --- a/libraries/GROOT/GValue.cxx +++ b/libraries/GROOT/GValue.cxx @@ -1,3 +1,4 @@ + #include "GValue.h" #include @@ -7,6 +8,8 @@ #include #include +#include + //std::string GValue::fValueData //std::map GValue::fValueMap; GValue *GValue::fDefaultValue = new GValue("GValue",sqrt(-1)); @@ -16,10 +19,18 @@ GValue::GValue() : fValue(0.00), fPriority(kUnset) { } GValue::GValue(const char *name,double value, EPriority priority) - : TNamed(name,name), fValue(value), fPriority(priority) { } + : fValue(value), fPriority(priority) { + std::string sname = name; + std::transform(sname.begin(),sname.end(),sname.begin(),::toupper); + SetNameTitle(sname.c_str(),sname.c_str()); + } GValue::GValue(const char *name) - : TNamed(name,name), fValue(0.00), fPriority(kUnset) { } + : fValue(0.00), fPriority(kUnset) { + std::string sname = name; + std::transform(sname.begin(),sname.end(),sname.begin(),::toupper); + SetNameTitle(sname.c_str(),sname.c_str()); +} GValue::GValue(const GValue &val) : TNamed(val) { @@ -33,6 +44,7 @@ void GValue::Copy(TObject &obj) const { } double GValue::Value(std::string name) { + std::transform(name.begin(),name.end(),name.begin(),::toupper); if(!fValueVector.count(name)) return sqrt(-1); return fValueVector.at(name)->GetValue(); @@ -40,6 +52,7 @@ double GValue::Value(std::string name) { void GValue::SetReplaceValue(std::string name, double value, EPriority priority) { + std::transform(name.begin(),name.end(),name.begin(),::toupper); GValue* gvalue = FindValue(name); if(!gvalue) { gvalue = new GValue(name.c_str(), value, priority); @@ -51,6 +64,7 @@ void GValue::SetReplaceValue(std::string name, double value, } GValue* GValue::FindValue(std::string name){ + std::transform(name.begin(),name.end(),name.begin(),::toupper); GValue* value = 0; if(!name.length()) return GetDefaultValue(); @@ -251,6 +265,7 @@ int GValue::ParseInputData(std::string input, EPriority priority, Option_t *opt) brace_open = true; name = line.substr(0,openbrace).c_str(); trim(&name); + std::transform(name.begin(),name.end(),name.begin(),::toupper); value = new GValue(name.c_str()); } //=============================================// diff --git a/libraries/GROOT/LinkDef.h b/libraries/GROOT/LinkDef.h index a7f4a569..a743b167 100644 --- a/libraries/GROOT/LinkDef.h +++ b/libraries/GROOT/LinkDef.h @@ -1,4 +1,4 @@ -// GRootGuiFactory.h GRootFunctions.h GRootCommands.h GRootCanvas.h GRootBrowser.h GCanvas.h GH2Base.h GH2I.h GH2D.h GPeak.h GGaus.h GValue.h GH1D.h GrutNotifier.h GPopup.h GSnapshot.h GCutG.h +// GRootGuiFactory.h GRootFunctions.h GRootCommands.h GRootCanvas.h GRootBrowser.h GCanvas.h GH2I.h GH2D.h GPeak.h GGaus.h GValue.h GH1D.h GrutNotifier.h GSnapshot.h GCutG.h GH1.h GH2.h GPopup.h GHistPopup.h TF1Sum.h GGraph.h GGraph2D.h GDoubleGaus.h #ifdef __CINT__ @@ -23,6 +23,7 @@ #pragma link C++ function RemovePeaks; #pragma link C++ function PhotoPeakFit; #pragma link C++ function GausFit; +#pragma link C++ function DoubleGausFit; #pragma link C++ function MergeStrings; @@ -35,40 +36,53 @@ #pragma link C++ function GrabFit; #pragma link C++ function StartGUI; #pragma link C++ function GUIIsRunning; +#pragma link C++ class DummyGuiCaller+; #pragma link C++ function GetProjectionX; #pragma link C++ function GetProjectionY; #pragma link C++ enum EAxis; #pragma link C++ enum kBackgroundSubtraction; -#pragma link C++ function AddOffset; +//#pragma link C++ function AddOffset; #pragma link C++ class GPopup+; +#pragma link C++ class GHistPopup+; #pragma link C++ class GCutG+; #pragma link C++ class GPeak+; #pragma link C++ class GGaus+; +#pragma link C++ class GDoubleGaus+; #pragma link C++ class GValue-; #pragma link C++ class std::map+; #pragma link C++ class std::pair+; #pragma link C++ class GMarker+; -#pragma link C++ class GCanvas+; +#pragma link C++ class GCanvas-; #pragma link C++ class GRootCanvas+; #pragma link C++ class GRootBrowser+; #pragma link C++ class GBrowserPlugin+; #pragma link C++ class GRootGuiFactory+; +#pragma link C++ class GH1+; +#pragma link C++ class GH2+; + #pragma link C++ class GH1D+; -#pragma link C++ class GH2Base+; #pragma link C++ class GH2I+; #pragma link C++ class GH2D+; //#pragma link C++ class GEfficiency+; +#pragma link C++ class GGraph+; +#pragma link C++ class GGraph2D+; + +#pragma link C++ class TF1Sum+; #pragma link C++ class GrutNotifier+; #pragma link C++ class GSnapshot+; + +#pragma link C++ class GHist-; +#pragma link C++ class xGH1D-; + #endif diff --git a/libraries/GROOT/TF1Sum.cxx b/libraries/GROOT/TF1Sum.cxx new file mode 100644 index 00000000..28e11e4b --- /dev/null +++ b/libraries/GROOT/TF1Sum.cxx @@ -0,0 +1,89 @@ + +#include + +//TF1Sum *TF1Sum::fTF1Sum=0; + + +void TF1Sum::AddTF1(TF1 *f) { + if(f) { + if(fTF1s.empty()) { + double min,max; + f->GetRange(min,max); + SetRange(min,max); + //SetNpx(f->GetNpx()); + } + + fTF1s.push_back(f); + int num_old_pars = GetNpar(); + int num_new_pars = f->GetNpar(); + npars= num_new_pars +num_old_pars; + + double lmin,lmax; + + for(int i=0; iGetParameter(i)); + fParErr.push_back(f->GetParError(i)); + f->GetParLimits(i,lmin,lmax); + fParMin.push_back(lmin); + fParMax.push_back(lmax); + fParName.push_back(Form("%s_par%i_%s",f->GetName(),i,f->GetParName(i))); + } + + if(fFit) { + delete fFit; + } + fFit = new TF1(Form("%s_obj",GetName()), + new TF1Sum(*this), + xlow, xhigh, npars); + for(int i=0;iSetParameter(i,fParam.at(i)); + fFit->SetParError(i,fParErr.at(i)); + fFit->SetParLimits(i,fParMin.at(i),fParMax.at(i)); + fFit->SetParName(i,fParName.at(i).c_str()); + } + } +} + +void TF1Sum::Print(Option_t *opt) const { + if(fFit) fFit->Print(opt); +} + +Double_t TF1Sum::EvalPar(const Double_t *x,const Double_t *params) { + int parnum = 0; + double sum = 0.0; + + for(auto fit : fTF1s) { + //printf("fit->GetNpar() = %i\n",fit->GetNpar()); fflush(stdout); + if(params==0) + sum += fit->EvalPar(x,params); + else + sum += fit->EvalPar(x, params+parnum); + + + parnum += fit->GetNpar(); + } + return sum; +} + + +void TF1Sum::Draw(Option_t *opt) { + TString sopt = opt; + int poffset=0; + int color=2; + if(!fFit) { + return; + } + for(int i=0;iGetNpar();i++) { + fParam[i] = fFit->GetParameter(i); + } + if(sopt.Contains("all")) { + fFit->Draw(); + } else { + for(unsigned int j=0;jSetParameters(fParam.data()+poffset); + poffset += fTF1s[j]->GetNpar(); + fTF1s[j]->SetLineColor(color++); + fTF1s[j]->Draw("same"); + } + } +} diff --git a/libraries/SourceData/eu152.sou b/libraries/SourceData/eu152.sou index 1aa30d7d..df3d93ab 100644 --- a/libraries/SourceData/eu152.sou +++ b/libraries/SourceData/eu152.sou @@ -1,25 +1,25 @@ 121.782 0.001 28.579488 0.12 244.697 0.001 7.58334 0.03 - 295.939 0.002 0.4470936 0.007 + //295.939 0.002 0.4470936 0.007 344.279 0.001 26.52272 1.5 - 367.789 0.002 0.8605954 0.018 - 411.116 0.005 2.2340934 0.018 + //367.789 0.002 0.8605954 0.018 + //411.116 0.005 2.2340934 0.018 //443 is a doublet 2.82129 + 0.33415. 443.976 0.005 3.156705 0.027 - 488.661 0.039 0.41891664 0.0046 - 563.99 0.007 0.4895028 0.009 - 586.265 0.002 0.4594114 0.019 - 678.623 0.005 0.4713912 0.015 - 688.67 0.005 0.8568096 0.012 + //488.661 0.039 0.41891664 0.0046 + //563.99 0.007 0.4895028 0.009 + //586.265 0.002 0.4594114 0.019 + //678.623 0.005 0.4713912 0.015 + //688.67 0.005 0.8568096 0.012 778.904 0.002 12.94097 0.09 867.373 0.003 4.2452328 0.029 964.079 0.018 14.606016 0.05 - 1005.272 0.017 0.6454824 0.007 + //1005.272 0.017 0.6454824 0.007 //1085 9s a doublet 10.20696 + 0.246548 1085.869 0.024 10.45351 0.04 1112.069 0.003 13.642824 0.05 - 1212.948 0.011 1.4217864 0.1 - 1299.14 0.009 1.4726796 0.029 + //1212.948 0.011 1.4217864 0.1 + //1299.14 0.009 1.4726796 0.029 1408.006 0.003 21.003336 0.006 diff --git a/libraries/SourceData/ra226.sou b/libraries/SourceData/ra226.sou new file mode 100644 index 00000000..b446d8c7 --- /dev/null +++ b/libraries/SourceData/ra226.sou @@ -0,0 +1,27 @@ + 187.00 0.3 + 241.997 0.003 + 295.224 0.002 + 351.932 0.002 + 609.312 0.007 + 768.356 0.010 + 1120.287 0.010 + 1238.11 0.012 + 1377.669 0.012 + 1729.595 0.015 + 1764.494 0.014 + 1847.42 0.025 + 2118.55 0.03 + 2204.21 0.04 + 2293.40 0.12 + 2447.86 0.10 + 2921.90 0.20 + 2978.90 0.20 + 3053.9 0.20 + + + + + + + + diff --git a/libraries/TDetSystems/TDetector/LinkDef.h b/libraries/TDetSystems/TDetector/LinkDef.h index ee60978d..0d1bd1f7 100644 --- a/libraries/TDetSystems/TDetector/LinkDef.h +++ b/libraries/TDetSystems/TDetector/LinkDef.h @@ -8,7 +8,7 @@ #pragma link C++ nestedclasses; #pragma link C++ class TDetectorEnv+; -#pragma link C++ class TDetectorHit+; -#pragma link C++ class TDetector+; +#pragma link C++ class TDetectorHit-; +#pragma link C++ class TDetector-; #endif diff --git a/libraries/TDetSystems/TDetector/TDetector.cxx b/libraries/TDetSystems/TDetector/TDetector.cxx index 1829a13f..921f4a1e 100644 --- a/libraries/TDetSystems/TDetector/TDetector.cxx +++ b/libraries/TDetSystems/TDetector/TDetector.cxx @@ -4,6 +4,7 @@ #include #include +#include ClassImp(TDetector) @@ -77,4 +78,12 @@ int TDetector::BuildHits(std::vector &raw_data) { } +void TDetector::Streamer(TBuffer &r_b) { + if(r_b.IsReading()) { + r_b.ReadClassBuffer(TDetector::Class(),this); + } else { + r_b.WriteClassBuffer(TDetector::Class(),this); + } +} + diff --git a/libraries/TDetSystems/TDetector/TDetectorEnv.cxx b/libraries/TDetSystems/TDetector/TDetectorEnv.cxx index a3eb7a77..9f5e6006 100644 --- a/libraries/TDetSystems/TDetector/TDetectorEnv.cxx +++ b/libraries/TDetSystems/TDetector/TDetectorEnv.cxx @@ -167,6 +167,7 @@ kDetectorSystems TDetectorEnv::DetermineSystem(TRawEvent& event) const { default: break; } - + if(TGRUTOptions::Get()->UseFSU()) + source_id=0; return DetermineSystem(source_id); } diff --git a/libraries/TDetSystems/TDetector/TDetectorHit.cxx b/libraries/TDetSystems/TDetector/TDetectorHit.cxx index 443f680b..8cd183ce 100644 --- a/libraries/TDetSystems/TDetector/TDetectorHit.cxx +++ b/libraries/TDetSystems/TDetector/TDetectorHit.cxx @@ -3,8 +3,9 @@ #include #include -#include +#include "TClass.h" #include "TRandom.h" +#include "TBuffer.h" ClassImp(TDetectorHit) @@ -53,19 +54,19 @@ Int_t TDetectorHit::Charge() const { if(fFlags & kIsEnergy) { return 0; } else { - return fCharge; + return RawCharge(); } } double TDetectorHit::GetEnergy() const { if(fFlags & kIsEnergy) { - return fCharge; + return RawCharge(); } else { TChannel* chan = TChannel::GetChannel(fAddress); if(!chan){ return fCharge; } else { - return chan->CalEnergy(fCharge, fTimestamp); + return chan->CalEnergy(RawCharge(), fTimestamp); } } } @@ -105,3 +106,23 @@ const char* TDetectorHit::GetName() const { return ""; } } + +int TDetectorHit::GetNumber() const { + TChannel* chan = TChannel::GetChannel(fAddress); + if(chan){ + return chan->GetNumber(); + } else { + return -1; + } +} + + +void TDetectorHit::Streamer(TBuffer &r_b) { + if(r_b.IsReading()) { + //std::cout << "streamer\tin!" << std::endl; + r_b.ReadClassBuffer(TDetectorHit::Class(),this); + } else { + //std::cout << "streamer\tout!" << std::endl; + r_b.WriteClassBuffer(TDetectorHit::Class(),this); + } +} diff --git a/libraries/TDetSystems/TFSU/LinkDef.h b/libraries/TDetSystems/TFSU/LinkDef.h new file mode 100644 index 00000000..dec20f2d --- /dev/null +++ b/libraries/TDetSystems/TFSU/LinkDef.h @@ -0,0 +1,14 @@ +// TFSU.h TFSUHit.h + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +#pragma link C++ nestedclasses; + +#pragma link C++ class TFSUHit+; +#pragma link C++ class std::vector+; +#pragma link C++ class TFSU+; + +#endif diff --git a/libraries/TDetSystems/TFSU/TFSU.cxx b/libraries/TDetSystems/TFSU/TFSU.cxx new file mode 100644 index 00000000..deabdb12 --- /dev/null +++ b/libraries/TDetSystems/TFSU/TFSU.cxx @@ -0,0 +1,79 @@ + +#include +#include + +TFSU::TFSU() { } + +TFSU::~TFSU() { } + +void TFSU::Clear(Option_t *opt) { + TDetector::Clear(); + + fEnergy.Clear(); + fDeltaE.Clear(); + + fFSUHits.clear(); +} + +void TFSU::Print(Option_t *opt) const { + TString sopt(opt); + sopt.ToLower(); + printf("+++++++++++++\n"); + printf("TFSU @ %lu \n",Timestamp()); + printf("dE: %i\t%ld\n",fDeltaE.Charge(),fDeltaE.Timestamp()); + printf("E: %i\t%ld\n",fEnergy.Charge(),fEnergy.Timestamp()); + printf("contains %lu hits\n",fFSUHits.size()); + if(sopt.Contains("all")) { + for(unsigned int i=0;i& raw_data) { + Long_t smallesttime = 0x0ffffffffffff; + for(auto& event : raw_data){ + TNSCLEvent& nscl = (TNSCLEvent&)event; + if(nscl.GetTimestamp()GetName(),"E")) { + hit.Copy(fEnergy); + } else if(!strcmp(channel->GetName(),"dE")) { + hit.Copy(fDeltaE); + } else { + fFSUHits.push_back(hit); + } + } + //printf(RED "I built %i hits!!" RESET_COLOR "\n", fFSUHits.size()); + SetTimestamp(smallesttime); + //:w + //Print("all"); + + return fFSUHits.size(); +} + + + diff --git a/libraries/TDetSystems/TFSU/TFSUHit.cxx b/libraries/TDetSystems/TFSU/TFSUHit.cxx new file mode 100644 index 00000000..e5007315 --- /dev/null +++ b/libraries/TDetSystems/TFSU/TFSUHit.cxx @@ -0,0 +1,59 @@ + +#include +#include +#include + + +#include + +TFSUHit::TFSUHit() { } + +TFSUHit::~TFSUHit() { } + + +void TFSUHit::Clear(Option_t *opt) { + TDetectorHit::Clear(); + +} + +void TFSUHit::Print(Option_t *opt) const { + + printf("---------------------------\n"); + printf("TFSUHit @ %lu\n",Timestamp()); + printf("\tAddress: 0x%08x\n",Address()); + printf("Name: %s\n",GetName()); + printf("\tCharge: %i\n",Charge()); + printf("\tTime: %i\n",Time()); + GetPosition().Print(); + printf("---------------------------\n"); + } + + +TVector3 TFSUHit::GetPosition() const { + TChannel *chan = TChannel::GetChannel(Address()); + if(chan) + return chan->GetChannelPosition(); + return TVector3(0,0,1); +} + + +double TFSUHit::GetDoppler(const TVector3 *recoil_vector) const { + //insert some checks that positions and betas are actually set..... + double beta = GValue::Value("beta"); + double gamma = 1/(sqrt(1-pow(beta,2))); + if(recoil_vector==0) { + recoil_vector = &BeamUnitVec; + } + return GetEnergy()*gamma *(1 - beta*TMath::Cos(GetPosition().Angle(*recoil_vector))); +} + + +double TFSUHit::GetDoppler(double beta) const { + //insert some checks that positions and betas are actually set..... + double gamma = 1/(sqrt(1-pow(beta,2))); + return GetEnergy()*gamma *(1 - beta*TMath::Cos(GetPosition().Theta())); +} + + + + diff --git a/libraries/TDetSystems/TFastScint/TFastScint.cxx b/libraries/TDetSystems/TFastScint/TFastScint.cxx index 8504e175..c91c2787 100644 --- a/libraries/TDetSystems/TFastScint/TFastScint.cxx +++ b/libraries/TDetSystems/TFastScint/TFastScint.cxx @@ -2,16 +2,19 @@ #include #include +#include #include "TNSCLEvent.h" #include "TH2.h" #include "TMath.h" +#include "TStopwatch.h" + int TFastScint::errors; TFastScint::TFastScint() { //fs_hits = new TClonesArray("TFastScintHit"); - //Clear(); + Clear(); } TFastScint::~TFastScint(){ @@ -26,6 +29,7 @@ void TFastScint::Copy(TObject& obj) const { fs.fs_hits = fs_hits; fs.trig_time = trig_time; //fs.raw_data.clear(); + fs.fReferenceTime = fReferenceTime; } void TFastScint::Clear(Option_t* opt){ @@ -37,6 +41,8 @@ void TFastScint::Clear(Option_t* opt){ //fs_hits->Clear(opt); fs_hits.clear(); trig_time = -1; + fReferenceTime = -1; + } void TFastScint::Print(Option_t *opt) const { @@ -50,11 +56,16 @@ void TFastScint::Print(Option_t *opt) const { int TFastScint::BuildHits(std::vector& raw_data){ + //static TStopwatch sw; + //sw.Start(); for(auto& event : raw_data){ - TNSCLEvent& nscl = (TNSCLEvent&)event; - SetTimestamp(nscl.GetTimestamp()); - errors+=Build_From(nscl,true); + //TNSCLEvent& nscl = (TNSCLEvent&)event; + SetTimestamp(event.GetTimestamp()); + errors+=Build_From(event); } + std::sort(fs_hits.begin(),fs_hits.end()); + //std::cout << "sw.CpuTime\t" << sw.CpuTime() << std::endl; + //sw.Continue(); return (int)Size(); } @@ -64,9 +75,6 @@ void TFastScint::InsertHit(const TDetectorHit& hit){ fs_hits.push_back((TFastScintHit)hit); } -unsigned int TFastScint::Size() const { - return fs_hits.size(); //->GetEntries(); -} int TFastScint::GoodSize() const { @@ -79,9 +87,8 @@ int TFastScint::GoodSize() const { return size; // fs_hits.size(); //->GetEntries(); } -TFastScintHit TFastScint::GetLaBrHit(int i) const { - const TFastScintHit hit = fs_hits.at(i); - return hit; +const TFastScintHit& TFastScint::GetLaBrHit(int i) const { + return fs_hits.at(i); } int TFastScint::GetDetNumberIn_fs_hits(Int_t det){ @@ -94,12 +101,16 @@ int TFastScint::GetDetNumberIn_fs_hits(Int_t det){ return detNumber; } -TFastScintHit *TFastScint::FindHit(int channelnumber) { +TFastScintHit *TFastScint::FindHit(int address) { for(unsigned int i=0;iSetAddress(address); + return back; } @@ -107,18 +118,39 @@ TDetectorHit& TFastScint::GetHit(int i){ return fs_hits.at(i); } +void TFastScint::SetRefTime(int refTime){ + fReferenceTime = refTime; +} + + // This is where the unpacking happens: -int TFastScint::Build_From(TNSCLEvent &event,bool Zero_Suppress){ +int TFastScint::Build_From(TRawEvent &event){ + + //event.Print("all"); + + //printf("body: 0x%04x\n",*((unsigned short*)event.GetBody())); + //printf("payload: 0x%04x\n",*((unsigned short*)event.GetPayload())); + + + //int total_words = *((unsigned short*)event.GetPayload())/2; + //int *data = (int*)(event.GetPaylad()+2); + + + //return 0; + + + bool DEBUG = false; - Zero_Suppress = true; + //Zero_Suppress = false; bool isQ = false; bool isT = false; - + Int_t words_processed = 0; //Int_t detNumber = -1; // Payload size in 32 bit words. - Int_t PayloadSize = event.GetPayloadSize()/4.0; + //Int_t PayloadSize = event.GetPayload() /4.0; + Int_t PayloadSize = *((unsigned short*)event.GetPayload())/2; if(PayloadSize == 1) return 1; @@ -129,17 +161,10 @@ int TFastScint::Build_From(TNSCLEvent &event,bool Zero_Suppress){ // UShort_t buffer_size = *((UShort_t*)(data)); data+=2; - if(DEBUG){ - std::cout << "===========================================================================================>" << std::endl; - event.Print("all"); - std::cout << " Payload Size : " << PayloadSize << std::endl; - } - - for(Int_t i = 0; i isHeader()){ // Header const TRawEvent::Mesy_Header* Mhead = (TRawEvent::Mesy_Header*)Mword; if(Mhead->isQDC()){ @@ -148,127 +173,57 @@ int TFastScint::Build_From(TNSCLEvent &event,bool Zero_Suppress){ else if(Mhead->isTDC()){ isQ = false; isT = true; } - else std::cout << " *** Error -- Not QDC or TDC *** " << std::endl; + // else std::cout << " *** Error -- Not QDC or TDC *** " << std::endl; - }// end if is header - else if(Mword->isData()){ // Data + } else if(Mword->isData()){ // Data + + // Both qdc and tdc have channel in same spot, and I want the channel now + unsigned int address = (12<<28) + ((TRawEvent::M_QDC_Data*)(Mword))->Chan(); + TFastScintHit *hit = FindHit(address); if(isQ){ // QDC: // NOTE -> we do it this way bc QDC should always come first!!!! const TRawEvent::M_QDC_Data* Mq = (TRawEvent::M_QDC_Data*)Mword; - TFastScintHit *hit = FindHit(Mq->Chan()); - if(!hit){ - TFastScintHit qdc_hit; - qdc_hit.SetChannel(Mq->Chan()); - qdc_hit.SetTime(-1); - qdc_hit.SetAddress((12<<28) + qdc_hit.GetChannel()); - - if(Mq->isOOR()) qdc_hit.SetCharge(5000); - else qdc_hit.SetCharge(Mq->Charge()); - - //hit.SetEnergy(); - - if(Zero_Suppress){ - if(Mq->Charge()>0){ - InsertHit(qdc_hit); - } - } - else{ - InsertHit(qdc_hit); - } - } else{ - if(Mq->isOOR()) hit->SetCharge(5000); - else hit->SetCharge(Mq->Charge()); - } - - // if(DEBUG){ - // std::cout << " QDC Q : " << std::hex << Mq->Charge() << std::endl; - // std::cout << " QDC ch: " << std::dec << Mq->Chan() << std::endl; - // std::cout << " QDC Ov: " << Mq->isOOR() << std::endl; - // } - } // end if isQ - else if(isT){ // TDC + if(Mq->isOOR()) hit->SetCharge(5000); + else hit->SetCharge(Mq->Charge()); + + } else if(isT){ // TDC const TRawEvent::M_TDC_Data* Mt = (TRawEvent::M_TDC_Data*)Mword; - //detNumber = -1; - //detNumber = GetDetNumberIn_fs_hits(Int_t(Mt->Chan())); - - TFastScintHit *hit = FindHit(Mt->Chan()); - if(!hit) { - TFastScintHit tdc_hit; - tdc_hit.SetTime(Mt->Time()); - tdc_hit.SetCharge(-1); - - tdc_hit.SetChannel(Mt->Chan()); - tdc_hit.SetAddress((12<<28) + tdc_hit.GetChannel()); - - if(Zero_Suppress){ - if(Mt->Time()>0){ - InsertHit(tdc_hit); - } - } - else { - //hit->SetTime(Mt->Time()); - InsertHit(tdc_hit); - } - if(DEBUG){ - std::cout << " TDC t : " << std::hex << Mt->Time() << std::endl; - std::cout << " TDC ch: " << std::dec << Mt->Chan() << std::endl; - std::cout << " TDC Tr: " << Mt->isTrig() << std::endl; - } - } else { - TFastScintHit *qdc_hit = hit; - if(qdc_hit->GetChannel()==Mt->Chan()){ - qdc_hit->SetTime(Mt->Time()); - - - if(DEBUG){ - std::cout << " TDC ch : " << Mt->Chan() << std::endl; - std::cout << " TDC for QDC ch : " << qdc_hit->GetChannel() << std::endl; - std::cout << " TDC time : " << Mt->Time() << std::endl; - std::cout << " QDC Charge : " << qdc_hit->Charge() << std::endl; - std::cout << " Time Check : " << qdc_hit->Time() << std::endl; - } - } - else{ // should never be here. - std::cout << " *** Found a Channel but it didnt match ?? *** " << std::endl; - } - } - if(Mt->isTrig()){ + hit->SetTime(Mt->Time()); + + if(Mt->isTrig()){ SetTrigTime(Mt->Time()); continue; } - - } // end elif isT - else{ // If not QDC or TDC - - std::cout << " *** Not TDC or QDC **** " << std::endl; + const int s800_reference_channel = (12<<28) + 31; + if(hit->Address() == s800_reference_channel){ + SetRefTime(Mt->Time()); //hit->Time()); + } } - }// end elif is data - else if(Mword->isETS()){ + } else if(Mword->isETS()){ if(DEBUG) std::cout << " ETS " << std::endl; - }//end elif ets - else if(Mword->isFILL()){ - if(DEBUG) + } else if(Mword->isFILL()){ + if(DEBUG) { std::cout << " Filler " << std::endl; - else if(Mword->isEOE()){ + } else if(Mword->isEOE()) { if(DEBUG) std::cout << " EOE " << std::endl; - }// end elif eoe - } - }// end for - - if(Zero_Suppress) { - std::vector::iterator it; - for(it=fs_hits.begin();it!=fs_hits.end();) { - if( (it->Charge()<100) || (it->Time()<0) ) { - it = fs_hits.erase(it); - } else { - it++; } } } + //if(Zero_Suppress) { + // std::vector::iterator it; + // for(it=fs_hits.begin();it!=fs_hits.end();) { + // if( (it->Charge()<100) || (it->Time()<0) ) { + // it = fs_hits.erase(it); + // } else { + // it++; + // } + // } + //} + // TFastScintHit *CheckHit = FindHit(3); // std::cout << " ------- Double Check Here -----------" << std::endl; // std::cout << " Channel = " << CheckHit->GetChannel() << std::endl; @@ -276,6 +231,7 @@ int TFastScint::Build_From(TNSCLEvent &event,bool Zero_Suppress){ // std::cout << " Energy = " << CheckHit->GetEnergy() << std::endl; return 0; + } TVector3 &TFastScint::GetPosition(int detector) { diff --git a/libraries/TDetSystems/TFastScint/TFastScintHit.cxx b/libraries/TDetSystems/TFastScint/TFastScintHit.cxx index 6f1c76e6..ba653183 100644 --- a/libraries/TDetSystems/TFastScint/TFastScintHit.cxx +++ b/libraries/TDetSystems/TFastScint/TFastScintHit.cxx @@ -17,16 +17,17 @@ void TFastScintHit::Copy(TObject& obj) const { TDetectorHit::Copy(obj); TFastScintHit& hit = (TFastScintHit&)obj; + hit.fTimes = fTimes; //hit.fCharge = fCharge; - hit.fChannel = fChannel; + // hit.fChannel = fChannel; //hit.fTime = fTime; //hit.fEnergy = fEnergy; } void TFastScintHit::Clear(Option_t* opt) { TDetectorHit::Clear(opt); - - fChannel = -1; + fTimes.clear(); + // fChannel = -1; //fCharge = -1; //fTime = -1; //fEnergy = -1; @@ -34,148 +35,9 @@ void TFastScintHit::Clear(Option_t* opt) { void TFastScintHit::Print(Option_t *opt) const { printf("LaBrHit[%i]: chg[%04i] -> %.02f | time[%04i] -> %.02f \n", - fChannel,Charge(),GetEnergy(),Time(),GetTime()); + GetChannel(),Charge(),GetEnergy(),Time(),GetTime()); } -TVector3 &TFastScintHit::GetPosition() const { return TFastScint::GetPosition(fChannel); } - - -/* - -void TFastScintHit::SetEnergy(){ - double charge = fCharge; - charge+=gRandom->Uniform(); +TVector3 &TFastScintHit::GetPosition() const { return TFastScint::GetPosition(GetChannel()); } - switch(fChannel){ - case 0: - //fEnergy = 8.3684*charge - 446.29; //825 V different base - //fEnergy = 5.0476*charge - 830.9; //1000 V different base - //fEnergy = 4.0253*charge - 1012.7; //1100 V different base - //fEnergy = 3.2121*charge + 174.03; //run279 - //fEnergy = 1.0095*charge - 758.72; //run290 - //fEnergy = charge; - //fEnergy = 1.2766*charge - 902.16; //run589 - //fEnergy = 1.3208*charge - 917.47; //run618 - fEnergy = 1.2971*charge - 893.18; //run687 - break; - case 1: - //fEnergy = 2.3212*charge + 119.19; //run279 - //fEnergy = 0.626*charge + 39.343; //run290 - //fEnergy = 1.2091*charge + 48.513; //run340 - //fEnergy = charge; - //fEnergy = 0.7438*charge + 32.719; //run589 - //fEnergy = 0.7402*charge + 33.425; //run618 - fEnergy = 0.7330*charge + 39.05; //run687 - break; - case 2: - //fEnergy = 2.5645*charge + 97.185; //run279 - //fEnergy = 0.6868*charge + 20.851; //run290 - //fEnergy = 1.4521*charge + 22.973; //run340 - //fEnergy = charge; - //fEnergy = 0.8068*charge + 8.3474; //run589 - //fEnergy = 0.8225*charge + 6.7178; //run618 - fEnergy = 0.8171*charge + 12.864; //run687 - break; - case 3: - //fEnergy = 5.129*charge + 275.42; //run279 - //fEnergy = 0.7114*charge + 39.013; //run290 - //fEnergy = charge; - //fEnergy = 0.8314*charge + 22.602; //run618 - fEnergy = 0.8331*charge + 25.992; //run687 - break; - case 4: - //fEnergy = 2.8393*charge + 81.295; //run279 - //fEnergy = 0.77*charge + 5.3317; //run290 - //fEnergy = charge; - //fEnergy = 0.7995*charge - 14.056; //run589 - //fEnergy = 0.8081*charge - 14.892; //run618 - fEnergy = 0.8031*charge - 10.783; //run687 - break; - case 5: - //fEnergy = 2.3643*charge + 61.182; //run279 - //Energy = 0.6424*charge + 9.8909; //run290 - //fEnergy = charge; - //fEnergy = 0.8124*charge - 7.5045; //run589 - //fEnergy = 0.8216*charge - 7.1619; //run618 - fEnergy = 0.8195*charge - 4.4342; //run687 - break; - case 6: - //fEnergy = 3.4011*charge + 69.353; //run279 - //fEnergy = 0.9164*charge + 27.009; //run290 - //fEnergy = charge; - //fEnergy = 0.8037*charge - 8.9718; //run589 - //fEnergy = 0.8006*charge - 8.4897; //run618 - fEnergy = 0.7908*charge - 6.0767; //run687 - break; - case 7: - //fEnergy = 3.3474*charge + 96.821; //run279 - //fEnergy = 0.8933*charge + 15.337; //run290 - //fEnergy = charge; - //fEnergy = 0.7595*charge - 8.7219; //run618 - fEnergy = 0.7549*charge - 4.2764; //run687 - break; - case 8: - //fEnergy = charge; - //fEnergy = 0.7709*charge - 20.417; //run589 - //fEnergy = 0.7773*charge - 20.66; //run618 - fEnergy = 0.7748*charge - 17.672; //run687 - break; - case 9: - //fEnergy = charge; - fEnergy = 0.7771*charge + 9.7792; //run687 - break; - case 10: - //fEnergy = charge; - fEnergy = 0.7748*charge + 3.8723; //run687 - break; - case 11: - //fEnergy = charge; - fEnergy = 0.7686*charge - 3.7752; //run687 - break; - case 12: - fEnergy = charge; - //fEnergy = 0.7512*charge - 1.151; //run589 - break; - case 13: - //fEnergy = charge; - //fEnergy = 0.8331*charge + 5.9087; //run589 - fEnergy = 0.7619*charge - 29.451; //run687 - break; - case 14: - //fEnergy = charge; - fEnergy = 0.7457*charge - 12.069; //run687 - break; - case 15: - //fEnergy = charge; - fEnergy = 0.8118*charge - 5.1587; //run687 - break; - case -10: - fEnergy = -1; - break; - } - - //Old Calibration Settings - //switch(fChannel){ - //case 3: - //fEnergy = 3.5333*charge + 176.6; - //break; - //case 5: - //fEnergy = 3.4565*charge + 56.543; - //break; - //case 11: - //fEnergy = 4.9688*charge + 174.28; - //break; - //case 13: - //fEnergy = 1.8068*charge + 78.068; - //break; - //case -10: - //fEnergy = -1; - //break; - //} - - if(fCharge<0){ - fEnergy = -1; - } -} -*/ diff --git a/libraries/TDetSystems/TGretina/LinkDef.h b/libraries/TDetSystems/TGretina/LinkDef.h index 9bb0b242..18e3d207 100644 --- a/libraries/TDetSystems/TGretina/LinkDef.h +++ b/libraries/TDetSystems/TGretina/LinkDef.h @@ -1,4 +1,4 @@ -// TGretina.h TGretinaHit.h TMode3.h TMode3Hit.h TBank29.h +// TGretina.h TGretinaHit.h TMode3.h TMode3Hit.h TBank88.h #ifdef __CINT__ @@ -7,12 +7,20 @@ #pragma link off all functions; #pragma link C++ nestedclasses; +//#pragma link C++ class interaction_point+; +#pragma link C++ class TInteractionPoint+; +#pragma link C++ class std::vector+; + #pragma link C++ class TGretinaHit+; #pragma link C++ class std::vector+; #pragma link C++ class TGretina+; #pragma link C++ class TMode3Hit+; #pragma link C++ class std::vector+; #pragma link C++ class TMode3+; -#pragma link C++ class TBank29+; +#pragma link C++ class TBank88+; + +#pragma link C++ class TCluster+; +#pragma link C++ class TClusterPoint+; +#pragma link C++ class std::vector+; #endif diff --git a/libraries/TDetSystems/TGretina/TBank29.cxx b/libraries/TDetSystems/TGretina/TBank29.cxx deleted file mode 100644 index f2bc1dee..00000000 --- a/libraries/TDetSystems/TGretina/TBank29.cxx +++ /dev/null @@ -1,46 +0,0 @@ -#include "TBank29.h" - -#include "TGEBEvent.h" -#include "TGRUTOptions.h" - -ClassImp(TBank29) - -TBank29::TBank29(){ -} - -TBank29::~TBank29() { -} - -void TBank29::Copy(TObject& obj) const { - TDetector::Copy(obj); - - TBank29& bank = (TBank29&)obj; - bank.channels = channels; -} - -void TBank29::InsertHit(const TDetectorHit& hit){ - channels.emplace_back((TMode3Hit&)hit); - fSize++; -} - -int TBank29::BuildHits(std::vector& raw_data){ - for(auto& event : raw_data){ - TGEBEvent* geb = (TGEBEvent*)&event; - SetTimestamp(geb->GetTimestamp()); - TMode3Hit hit; - TSmartBuffer buf = geb->GetPayloadBuffer(); - hit.BuildFrom(buf); - InsertHit(hit); - } - if(Size()) { - SetTimestamp(channels.at(0).GetLed()); - } - return Size(); -} - -void TBank29::Print(Option_t *opt) const { } - -void TBank29::Clear(Option_t *opt) { - TDetector::Clear(opt); - channels.clear(); -} diff --git a/libraries/TDetSystems/TGretina/TBank88.cxx b/libraries/TDetSystems/TGretina/TBank88.cxx new file mode 100644 index 00000000..825873a3 --- /dev/null +++ b/libraries/TDetSystems/TGretina/TBank88.cxx @@ -0,0 +1,69 @@ +#include "TBank88.h" + +#include "TGEBEvent.h" +#include "TGRUTOptions.h" + +ClassImp(TBank88) + +TBank88::TBank88(){ +} + +TBank88::~TBank88() { +} + +void TBank88::Copy(TObject& obj) const { + TDetector::Copy(obj); + + TBank88& bank = (TBank88&)obj; + bank.channels = channels; +} + +void TBank88::InsertHit(const TDetectorHit& hit){ + channels.emplace_back((TMode3Hit&)hit); + fSize++; +} + +int TBank88::BuildHits(std::vector& raw_data){ + for(auto& event : raw_data){ + //event.Print("all"); + TGEBEvent* geb = (TGEBEvent*)&event; + SetTimestamp(event.GetTimestamp()); // geb->GetTimestamp()); + TMode3Hit hit; + TSmartBuffer buf = geb->GetPayloadBuffer(); + hit.BuildFrom(buf); + //hit.SetTimestamp(event.GetTimestamp()); //the ts is now set from the hit led in the build + InsertHit(hit); + //std::cout << "----------------------\n"; + //std::cout <<"event " << event.GetTimestamp() <<"\t"<< hit.Timestamp()<<"\tdt: "<< event.GetTimestamp() -hit.Timestamp() << std::endl; + //std::cout <<"gevent " << geb->GetTimestamp() <<"\t"<< hit.Timestamp()<<"\tdt: "<< geb->GetTimestamp() -hit.Timestamp() << std::endl; + //std::cout <<"bank " < +#include + +#include "TCluster.h" + +TClusterPoint::TClusterPoint() { } + +TClusterPoint::~TClusterPoint() { } + +TClusterPoint::TClusterPoint(TGretinaHit &hit, TInteractionPoint &ip) { + this->Copy(ip); + fXtalId = hit.GetCrystalId(); + fXtalAddress = hit.Address(); + fTimestamp = hit.Timestamp(); + fT0 = hit.GetT0(); + fPad = hit.GetPad(); +} + +void TClusterPoint::Print(Option_t *opt) const { + opt=opt; //quiet the warnings. + printf("xtal[%03i] %5.1f / %5.1f seg[%02i]:[ %3.1f, %3.1f, %3.1f ] \n", + GetXtal(), GetAssignE(), GetPreampE(), GetSegNum(), + GetPosition().Mag(),GetPosition().Theta()*TMath::RadToDeg(), + GetPosition().Phi()*TMath::RadToDeg()); +} + +void TClusterPoint::Combine(const TClusterPoint &other) { + if(other.GetEnergy()>GetEnergy()) { + //fXtalId = other.GetXtal(); + //SetSegNum(other.GetSegNum()); + fTimestamp = other.GetTimestamp(); + fT0 = other.fT0; + } + SetAssignE(GetAssignE()+other.GetAssignE()); + if(fPad xtal; +// for(unsigned int x=0;x::iterator it1; + std::vector::iterator it2; + for(it1=fClusterPoints.begin();it1!=fClusterPoints.end();it1++) { + for(it2=it1+1;it2!=fClusterPoints.end();) { + if(*it1 == *it2) { //checks the 2 ints are the same Xtal && same Seg + it1->Combine(*it2); + it2 = fClusterPoints.erase(it2); + } else { + it2++; + } + } + } +} + + +void TCluster::CompressInteractions(std::vector *pts) { + std::vector::iterator it1; + std::vector::iterator it2; + for(it1=pts->begin();it1!=pts->end();it1++) { + for(it2=it1+1;it2!=pts->end();) { + if(*it1 == *it2) { //checks the 2 ints are the same Xtal && same Seg + it1->Combine(*it2); + it2 = pts->erase(it2); + } else { + it2++; + } + } + } +} + + +void TCluster::WedgeInteractions(std::vector *pts) { + std::vector::iterator it1; + std::vector::iterator it2; + for(it1=pts->begin();it1!=pts->end();it1++) { + for(it2=it1+1;it2!=pts->end();) { + //if(*it1 == *it2) { //checks the 2 ints are the same Xtal && same Seg + if((it1->GetXtal() == it2->GetXtal() ) && + (it1->Wedge() == it2->Wedge())) { + it1->Combine(*it2); + it2 = pts->erase(it2); + } else { + it2++; + } + } + } +} + +/* +void TCluster::XtalInteractions(std::vector *pts) { + std::vector::iterator it1; + std::vector::iterator it2; + for(it1=pts->begin();it1!=pts->end();it1++) { + for(it2=it1+1;it2!=pts->end();) { + //if(*it1 == *it2) { //checks the 2 ints are the same Xtal && same Seg + if((it1->GetXtal() == it2->GetXtal() ) { + //(it1->Wedge() == it2->Wedge())) { + it1->Combine(*it2); + it2 = pts->erase(it2); + } else { + it2++; + } + } + } +} +*/ + + + + +void TCluster::Fit() { + std::vector xpts; + std::vector ypts; + std::vector::const_iterator it; + for(it=fClusterPoints.begin();it!=fClusterPoints.end();it++) { + xpts.push_back(it->GetThetaDeg()); + ypts.push_back(it->GetPhiDeg()); + } + TGraph gr(xpts.size(),&(xpts[0]),&(ypts[0])); + TFitResultPtr fr = gr.Fit("pol1","QNS"); + + fFOM = fr->Chi2(); + fKN = fr->Parameter(1); + + //printf("KN set to %.4f \n",GetKN()); + +} + + + + + + + + + + + + + + diff --git a/libraries/TDetSystems/TGretina/TGretina.cxx b/libraries/TDetSystems/TGretina/TGretina.cxx index 60001e08..ebd7056e 100644 --- a/libraries/TDetSystems/TGretina/TGretina.cxx +++ b/libraries/TDetSystems/TGretina/TGretina.cxx @@ -4,14 +4,13 @@ #include #include "TGretina.h" -#include "GRootCommands.h" +//#include "GRootCommands.h" +#include "GRootFunctions.h" +#include "Globals.h" #include #include -#include "GH1D.h" -#include "GH2I.h" -#include "TGRUTOptions.h" -#include "GCanvas.h" +#include "math.h" #include "TGEBEvent.h" @@ -30,51 +29,13 @@ Float_t TGretina::crmat[32][4][4][4]; Float_t TGretina::m_segpos[2][36][3]; bool TGretina::fCRMATSet = false; +/* bool DefaultAddback(const TGretinaHit& one,const TGretinaHit &two) { - TVector3 res = one.GetLastPosition()-two.GetPosition(); + TVector3 res = one.GetPosition()-two.GetPosition(); //one.GetLastPosition()-two.GetPosition(); return ((std::abs(one.GetTime()-two.GetTime()) < 44.0) && - (res.Mag() < 80.0) ) ; -} - -std::function TGretina::fAddbackCondition = DefaultAddback; - -void TGretina::BuildAddback(int EngRange) const { - if( addback_hits.size() > 0 || - gretina_hits.size() == 0) { - return; - } - - addback_hits = gretina_hits; - - if(EngRange>=0 && EngRange<4){ - for(auto& hit : addback_hits) { - hit.SetCoreEnergy(hit.GetCoreEnergy(EngRange)); - } - } - - - std::sort(addback_hits.begin(), addback_hits.end(), - [](const TGretinaHit& a, const TGretinaHit& b) { - return a.GetCoreEnergy() > b.GetCoreEnergy(); - }); - - for(unsigned int i=0; i to_erase; - for(unsigned int j=i+1; j& raw_data){ //printf("%s\n",__PRETTY_FUNCTION__); for(auto& event : raw_data){ @@ -229,6 +194,7 @@ int TGretina::BuildHits(std::vector& raw_data){ return Size(); } + TVector3 TGretina::CrystalToGlobal(int cryId,Float_t x,Float_t y,Float_t z) { SetCRMAT(); @@ -238,58 +204,25 @@ TVector3 TGretina::CrystalToGlobal(int cryId,Float_t x,Float_t y,Float_t z) { /* x,y,z need to be in cm to work properly. Depending on the source of the mapping, you might need to convert from mm (if you read from crmat.linux). */ + double xl = ( (crmat[detectorPosition][crystalNumber][0][0] * x) + - (crmat[detectorPosition][crystalNumber][0][1] * y) + - (crmat[detectorPosition][crystalNumber][0][2] * z) + - (crmat[detectorPosition][crystalNumber][0][3]) ); + (crmat[detectorPosition][crystalNumber][0][1] * y) + + (crmat[detectorPosition][crystalNumber][0][2] * z) + + (crmat[detectorPosition][crystalNumber][0][3]) ); double yl = ( (crmat[detectorPosition][crystalNumber][1][0] * x) + - (crmat[detectorPosition][crystalNumber][1][1] * y) + - (crmat[detectorPosition][crystalNumber][1][2] * z) + - (crmat[detectorPosition][crystalNumber][1][3]) ); + (crmat[detectorPosition][crystalNumber][1][1] * y) + + (crmat[detectorPosition][crystalNumber][1][2] * z) + + (crmat[detectorPosition][crystalNumber][1][3]) ); double zl = ( (crmat[detectorPosition][crystalNumber][2][0] * x) + - (crmat[detectorPosition][crystalNumber][2][1] * y) + - (crmat[detectorPosition][crystalNumber][2][2] * z) + - (crmat[detectorPosition][crystalNumber][2][3]) ); + (crmat[detectorPosition][crystalNumber][2][1] * y) + + (crmat[detectorPosition][crystalNumber][2][2] * z) + + (crmat[detectorPosition][crystalNumber][2][3]) ); return TVector3(xl, yl, zl); } -/* -void TGretina::BuildAddbackHits(){ - if(Size()==0) - return; - - addback_hits->Clear(); - TGretinaHit *newhit = (TGretinaHit*)addback_hits->ConstructedAt(0); - GetHit(0).Copy(*newhit); - - if(Size()==1) - return; - - std::vector max_energies; - max_energies.push_back(newhit->GetCoreEnergy()); - - for(int x=1;xGetEntries();y++) { - if(GetAddbackHit(y).CheckAddback(GetGretinaHit(x))) { - used = true; - GetAddbackHit(y).AddToSelf(GetGretinaHit(x), max_energies[y]); - break; - } - } - - if(!used) { - TGretinaHit *tmphit = (TGretinaHit*)addback_hits->ConstructedAt(addback_hits->GetEntries()); - GetGretinaHit(x).Copy(*tmphit); - max_energies.push_back(newhit->GetCoreEnergy()); - } - } -} -*/ void TGretina::Print(Option_t *opt) const { printf(BLUE "GRETINA: size = %i" RESET_COLOR "\n",Size()); @@ -301,6 +234,50 @@ void TGretina::Print(Option_t *opt) const { printf(BLUE "--------------------------------" RESET_COLOR "\n"); } + +void TGretina::PrintInteractions(Option_t *opt) const { + opt=opt; + /* + int ndet = Size(); + double sum=0.0; + std::vector vecs; + + for(int x=0;xGetBranch("TGretina")) - return; - if(!gPad || !gPad->IsEditable()){ - gROOT->MakeDefCanvas(); - }else{ - gPad->GetCanvas()->Clear(); - } - std::string name = Form("%s_Gammas",Class()->GetName()); - std::string title = Form("%s Gamma 1-D",Class()->GetName()); - GH1D *h = (GH1D*)gROOT->FindObject(name.c_str()); - if(!h) - h = new GH1D(name.c_str(),title.c_str(),4000,0,8000); +//double TGretina::ComptonAngle(double eoriginal,double escatterer) { +// return 0; +//} - chain->Project(name.c_str(),Form("gretina_hits.GetDoppler(%f)",Beta),gate,opt,nentries); - h->GetXaxis()->SetTitle("Energy [keV]"); - h->GetYaxis()->SetTitle("Counts / 2 keV"); - h->Draw(opt); +//double TGretina::ComptonEnergy(double eoriginal,double theta) { +// double temp = 1 + (eoriginal/511.)*(1-TMath::Cos(theta*TMath::DegToRad())); +// return eoriginal *(1/temp); +//} -} -void TGretina::DrawDopplerBeta(Option_t *gate,Option_t *opt,Long_t nentries,TChain *chain){ - TString OptString = opt; - if(!chain) - chain = gChain; - if(!chain || !chain->GetBranch("TGretina")) - return; - if(!gPad || !gPad->IsEditable()){ - gROOT->MakeDefCanvas(); - }else{ - gPad->GetCanvas()->Clear(); +int TGretina::BuildClusters() const { + // so, you wanna build a cluster. + // 1) lets collect get ALL the interaction points... + std::vector cluster_points; + for(unsigned int i=0;iGetName()); - std::string title = Form("Gretina Doppler Beta"); - GH2I *h = (GH2I*)gROOT->FindObject(name.c_str()); - if(!h) - h = new GH2I(name.c_str(),title.c_str(),2000,0,4000,101,0.2,0.5); - double beta = 0.2; - for(int i = 0; i < 100; i++){ - chain->Project(name.c_str(),Form("gretina_hits.GetDoppler(%f):%f",beta,beta),gate,opt,nentries); + //sort the cluster_points? energy, theta, phi, id ? i dunno. + //for(unsigned int x=0;xAdd(cluster_points.at(0)); + cluster_points.erase(cluster_points.begin()); + std::vector::iterator p_it; + std::vector::iterator c_it; + + // 2.a) while we do this, lets find the largest energy and set the clusters time. + double max_energy; + double max_energy_time; + for(p_it=cluster_points.begin();p_it!=cluster_points.end();p_it++) { + bool used=false; + for(c_it=clusters.begin();c_it!=clusters.end();c_it++) { + //printf("ANGLE: %.2f \n",c_it->GetPosition().Angle(p_it->GetPosition())*TMath::RadToDeg()); + if( c_it->GetPosition().Angle(p_it->GetPosition()) < CLUSTER_ANGLE && + fabs(c_it->GetTime()-p_it->GetTime()) < CLUSTER_BUILD_TIME ) { + //true ) { + c_it->Add(*p_it); + used=true; + break; + } + } + if(!used) { + clusters.push_back(TCluster()); + clusters.back().Add(*p_it); + } + //p_it = cluster_points.erase(p_it); + // printf("\n"); } - h->GetXaxis()->SetTitle("Energy [keV]"); - h->GetYaxis()->SetTitle("BETA"); - h->Draw(opt); - std::cout << " I DONT WORK YET!!!" << std::endl; + return clusters.size(); } -void TGretina::DrawEnVsTheta(Double_t Beta,Option_t *gate,Option_t *opt,Long_t nentries,TChain *chain){ - TString OptString = opt; - if(!chain) - chain = gChain; - if(!chain || !chain->GetBranch("TGretina")) - return; - if(!gPad || !gPad->IsEditable()){ - gROOT->MakeDefCanvas(); - }else{ - gPad->GetCanvas()->Clear(); + //3 ok, now - ideally - we would "track" the clusters. + // -- can we order the interactions? + // -- do the interactions reproduce a FEP? +/* + for(int z=0;zSetFOM(2.0); + cluster->SetKN(-2.0); + for(int x=0;xSize();x++) { + for(int y=0;ySize();y++) { + if(x==y) continue; + TVector3 v1 = cluster->GetPoint(x).GetPosition(); + TVector3 v2 = cluster->GetPoint(y).GetPosition(); + double scattered_energy = cluster->GetEnergy() - cluster->GetPoint(x).GetEnergy(); + double total_energy = cluster->GetEnergy(); + double scattered_angle = v1.Angle(v2-v1) * TMath::RadToDeg(); // 1 - (2-1) + + double calculated_angle = GRootFunctions::ComptonAngle(&scattered_energy,&total_energy); // i am in degrees! + double calculated_energy = GRootFunctions::ComptonEnergy(&scattered_angle,&total_energy); // i am in degrees! + + //double fom = fabs(scattered_angle-calculated_angle)/ + double e_ratio = scattered_energy/calculated_energy; + double a_ratio = scattered_angle/calculated_angle; + double fom = (e_ratio+a_ratio)/2.; + + //double kn = GRootFunctions::KN_unpol_theta(&scattered_angle,&total_energy); + double kn = GRootFunctions::KN_unpol_theta(&calculated_angle,&total_energy); + + TF1 f("f",GRootFunctions::KN_unpol_theta_norm,0,180,2); + f.SetParameter(0,total_energy); //initial gamma energy + f.SetParameter(1,1.0); //scaling factor. + double integral = f.Integral(0,180); + f.SetParameter(1,1/integral); + + double angleErr = 5.; //deg + double sigma = 5.; + + //double kn1 = f.Integral(0,scattered_angle); + //double kn2 = 1- kn1; //f.Integral(0,scattered_angle); + //double kn3 = f.Eval(scattered_angle); + //double kn4 = f.Integral(calculated_angle-angleErr,calculated_angle+angleErr); + //double kn5 =0.; + //double kn6 =0.; + double kn7=0.; + double kn8=0.; + double kn0=0.; + double kn9=0.; + double angDif = fabs(scattered_angle-calculated_angle); + double kn11 = f.Integral(calculated_angle-angDif,calculated_angle+angDif); + double kn12 = f.Eval(scattered_angle)/f.Eval(calculated_angle); + double kn13 = log(kn12); + if(calculated_angle180) + angHigh=180.; + + + kn7 = f.Integral(angLow,angHigh); //with "Dirk" fom actually want this close to zero for good events so removing 1- + + + kn=kn13; + + double radAngleSc = scattered_angle*3.14159/180.; + double radAngleCl = calculated_angle*3.14159/180.; + + //fom = (scattered_angle-calculated_angle)/2.; + + fom = ( cos(radAngleSc)-cos(radAngleCl) )/2.; + //fom += ( scattered_energy - calculated_energy)/2; + // fom+=1-e_ratio; + + //fom = pow(kn,1)*fom; + + //if(fabs(1-fom) < fabs(1-cluster->GetFOM())) { cluster->SetFOM(fom); cluster->SetKN(kn); cluster->SetTheta(scattered_angle); } + if(fabs(fom) < fabs(cluster->GetFOM())) { cluster->SetFOM(fom); cluster->SetKN(kn); cluster->SetTheta(scattered_angle); } + //if(fabs(kn) < fabs(cluster->GetKN())) { cluster->SetFOM(fom); cluster->SetKN(kn); cluster->SetTheta(scattered_angle); } + //if(fabs(fom-kn) < fabs(cluster->GetFOM()-cluster->GetKN())) { cluster->SetFOM(fom); cluster->SetKN(kn); cluster->SetTheta(scattered_angle); } + //if(kn>cluster->GetKN()) { cluster->SetFOM(fom); cluster->SetKN(kn); } + + //if(kn>cluster->GetKN()) { cluster->SetKN(kn); } + + + //printf("[%i][%i] angle %3.1f / %3.1f = %2.4f \t energy %4.1f / %4.1f = %4.4f fom: %2.4f\n",x,y, + // scattered_angle,calculated_angle,scattered_angle/calculated_angle, + // scattered_energy,calculated_energy,scattered_energy/calculated_energy,fom); + } + } } - std::string name = Form("%s_En_vs_Theta",Class()->GetName()); - std::string title = Form("Gretina Energy vs Theta"); - GH2I *h = (GH2I*)gROOT->FindObject(name.c_str()); - if(!h) - h = new GH2I(name.c_str(),title.c_str(),4000,0,4000,314,0,3.14); + //printf("best fom for the cluster is %2.4f\n",fom_best); +*/ +// return clusters.size(); +//} + - chain->Project(name.c_str(),Form("gretina_hits.GetTheta():gretina_hits.GetDoppler(%f)",Beta),gate,opt,nentries); - h->GetXaxis()->SetTitle("Theta [radians]"); - h->GetYaxis()->SetTitle("Energy [keV]"); - h->Draw(opt); + +void TGretina::PrintClusters(Option_t *opt) const { + printf("------TGretina :: %i hits -> %i clusters ---------\n",(int)Size(),(int)clusters.size()); + for(unsigned int x=0;xGetBranch("TGretina")) - return; - if(!gPad || !gPad->IsEditable()){ - gROOT->MakeDefCanvas(); - }else{ - gPad->GetCanvas()->Clear(); + +void TGretina::CleanHits() { + std::vector::iterator it; + for(it=gretina_hits.begin();it!=gretina_hits.end();) { + if(it->GetPad()>0) + it = gretina_hits.erase(it); + else + it++; } - std::string name = Form("%s_Core_Summary",Class()->GetName()); - std::string title = Form("Gretina Core Summary"); - GH2I *h = (GH2I*)gROOT->FindObject(name.c_str()); - if(!h) - h = new GH2I(name.c_str(),title.c_str(),60,20,80,4000,0,4000); +} - chain->Project(name.c_str(),"gretina_hits.GetCoreEnergy():gretina_hits.GetCrystalId()",gate,opt,nentries); - h->GetXaxis()->SetTitle("Crystal ID"); - h->GetYaxis()->SetTitle("Energy [arb]"); - h->Draw(opt); +double TGretina::GetTotalEnergy() const { + std::vector::const_iterator it; + double sum=0.0; + for(it=gretina_hits.begin();it!=gretina_hits.end();it++) + sum += it->GetCoreEnergy(); + return sum; } + + + + diff --git a/libraries/TDetSystems/TGretina/TGretinaHit.cxx b/libraries/TDetSystems/TGretina/TGretinaHit.cxx index b31a4b5f..a34f47d0 100644 --- a/libraries/TDetSystems/TGretina/TGretinaHit.cxx +++ b/libraries/TDetSystems/TGretina/TGretinaHit.cxx @@ -9,30 +9,74 @@ #include "GValue.h" #include "TGEBEvent.h" #include "TGretina.h" -#include "TS800.h" +//#include "TS800.h" +/* struct interaction_point { - interaction_point(int segnum, TVector3 pos,TVector3 loc,float energy,float fraction=100.0) - : segnum(segnum), pos(pos),local_pos(loc), energy(energy), energy_fraction(fraction) { } + interaction_point(int segnum, TVector3 pos,TVector3 loc,float energy,float fraction,float assigned) + : segnum(segnum), pos(pos),local_pos(loc), energy(energy), energy_fraction(fraction), energy_assigned(assigned) { } int segnum; TVector3 pos; TVector3 local_pos; float energy; float energy_fraction; + float energy_assigned; bool operator<(const interaction_point& other) const { - if (energy != other.energy) { - return energy > other.energy; + if (energy_assigned != other.energy_assigned) { + return energy_assigned > other.energy_assigned; } - if(segnum == other.segnum) { - return energy_fraction > other.energy_fraction; - } + //if(segnum == other.segnum) { + // return energy_fraction > other.energy_fraction; + //} return segnum < other.segnum; } }; +*/ + +TInteractionPoint::TInteractionPoint(const TInteractionPoint &IP) { + this->Copy(IP); +} + +void TInteractionPoint::Copy(const TInteractionPoint &IP) { + fSegNum = IP.GetSegNum(); + fEng = IP.GetPreampE(); + fDecompEng = IP.GetDecompE(); + fAssignedEng = IP.GetAssignE(); + fOrder = IP.GetOrder(); + fLPosition = IP.GetLocalPosition(); +} + +TVector3 TInteractionPoint::GetPosition(int xtal) const { return TGretina::CrystalToGlobal(xtal, + fLPosition.X(), + fLPosition.Y(), + fLPosition.Z()); } + + +void TInteractionPoint::Print(Option_t *opt) const { + TVector3 lv = GetLocalPosition(); + printf("seg[%02i] wedge[%i] %.1f / %.1f [ %.1f, %.1f. %.1f] \n", + GetSegNum(),Wedge(),GetAssignE(),GetPreampE(),lv.X(),lv.Y(),lv.Z()); +} + + +void TInteractionPoint::Clear(Option_t *opt) { + fSegNum = -1; + fEng = sqrt(-1); + fDecompEng = sqrt(-1); + fAssignedEng = sqrt(-1);; + fOrder = -1; + fLPosition.SetXYZ(0,0,1); +} + + + + + + TGretinaHit::TGretinaHit(){ Clear(); } @@ -40,8 +84,8 @@ TGretinaHit::~TGretinaHit(){ } void TGretinaHit::Copy(TObject &rhs) const { TDetectorHit::Copy(rhs); - ((TGretinaHit&)rhs).fTimeStamp = fTimeStamp; - ((TGretinaHit&)rhs).fWalkCorrection = fWalkCorrection; + //((TGretinaHit&)rhs).fTimeStamp = fTimeStamp; + ((TGretinaHit&)rhs).fT0 = fT0; ((TGretinaHit&)rhs).fAddress = fAddress; ((TGretinaHit&)rhs).fPad = fPad; ((TGretinaHit&)rhs).fCrystalId = fCrystalId; @@ -50,6 +94,10 @@ void TGretinaHit::Copy(TObject &rhs) const { ((TGretinaHit&)rhs).fCoreCharge[1] = fCoreCharge[1]; ((TGretinaHit&)rhs).fCoreCharge[2] = fCoreCharge[2]; ((TGretinaHit&)rhs).fCoreCharge[3] = fCoreCharge[3]; + + ((TGretinaHit&)rhs).fNumberOfInteractions = fNumberOfInteractions; + ((TGretinaHit&)rhs).fInteractions = fInteractions; + /* ((TGretinaHit&)rhs).fFirstInteraction = fFirstInteraction; ((TGretinaHit&)rhs).fSecondInteraction = fSecondInteraction; ((TGretinaHit&)rhs).fNumberOfInteractions = fNumberOfInteractions; @@ -58,6 +106,7 @@ void TGretinaHit::Copy(TObject &rhs) const { ((TGretinaHit&)rhs).fLocalInteractionPosition = fLocalInteractionPosition; ((TGretinaHit&)rhs).fInteractionEnergy = fInteractionEnergy; ((TGretinaHit&)rhs).fInteractionFraction = fInteractionFraction; + */ } Float_t TGretinaHit::GetCoreEnergy(int i) const { @@ -70,21 +119,21 @@ Float_t TGretinaHit::GetCoreEnergy(int i) const { return channel->CalEnergy(charge); } -const char *TGretinaHit::GetName() const { - std::string name = ""; - TChannel *channel = TChannel::GetChannel(GetAddress()); - if(!channel) - return name.c_str(); - return channel->GetName(); -} +//const char *TGretinaHit::GetName() const { +// std::string name = ""; +// TChannel *channel = TChannel::GetChannel(GetAddress()); +// if(!channel) +// return name.c_str(); +// return channel->GetName(); +//} -TVector3 TGretinaHit::GetCrystalPosition() const { return TGretina::GetCrystalPosition(fCrystalId); } -TVector3 TGretinaHit::GetSegmentPosition() const { if(fSegmentNumber.size()) - return TGretina::GetSegmentPosition(fCrystalId,fSegmentNumber.at(0)); - else - return TGretina::GetSegmentPosition(fCrystalId,0); - } +//TVector3 TGretinaHit::GetCrystalPosition() const { return TGretina::GetCrystalPosition(fCrystalId); } +//TVector3 TGretinaHit::GetSegmentPosition() const { if(fSegmentNumber.size()) +// return TGretina::GetSegmentPosition(fCrystalId,fSegmentNumber.at(0)); +// else +// return TGretina::GetSegmentPosition(fCrystalId,0); +//} @@ -95,24 +144,26 @@ void TGretinaHit::BuildFrom(TSmartBuffer& buf){ //SetAddress(kDetectorSystems::GRETINA, 1, raw.crystal_id); // HOLE CRYSTAL SEGMENT //SetAddress(kDetectorSystems::GRETINA, 1, raw.crystal_id); - //std::cout << "-------------------------------------------------" << std::endl; //std::cout << raw << std::endl; Clear(); - - fTimeStamp = raw.timestamp; - fWalkCorrection = raw.t0; + + SetTimestamp(raw.timestamp); + fT0 = raw.t0; fCrystalId = raw.crystal_id; - fCoreEnergy = raw.tot_e; - //fAddress = (1<<24) + (fCrystalId<<16); - //fAddress = (1<<24) + ( raw.board_id ); int board_id = ((fCrystalId/4) << 8) ; //hole number : 0x1f00 -// board_id = ; //card number : 0x0030 information not available here. - board_id += ((fCrystalId%4) << 6) ; //x-tal number : 0x00c0 - board_id += 9; //chan number : 0x000f information not available here(assume core). + // board_id = ; //card number : 0x0030 information not available here. + board_id += ((fCrystalId%4) << 6) ; //x-tal number : 0x00c0 + board_id += 9; //chan number : 0x000f information not available here(assume core). fAddress = (1<<24) + board_id; + TChannel *ch = TChannel::GetChannel(fAddress); + if(!ch) + fCoreEnergy = raw.tot_e; + else + fCoreEnergy = ch->CalEnergy(raw.tot_e); + for(int i=0; i<4; i++){ fCoreCharge[i] = raw.core_e[i]; @@ -121,58 +172,99 @@ void TGretinaHit::BuildFrom(TSmartBuffer& buf){ fNumberOfInteractions = raw.num; fPad = raw.pad; - float first_interaction_value = sqrt(-1); - float second_interaction_value = sqrt(-1); + //float first_interaction_value = fFirstInteraction;//sqrt(-1); + //float second_interaction_value = sqrt(-1); + int order_counter=0; + float decomp_sum =0.0; for(int i=0; i= first_interaction_value){ - second_interaction_value = first_interaction_value; - first_interaction_value = seg_ener; - fSecondInteraction = fFirstInteraction; - fFirstInteraction = i; - } else if(seg_ener > second_interaction_value){ - fSecondInteraction = i; - second_interaction_value = seg_ener; + int seg = raw.intpts[i].seg; + float eng = raw.intpts[i].seg_ener; + float frac = raw.intpts[i].e; + + TVector3 lpos = TVector3(raw.intpts[i].x,raw.intpts[i].y,raw.intpts[i].z); + + TInteractionPoint intpt(seg,eng,frac,lpos); + + intpt.SetOrder(order_counter++); + decomp_sum += intpt.GetDecompE(); + fInteractions.push_back(intpt); + } + //now that the interactions are set, assign energy fractions based of of core - + for(int i=0;i0.0) { + fInteractions[i].SetAssignE((fInteractions[i].GetDecompE()/decomp_sum)*GetCoreEnergy()); + } else { // go home antiphoton, you're drunk. + fInteractions[i].SetAssignE(0.00); } } - // fFirstInteraction=0; - SortHits(); - // Print("all"); - + + SortInts(); } -TVector3 TGretinaHit::GetInteractionPosition(int i) const { - if(i>=0 && iother.GetDecompE()) { + SetAssignE(GetAssignE()+other.GetAssignE()); } else { - return TVector3(0,0,1); + double eng = GetAssignE(); + Copy(other); + SetAssignE(GetAssignE()+eng); } } -TVector3 TGretinaHit::GetLocalPosition(int i) const { - if(i>=0 && i=0 && i0){ + //double xoffset = GValue::Value("GRETINA_X_OFFSET"); + //if(std::isnan(xoffset)) + // xoffset=0.00; + //double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + //if(std::isnan(yoffset)) + // yoffset=0.00; + //double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + //if(std::isnan(zoffset)) + // zoffset=0.00; + //TVector3 offset(xoffset,yoffset,zoffset); + return GetInteractionPoint(0).GetPosition(GetCrystalId());// + offset; } else { - return TVector3(0,0,1); + return TDetectorHit::BeamUnitVec; } } +//TVector3 TGretinaHit::GetLocalPosition(int i) const { +// if(i>=0 && iGetDta(); - beta *=(1.+dp_p/(gamma*gamma)); + +int TGretinaHit::CleanInteractions() { + std::map int_map; + std::vector::iterator it; + for(it=fInteractions.begin();it!=fInteractions.end();it++) { + if(int_map.count(it->GetSegNum())>0) { + int_map[it->GetSegNum()].Add(*it); + } else { + int_map[it->GetSegNum()]=*it; + } } - TVector3 track = s800->Track(gata,gbta); //(TMath::Sin(s800->GetAta()),-TMath::Sin(s800->GetBta()),1); - if(EngRange>-1) - return GetDoppler(EngRange,beta,&track); - return GetDoppler(beta,&track); + fInteractions.clear(); + std::map::iterator it2; + for(it2=int_map.begin();it2!=int_map.end();it2++) { + fInteractions.push_back(it2->second); + } + return fInteractions.size(); } +TVector3 TGretinaHit::GetCrystalPosition() const { return TGretina::GetCrystalPosition(fCrystalId); } + + //TVector3 TGretinaHit::GetCrystalPosition(int i) const { // std::cerr << __PRETTY_FUNCTION__ << " NOT IMPLEMENTED YET" << std::endl; //} - +/* void TGretinaHit::SortHits(){ // sets are sorted, so this will sort all properties together. // @@ -227,14 +314,14 @@ void TGretinaHit::SortHits(){ // segment, the first interaction is currenlty assigned // to that segment! // - std::vector ips; for(int i=0; i= MAXHPGESEGMENTS){ break; @@ -267,6 +354,71 @@ void TGretinaHit::SortHits(){ if(fNumberOfInteractions>1) fSecondInteraction = 1; } +*/ + +void TGretinaHit::SortInts(){ + std::sort(fInteractions.begin(),fInteractions.end()); + // sets are sorted, so this will sort all properties together. + // + // !! When multiple interactions are assigned to a single + // segment, the first interaction is currenlty assigned + // to that segment! + // + /* + std::vector ips; + for(int i=0; i= MAXHPGESEGMENTS){ + break; + } + fSegmentNumber.push_back(point.segnum); + fGlobalInteractionPosition.push_back(point.pos); + fLocalInteractionPosition.push_back(point.local_pos); + fInteractionEnergy.push_back(point.energy); + fInteractionFraction.push_back(point.energy_fraction); + fNumberOfInteractions++; + } + + //Print("all"); + // Because they are now sorted + fFirstInteraction = 0; + if(fNumberOfInteractions>1) + fSecondInteraction = 1; + */ +} + + + + + + + + + + + +/* // TODO: Handle interactions points better // Right now, the "first interaction point" is the one with the highest energy, @@ -278,15 +430,15 @@ void TGretinaHit::AddToSelf(const TGretinaHit& rhs) { std::set ips; for(int i=0; i-1){ @@ -372,28 +525,6 @@ TVector3 TGretinaHit::GetFirstIntPosition() const { return TDetectorHit::BeamUnitVec; } -TVector3 TGretinaHit::GetFirstIntPosition_2() const { - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - - if(GetFirstIntPoint()>-1){ - TVector3 IntPos = GetInteractionPosition(GetFirstIntPoint()); - IntPos.SetX(IntPos.X()-xoffset); - IntPos.SetY(IntPos.Y()-yoffset); - IntPos.SetZ(IntPos.Z()-zoffset); - - return IntPos; - } - return TDetectorHit::BeamUnitVec; -} - TVector3 TGretinaHit::GetLastPosition() const { double xoffset = GValue::Value("GRETINA_X_OFFSET"); if(std::isnan(xoffset)) @@ -404,15 +535,16 @@ TVector3 TGretinaHit::GetLastPosition() const { double zoffset = GValue::Value("GRETINA_Z_OFFSET"); if(std::isnan(zoffset)) zoffset=0.00; - + TVector3 offset(xoffset,yoffset,zoffset); if(fNumberOfInteractions>0) - return GetInteractionPosition(fNumberOfInteractions-1) + offset; - return TDetectorHit::BeamUnitVec; - -} + return GetInteractionPosition(fNumberOfInteractions-1) + offset; + return TDetectorHit::BeamUnitVec; +} +*/ +/* TVector3 TGretinaHit::GetSecondIntPosition() const { double xoffset = GValue::Value("GRETINA_X_OFFSET"); if(std::isnan(xoffset)) @@ -428,6 +560,7 @@ TVector3 TGretinaHit::GetSecondIntPosition() const { return GetInteractionPosition(GetSecondIntPoint())+offset; return TDetectorHit::BeamUnitVec; } +*/ void TGretinaHit::Print(Option_t *opt) const { @@ -438,8 +571,8 @@ void TGretinaHit::Print(Option_t *opt) const { std::cout << "\tCrystalNum \t" << GetCrystalNumber() << std::endl; std::cout << "\tCrystalId: \t" << GetCrystalId() << std::endl; - std::cout << "\tLocal Timestamp:\t" << fTimeStamp << std::endl; - std::cout << "\tCorrected time: \t" << fTimeStamp - fWalkCorrection << std::endl; + std::cout << "\tLocal Timestamp:\t" << Timestamp() << std::endl; + std::cout << "\tCorrected time: \t" << Timestamp() - fT0 << std::endl; std::cout << "\tDecomp Energy: \t" << fCoreEnergy << std::endl; if(!strcmp(opt,"all")) { for(int i=0;i<4;i++) @@ -447,15 +580,20 @@ void TGretinaHit::Print(Option_t *opt) const { } std::cout << "\tErrorCode: \t" << fPad << std::endl; std::cout << "\tInteractions: \t" << fNumberOfInteractions << std::endl; - std::cout << "\tFirst Int: \t" << fFirstInteraction << std::endl; - std::cout << "\tSecond Int: \t" << fSecondInteraction << std::endl; + //std::cout << "\tFirst Int: \t" << fFirstInteraction << std::endl; + //std::cout << "\tSecond Int: \t" << fSecondInteraction << std::endl; if(!strcmp(opt,"all")) { - for(int i=0;i::const_iterator it; + for(it=fInteractions.begin();it!=fInteractions.end();it++) { + it->Print(); + + //for(int i=0;iGetCoreEnergy()>other->GetCoreEnergy()) + return -1; + else if(this->GetCoreEnergy()GetCoreEnergy()) + return 1; //sort largest to smallest. + return 0; } +/* +Float_t TGretinaHit::GetInteractionPercentage(int i) const { + //this function 'normalizes' the decomp output, + //finds the percentage of the total_energy from the core assigne to the interaction + //multiples this percentage byt the CC energy. + float sum=0.0; + for(int x=0;x& raw_data){ + if(raw_data.size()<1) + return Size(); + long smallest_time = 0x3fffffffffffffff; for(auto& event : raw_data){ - SetTimestamp(event.GetTimestamp()); + if(event.GetTimestamp()Clear(opt);//("TMode3Hit"); } + +void TMode3::Draw(Option_t *opt) const { + if(!Size()) + return; + TString option = opt; + if(!gPad || option.Contains("new",TString::kIgnoreCase)) { + new GCanvas; + } else { + gPad->Clear(); + } + int total_bins =0; + std::vector segdata; + std::vector coredata; + for(size_t i=0;iExtractWaves(); auto header = (TRawEvent::GEBMode3Head*)buf.GetData(); @@ -32,12 +34,22 @@ void TMode3Hit::BuildFrom(TSmartBuffer& buf){ buf.Advance(sizeof(TRawEvent::GEBMode3Data)); led = data->GetLed(); - //charge = data->GetEnergy(*header); - SetCharge(data->GetEnergy(*header)); + int charge = data->GetEnergy(*header); + //SetCharge(data->GetEnergy(*header)); + if(charge<0) { charge*=-1; } // we should prob remove this... pcb + SetCharge(charge); + + + //std::cout << "Board ID:" << board_id << " and still sorting!" << std::endl ; + + //std::cout << "LED:" << led << std::endl ; dt1 = data->GetDeltaT1(); dt2 = data->GetDeltaT2(); + //std::cout << "DT1:" << dt1 << std::endl ; + //std::cout << "DT2:" << dt2 << std::endl ; + charge0 = data->GetEnergy0(*header); charge1 = data->GetEnergy1(*header); charge2 = data->GetEnergy2(*header); @@ -45,8 +57,15 @@ void TMode3Hit::BuildFrom(TSmartBuffer& buf){ cfd = data->GetCfd(); size_t wave_bytes = header->GetLength()*4 - sizeof(*header) + 4 - sizeof(*data); + //std::cout << "wave_bytes: " << wave_bytes << std::endl; + //std::cout << "timestamp: " << led << std::endl; + //std::cout << "timestamp: " << std::hex << led << std::dec << std::endl; + SetTimestamp(led); + if(read_waveform){ size_t wavesize = wave_bytes/sizeof(short); + + //std::cout << "wave size: " << wavesize << std::endl; waveform.resize(wavesize); memcpy((char*)&waveform[0], buf.GetData(), wave_bytes); @@ -57,7 +76,11 @@ void TMode3Hit::BuildFrom(TSmartBuffer& buf){ waveform[i] = tmp; } } + //std::cout << "Charge: " << Charge() << std::endl; + //std::cout << "Charge0: " << GetCharge0() << std::endl; + //Print("all"); buf.Advance(wave_bytes); + //exit(0); } @@ -69,7 +92,6 @@ void TMode3Hit::Copy(TObject& obj) const { TMode3Hit& mode3 = (TMode3Hit&)obj; - mode3.board_id = board_id; mode3.led = led; mode3.cfd = cfd; @@ -77,7 +99,20 @@ void TMode3Hit::Copy(TObject& obj) const { } -void TMode3Hit::Print(Option_t *opt) const { } +void TMode3Hit::Print(Option_t *opt) const { + TString sopt(opt); + if(sopt.Contains("long")) { + printf("TMode3Hit @ %lu \n",Timestamp()); + printf("\tHole: %i\n",GetHole()); + printf("\tXtal: %i\n",GetCrystal()); + printf("\tSegment: %i\n",GetSegmentId()); + printf("\tCharge: %i\n",Charge()); + printf("\tPickoff: %i\n",GetCharge0()); + printf("\tWaveSize: %i\t%i\n",wavesize,(int)waveform.size()); + } else { + printf("hole[%03i] xtal[%i] seg[%03i]: %i\n",GetHole(),GetCrystal(),GetSegmentId(),GetCharge0()); + } +} void TMode3Hit::Clear(Option_t *opt) { TDetectorHit::Clear(opt); @@ -93,7 +128,7 @@ void TMode3Hit::Clear(Option_t *opt) { waveform.clear(); } -double TMode3Hit::AverageWave(int samples) { +double TMode3Hit::AverageWave(int samples) const { if(waveform.size() == 0) { return 0.0; } @@ -102,16 +137,16 @@ double TMode3Hit::AverageWave(int samples) { samples = waveform.size(); } double sum = 0.0; - double wsum = 0.0; for(int i=0;iClear(); } - GH1D wave("wave","wave",(int)waveform.size(),0,(double)waveform.size()); + //double avg = AverageWave(10); + + GH1D wave("wave",Form("0x%08x",Address()),(int)waveform.size(),0,(double)waveform.size()); for(unsigned int x=0;x 50 && hit.Time() < 3900 && // hit.Charge() > max_charge){ - if(hit.Charge() > max_charge && + if(hit.GetEnergy() > max_energy && hit.GetDetnum() >= 0 && hit.GetDetnum() < 2){ best_front = elem.first; - max_charge = hit.Charge(); + max_energy = hit.Charge(); } } // Find all backs with a reasonable TDC value int best_back = -1; - max_charge = -1; + max_energy = -1e9; for(auto& elem : back_hits){ TJanusHit& hit = elem.second; // if(hit.Time() > 50 && hit.Time() < 3900 && // hit.Charge() > max_charge) { - if(hit.Charge() > max_charge && + if(hit.GetEnergy() > max_energy && hit.GetDetnum() >= 0 && hit.GetDetnum() < 2){ best_back = elem.first; - max_charge = hit.Charge(); + max_energy = hit.Charge(); } } diff --git a/libraries/TDetSystems/TLenda/LinkDef.h b/libraries/TDetSystems/TLenda/LinkDef.h new file mode 100644 index 00000000..cc54f52e --- /dev/null +++ b/libraries/TDetSystems/TLenda/LinkDef.h @@ -0,0 +1,14 @@ +// TLenda.h TLendaHit.h + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +#pragma link C++ nestedclasses; + +#pragma link C++ class TLendaHit+; +#pragma link C++ class std::vector+; +#pragma link C++ class TLenda+; + +#endif diff --git a/libraries/TDetSystems/TLenda/TLenda.cxx b/libraries/TDetSystems/TLenda/TLenda.cxx new file mode 100644 index 00000000..ce4bd50a --- /dev/null +++ b/libraries/TDetSystems/TLenda/TLenda.cxx @@ -0,0 +1,46 @@ + +#include + +#include +#include +#include + +ClassImp(TLenda) + + +int TLenda::BuildHits(std::vector& raw_data) { + for(auto& event : raw_data){ + SetTimestamp(event.GetTimestamp()); + + TSmartBuffer buf = event.GetPayloadBuffer(); + + int total_size = *(int*)buf.GetData(); + const char* buffer_end = buf.GetData() + total_size; + buf.Advance(sizeof(int)); + //int ptr = sizeof(int); + + while(buf.GetData() < buffer_end) { + TLendaHit hit; + + // Constructor advances the buffer to end of each channel + TDDASEvent ddas(buf); + + unsigned int address = 0x12341234; + + hit.SetAddress(address); + hit.SetCharge(ddas.GetEnergy()); + hit.SetTime(ddas.GetCFDTime()); + hit.SetTimestamp(ddas.GetTimestamp()); + + //InsertHit(hit); + lenda_hits.push_back(hit); + } + + + } + fSize = lenda_hits.size(); + + //printf("lenda build hits called\t%u\t%u\n",lenda_hits.size(),Size()); + //fflush(stdout); + return fSize; +} diff --git a/libraries/TDetSystems/TLenda/TLendaHit.cxx b/libraries/TDetSystems/TLenda/TLendaHit.cxx new file mode 100644 index 00000000..fda57c51 --- /dev/null +++ b/libraries/TDetSystems/TLenda/TLendaHit.cxx @@ -0,0 +1,21 @@ + +#include + +ClassImp(TLendaHit) + + +void TLendaHit::SetTrace(unsigned int trace_length, const unsigned short* trace) { + fTrace.reserve(trace_length); + copy(trace,trace+trace_length,back_inserter(fTrace)); + //printf("%s called\t%i\n",__PRETTY_FUNCTION__,Size()); fflush(stdout); +} + + +void TLendaHit::Clear(Option_t *opt) { + TDetectorHit::Clear(opt); + fTrace.clear(); +} + + + + diff --git a/libraries/TDetSystems/TNSCLScalers/TNSCLScalers.cxx b/libraries/TDetSystems/TNSCLScalers/TNSCLScalers.cxx index 259ffa9f..43f039c2 100644 --- a/libraries/TDetSystems/TNSCLScalers/TNSCLScalers.cxx +++ b/libraries/TDetSystems/TNSCLScalers/TNSCLScalers.cxx @@ -4,6 +4,7 @@ #include #include "TNSCLEvent.h" +#include "TGRUTOptions.h" TNSCLScalers::TNSCLScalers() { Clear(); @@ -55,6 +56,7 @@ void TNSCLScalers::Clear(Option_t *opt) { } int TNSCLScalers::BuildHits(std::vector& raw_data) { + if(TGRUTOptions::Get()->UseFSU()) return 0; for(auto& event : raw_data){ SetTimestamp(event.GetTimestamp()); source_id = ((TNSCLEvent&)event).GetSourceID(); diff --git a/libraries/TDetSystems/TOBJ/LinkDef.h b/libraries/TDetSystems/TOBJ/LinkDef.h new file mode 100644 index 00000000..b025f670 --- /dev/null +++ b/libraries/TDetSystems/TOBJ/LinkDef.h @@ -0,0 +1,14 @@ +// TOBJ.h TOBJHit.h + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +#pragma link C++ nestedclasses; + +#pragma link C++ class TOBJHit+; +#pragma link C++ class std::vector+; +#pragma link C++ class TOBJ+; + +#endif diff --git a/libraries/TDetSystems/TOBJ/TOBJ.cxx b/libraries/TDetSystems/TOBJ/TOBJ.cxx new file mode 100644 index 00000000..caaa845b --- /dev/null +++ b/libraries/TDetSystems/TOBJ/TOBJ.cxx @@ -0,0 +1,113 @@ + +#include + +#include + +#include +#include +#include + +ClassImp(TOBJ) + + +int TOBJ::BuildHits(std::vector& raw_data) { + for(auto& event : raw_data){ + SetTimestamp(event.GetTimestamp()); + TSmartBuffer buf = event.GetPayloadBuffer(); + int total_size = *(int*)buf.GetData(); + const char* buffer_end = buf.GetData() + total_size; + // uncomment below two lines if we are getting data from gebpush + //buf.Advance(sizeof(int)); + //buf.Advance(sizeof(short)); // i am now even more confused. extra 0x0000 after first ncsl ts + //buf.Advance(sizeof(int)); // i dont know why this is??? 2019-Pt run pcb. + //int ptr = sizeof(int); + while(buf.GetData() < buffer_end) { + // Constructor advances the buffer to end of each channel + //TDDASEvent ddas(buf); + TDDASEvent ddas(buf); + //std::cout << ddas.GetTimestamp() << " ddas.GetAddress(): " << ddas.GetAddress() << std::endl; + + ///////////////// + ///////////////// + ///////////////// + TOBJHit hit; + hit.SetAddress(ddas.GetAddress()); + hit.SetCharge(ddas.GetEnergy()); + hit.SetTime(ddas.GetCFDTime()); + hit.SetTimestamp(ddas.GetTimestamp()); + hit.SetTrace(ddas.GetTraceLength(),ddas.trace); + hit.SetPileup(ddas.GetFinishCode()); +// hit.TrigFilter(0.192,0.192); +// hit.EnergyFilter(0.192,0.048,0.050); +// if(ddas.energy_sum!=NULL) std::cout<<"energy_sum: "<energy_sum[0]< veto high gain + break; + case 12: //xtal q6p4 + break; + case 13: // + break; + case 14: // + break; + case 15: // low hertz pulser + break; + }; + + + } else if(ddas_card==3) { //sssd detector + } + + + } + } + fSize = obj_hits.size(); + return fSize; +} diff --git a/libraries/TDetSystems/TOBJ/TOBJHit.cxx b/libraries/TDetSystems/TOBJ/TOBJHit.cxx new file mode 100644 index 00000000..446dbe4a --- /dev/null +++ b/libraries/TDetSystems/TOBJ/TOBJHit.cxx @@ -0,0 +1,192 @@ + +#include +#include + +ClassImp(TOBJHit) + + +void TOBJHit::SetTrace(unsigned int trace_length, const unsigned short* trace) { + fTrace.reserve(trace_length); + copy(trace,trace+trace_length,back_inserter(fTrace)); + //printf("%s called\t%i\n",__PRETTY_FUNCTION__,Size()); fflush(stdout); +} + + +// modified according to XIA pixie-16 algorithm +void TOBJHit::TrigFilter(Double_t tpeak,Double_t tgap){ + if(fTrace.size()<=0) return; + Double_t *data = new Double_t[fTrace.size()]; + Double_t FastFilterRange = 0; + int Module_ADCMSPS = 250; // 250MHz ADC + Double_t FL = (unsigned int) std::round(tpeak * (double) (Module_ADCMSPS/2)/std::pow(2.0,FastFilterRange)); + Double_t FG = (unsigned int) std::round(tgap * (double) (Module_ADCMSPS/2)/std::pow(2.0,FastFilterRange)); + int FastLen = FL * (unsigned int)std::pow(2.0,(double)FastFilterRange); + int FastGap = FG * (unsigned int)std::pow(2.0,(double)FastFilterRange); + size_t Size = fTrace.size(); + + int offset = 2*FastLen + FastGap - 1; + for(size_t x = offset; x < Size; x++){ + double fsum0 = 0; + for( size_t y = (x-offset); y < (x-offset+FastLen) && y < Size; y++){ + fsum0 += fTrace.at(y); + } + double fsum1 = 0; + for(size_t y = (x-offset+FastLen+FastGap); y < (x-offset + 2*FastLen+FastGap) && y < Size; y++){ + fsum1 += fTrace.at(y); + } + data[x] = (fsum1 - fsum0) / (double)FastLen; + } + for( size_t x = 0; x < (size_t)offset; x++) + data[x] = data[offset]; + fTTrace.reserve(Size); + copy(data,data+Size,back_inserter(fTTrace)); + + delete [] data; +} + +void TOBJHit::EnergyFilter(Double_t tpeak,Double_t tgap,Double_t tau){ + if(fTrace.size() <=0) return; + + size_t Size = fTrace.size(); + Double_t *data = new Double_t[Size]; + int SlowFilterRange = 1; + double Module_ADCMSPS = 250; + int SL = (int) std::round(tpeak * (double)(Module_ADCMSPS / 2) / std::pow(2.0, (double)SlowFilterRange)); + int SG = (int) std::round(tgap * (double)(Module_ADCMSPS / 2) / std::pow(2.0, (double)SlowFilterRange)); + int SlowLen = SL * (unsigned int) std::pow(2.0,(double) SlowFilterRange); + int SlowGap = SG * (unsigned int) std::pow(2.0,(double) SlowFilterRange); + + PeakSample = SL+SG-3; + + if(Size<(size_t)((2*SlowLen+SlowGap)*2)) { + std::cout<<"The length of recoreded trace is too short!"<GetNbinsX()!=len){ + htrace->Delete(); + htrace = new GH1D("trace","",len,0,len); + } + for(int i = 0; iSetBinContent(i+1,fTrace.at(i)); + } + if(!gPad){ + TCanvas *c = new TCanvas(); + } + gPad->cd(); + htrace->Draw(option); +} + +void TOBJHit::DrawTTrace(Option_t *option){ + if(fTTrace.size() <= 0) return; + int len = fTTrace.size(); + if(ttrace == nullptr) + ttrace = new GH1D("ttrace","",len,0,len); + else if(ttrace->GetNbinsX()!=len){ + ttrace->Delete(); + ttrace = new GH1D("ttrace","",len,0,len); + } + for(int i = 0; iSetBinContent(i+1,fTTrace.at(i)); + } + if(!gPad){ + TCanvas *c = new TCanvas(); + } + gPad->cd(); + ttrace->Draw(option); +} + +void TOBJHit::DrawETrace(Option_t *option){ + if(fETrace.size() <= 0) return; + int len = fETrace.size(); + if(etrace == nullptr) + etrace = new GH1D("etrace","",len,0,len); + else if(etrace->GetNbinsX()!=len){ + etrace->Delete(); + etrace = new GH1D("etrace","",len,0,len); + } + for(int i = 0; iSetBinContent(i+1,fETrace.at(i)); + } + if(!gPad){ + TCanvas *c = new TCanvas(); + } + gPad->cd(); + etrace->Draw(option); +} + +void TOBJHit::CalOfflineEnergy(double thres){ + if(fTTrace.size() == 0 || fETrace.size() == 0) { + fEnergy = -1; + return; + } + + size_t x = 0; + for(x = 0; x=thres) + break; + if(x!=fTTrace.size()-1){ + x = x+PeakSample*(unsigned int)std::pow(2.0,1);//1 slowfilter range + fEnergy = fETrace.at(x); + } + else + fEnergy = -1; +} diff --git a/libraries/TDetSystems/TPhosWall/TPhosWall.cxx b/libraries/TDetSystems/TPhosWall/TPhosWall.cxx index 7b831ad7..44f24496 100644 --- a/libraries/TDetSystems/TPhosWall/TPhosWall.cxx +++ b/libraries/TDetSystems/TPhosWall/TPhosWall.cxx @@ -5,7 +5,7 @@ #include "TH2.h" #include "TCutG.h" -#include "GCanvas.h" +//#include "GCanvas.h" #include "TMath.h" #include "TStyle.h" #include "TPaveStats.h" @@ -268,6 +268,7 @@ TVector3 TPhosWall::GetWallPosition(int pixelnumber, double delta){ // +/* void TPhosWall::Draw(Option_t *opt) { TH2I hitpat[4]; //std::string exef; @@ -313,7 +314,8 @@ void TPhosWall::Draw(Option_t *opt) { gPad->Update(); return; } - +*/ +/* void TPhosWall::DrawPID(Option_t *gate,Option_t *opt,Long_t nentries,TChain *chain) { if(!chain) chain = gChain; @@ -336,6 +338,7 @@ void TPhosWall::DrawPID(Option_t *gate,Option_t *opt,Long_t nentries,TChain *cha //TCanvas *C1 = new TCanvas("C1"); //chain->Draw("phoswall_hits.C():phoswall_hits.B()","","colz",10000); } +*/ TVector3 TPhosWall::GetKinVector(Double_t E_ejec,Double_t E_beam,const char *beam,const char *recoil, const char *ejec) { TNucleus nbeam(beam); diff --git a/libraries/TDetSystems/TS800/TS800.cxx b/libraries/TDetSystems/TS800/TS800.cxx index 35dbf5b9..a63157f4 100644 --- a/libraries/TDetSystems/TS800/TS800.cxx +++ b/libraries/TDetSystems/TS800/TS800.cxx @@ -224,7 +224,8 @@ void TS800::Clear(Option_t* opt){ int TS800::BuildHits(std::vector& raw_data){ if(raw_data.size() != 1){ - std::cout << "Data buffers: " << raw_data.size() << std::endl; + std::cout << "Trying to combine multiple (" << raw_data.size() <<"s800 buffers: " << std::endl; + return 0; } for(auto& event : raw_data) { // should only be one.. SetTimestamp(event.GetTimestamp()); @@ -278,6 +279,7 @@ int TS800::BuildHits(std::vector& raw_data){ case 0x5890: // Obj Scint break; case 0x58a0: // Obj Pin Packet + HandleOBJPinPacket(dptr+1,sizeleft); break; case 0x58b0: // S800 Hodoscope break; @@ -285,6 +287,8 @@ int TS800::BuildHits(std::vector& raw_data){ break; case 0x58d0: // Galotte break; + case 0x5805: // Pin detector for Hiro + break; case 0x58e0: break; case 0x58f0: @@ -301,6 +305,103 @@ int TS800::BuildHits(std::vector& raw_data){ return 1; } +int TS800::BuildHits(UShort_t eventsize,UShort_t *dptr,Long64_t timestamp) { //std::vector& raw_data){ + SetTimestamp(timestamp); + //int ptr = 0; + //const TRawEvent::GEBS800Header *head = ((const TRawEvent::GEBS800Header*)event.GetPayload()); + //ptr += sizeof(TRawEvent::GEBS800Header); + + //Here, we are now pointing at the size of the next S800 thing. Inclusive in shorts. + //std::string toprint = "all"; + + unsigned short *data = dptr+2; //unsigned short*)(event.GetPayload()+ptr); + size_t x = 0; + //printf(" new s800 event\n"); fflush(stdout); + while(xtotal_size-sizeof(TRawEvent::GEBS800Header)+16)) { //total size is inclusive. + int size = *(data+x); + unsigned short *dptr = (data+x+1); + //toprint.append(Form("0x%04x",*dptr)); + x+=size; + if(x>eventsize) { + //std::cout << "x is oor." << std::endl; + return -1; + } + if(size==0) { + std::cout << "size is zero." << std::endl;\ + return -1; + // geb->Print(toprint.c_str()); + // printf("head size = %i\n",sizeof(head)); + // exit(0); + } + int sizeleft = size-2; + //ptr += (*((unsigned short*)(geb->GetPayload()+ptr))*2); + //printf(" x [0x%04x] at %i\n",*dptr,x); fflush(stdout); + switch(*dptr) { + case 0x5801: //S800 TriggerPacket. + HandleTrigPacket(dptr+1,sizeleft); + break; + case 0x5802: // S800 TOF. + //event.Print("all0x5802"); + HandleTOFPacket(dptr+1,sizeleft); + break; + case 0x5810: // S800 Scint + //event.Print("all0x5810"); + HandleScintPacket(dptr+1,sizeleft); + break; + case 0x5820: // S800 Ion Chamber + //event.Print("all0x5820"); + HandleIonCPacket(dptr+1,sizeleft); + break; + case 0x5840: // CRDC Packet + //event.Print("all0x58400x5845"); + HandleCRDCPacket(dptr+1,sizeleft); + break; + case 0x5850: // II CRDC Packet + break; + case 0x5860: // TA Pin Packet + break; + case 0x5870: // II Track Packet + + break; + case 0x5880: // II PPAC + break; + case 0x5890: // Obj Scint + break; + case 0x58a0: // Obj Pin Packet + HandleOBJPinPacket(dptr+1,sizeleft); + break; + case 0x58b0: // S800 Hodoscope + break; + case 0x58c0: // VME ADC + break; + case 0x58d0: // Galotte + break; + case 0x5805: // Pin detector for Hiro + break; + case 0x58e0: + break; + case 0x58f0: + HandleMTDCPacket(dptr+1,sizeleft); + break; + + default: + //fprintf(stderr,"unknown data S800 type: 0x%04x @ x = %i \n",*dptr,x); + return 0; + }; + } + //SetEventCounter(head->GetEventNumber()); + //geb->Print(toprint.c_str()); + + return 1; +} + + + + + + + + bool TS800::HandleTrigPacket(unsigned short *data,int size) { if(size<1){ static int i=0; @@ -461,6 +562,16 @@ bool TS800::HandleCRDCPacket(unsigned short *data,int size) { return true; } +bool TS800::HandleOBJPinPacket(unsigned short* data, int size){ + if(size == 0) { + pine = 0; + }else{ + pine = *data; + pine = (pine&0x0fff); + } + return true; +} + bool TS800::HandleScintPacket(unsigned short* data, int size){ for(int x = 0; x-1) + return GetTof().GetTacXFP() + c1 * GetAFP() + c2 * GetCrdc(0).GetDispersiveX(); + return sqrt(-1); + +} + float TS800::GetTofE1_TDC(float c1,float c2) const { /*----------------*\ @@ -710,6 +837,10 @@ float TS800::GetTofE1_TDC(float c1,float c2) const { float TS800::GetTofE1_MTDC(float c1,float c2,int i) const { + if(!std::isnan(GValue::Value("TARGET_MTOF_OBJE1"))){ + return mtof.GetCorrelatedObjE1() + c1*GetAFP()+c2*GetCrdc(0).GetDispersiveX(); + } +/* std::vector result; // TODO: This check is always false. Commented it out, but was there some reason for it? // if(mtof.fObj.size()<0) @@ -717,30 +848,69 @@ float TS800::GetTofE1_MTDC(float c1,float c2,int i) const { for(unsigned int x=0;x result; + // TODO: This check is always false. Commented it out, but was there some reason for it? + // if(mtof.fObj.size()<0) + // std::cout << " In GetTOF MTDC, Size = " << mtof.fObj.size() << std::endl; + //for(unsigned int x=0;x=x*y) return sqrt(-1); + + int index_x = i/y; + int index_y = i%y; + + return mtof.fXfp.at(index_x)-mtof.fE1Up.at(index_y)+c1*GetAFP()+c2*GetCrdc(0).GetDispersiveX(); +} + +float TS800::GetTofE1_MTDC_RF(float c1,float c2,int i) const { - if(result.size()>(unsigned int)i) - return result.at(i); - return sqrt(-1.0); + if(!std::isnan(GValue::Value("TARGET_MTOF_RfE1"))){ + + return mtof.GetCorrelatedRfE1() + c1 *GetAFP()+c2*GetCrdc(0).GetDispersiveX(); + + } + //std::vector result; + // TODO: This check is always false. Commented it out, but was there some reason for it? + // if(mtof.fObj.size()<0) + // std::cout << " In GetTOF MTDC, Size = " << mtof.fObj.size() << std::endl; + //for(unsigned int x=0;x=x*y) return sqrt(-1.0); + int index_x = i/y; + int index_y = i%y; + return mtof.fRf.at(index_x) - mtof.fE1Up.at(index_y) + c1 * GetAFP() + c2 * GetCrdc(0).GetDispersiveX(); } float TS800::GetOBJRaw_TAC() const { @@ -752,6 +922,7 @@ float TS800::GetOBJ_E1Raw() const { } float TS800::GetOBJ_E1Raw_MESY(int i) const { + /* std::vector result; for(unsigned int x=0;x(unsigned int)i) return result.at(i); return sqrt(-1.0); + */ + + int x = mtof.fObj.size(); + int y = mtof.fE1Up.size(); + + if(i<0 || i>=x*y ) return sqrt(-1); + + int index_x = i/y; + int index_y = i%y; + + return mtof.fObj.at(index_x)-mtof.fE1Up.at(index_y); } float TS800::GetOBJ_E1Raw_MESY_Ch15(int i) const { + /* std::vector result; for(unsigned int x=0;x(unsigned int)i) return result.at(i); return sqrt(-1.0); + */ + int x = mtof.fObj.size(); + int y = mtof.fRef.size(); + + if(i<0 || i>=x*y) return sqrt(-1); + + int index_x = i/y; + int index_y = i%y; + + return mtof.fObj.at(index_x)-mtof.fRef.at(index_y); } float TS800::GetRawOBJ_MESY(unsigned int i) const { @@ -832,37 +1025,25 @@ float TS800::GetXF_E1Raw_MESY_Ch15(int i) const { return sqrt(-1.0); } -float TS800::MCorrelatedOBJ() const{ - if(mtof.fCorrelatedOBJ>-1) return mtof.fObj.at(mtof.fCorrelatedOBJ); - else return 0; -} - -float TS800::MCorrelatedXFP() const{ - if(mtof.fCorrelatedXFP>-1) return mtof.fXfp.at(mtof.fCorrelatedXFP); - else return 0; -} -float TS800::MCorrelatedE1() const{ - if(mtof.fCorrelatedE1>-1) return mtof.fE1Up.at(mtof.fCorrelatedE1); - else return 0; -} +/* float TS800::MCorrelatedOBJ_E1(bool corrected) const{ if(!(mtof.fE1Up.size()==1)) { mtof.fCorrelatedOBJ = -1; - mtof.fCorrelatedE1 = -1; + mtof.fCorrelatedE1Up = -1; } - else if(mtof.fCorrelatedOBJ>-1 && mtof.fCorrelatedE1>-1){ + else if(mtof.fCorrelatedOBJ>-1 && mtof.fCorrelatedE1Up>-1){ double afp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); double xfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); if(corrected==false){ afp_cor = 0; xfp_cor = 0; } - return (mtof.fObj.at(mtof.fCorrelatedOBJ)-mtof.fE1Up.at(mtof.fCorrelatedE1) + + return (mtof.fObj.at(mtof.fCorrelatedOBJ)-mtof.fE1Up.at(mtof.fCorrelatedE1Up) + afp_cor * GetAFP() + xfp_cor * GetCrdc(0).GetDispersiveX()); } - else if(mtof.fCorrelatedE1>-1){ + else if(mtof.fCorrelatedE1Up>-1){ double OBJLow = GValue::Value("MOBJ_CORR_LOW"); double OBJHigh = GValue::Value("MOBJ_CORR_HIGH"); @@ -881,7 +1062,7 @@ float TS800::MCorrelatedOBJ_E1(bool corrected) const{ std::vector val2; float val; for(unsigned int y=0;yOBJLow){ val2.push_back(val); mtof.fCorrelatedOBJ=y; @@ -916,7 +1097,7 @@ float TS800::MCorrelatedOBJ_E1(bool corrected) const{ if(valOBJLow){ val2.push_back(val); mtof.fCorrelatedOBJ=y; - mtof.fCorrelatedE1=x; + mtof.fCorrelatedE1Up=x; } } } @@ -924,18 +1105,20 @@ float TS800::MCorrelatedOBJ_E1(bool corrected) const{ if(val2.size()==1) return val2.at(0); mtof.fCorrelatedOBJ =-1; - mtof.fCorrelatedE1 =-1; + mtof.fCorrelatedE1Up =-1; } return 0; } +*/ +/* float TS800::MCorrelatedXFP_E1(bool corrected) const{ if(!(mtof.fE1Up.size()==1)) { mtof.fCorrelatedXFP = -1; - mtof.fCorrelatedE1 = -1; + mtof.fCorrelatedE1Up = -1; } - else if(mtof.fCorrelatedXFP>-1 && mtof.fCorrelatedE1>-1) { + else if(mtof.fCorrelatedXFP>-1 && mtof.fCorrelatedE1Up>-1) { double afp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); double xfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); if(corrected==false){ @@ -943,9 +1126,9 @@ float TS800::MCorrelatedXFP_E1(bool corrected) const{ xfp_cor = 0; } - return (mtof.fXfp.at(mtof.fCorrelatedXFP)-mtof.fE1Up.at(mtof.fCorrelatedE1) + afp_cor * GetAFP() + xfp_cor * GetCrdc(0).GetDispersiveX()); + return (mtof.fXfp.at(mtof.fCorrelatedXFP)-mtof.fE1Up.at(mtof.fCorrelatedE1Up) + afp_cor * GetAFP() + xfp_cor * GetCrdc(0).GetDispersiveX()); } - else if(mtof.fCorrelatedE1>-1){ + else if(mtof.fCorrelatedE1Up>-1){ double XFLow = GValue::Value("MXF_CORR_LOW"); double XFHigh = GValue::Value("MXF_CORR_HIGH"); double afp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); @@ -963,7 +1146,7 @@ float TS800::MCorrelatedXFP_E1(bool corrected) const{ std::vector val2; float val; for(unsigned int y=0;yXFLow){ val2.push_back(val); mtof.fCorrelatedXFP=y; @@ -996,19 +1179,20 @@ float TS800::MCorrelatedXFP_E1(bool corrected) const{ if(valXFLow){ val2.push_back(val); mtof.fCorrelatedXFP=y; - mtof.fCorrelatedE1=x; + mtof.fCorrelatedE1Up=x; } } } if(val2.size()==1) return val2.at(0); mtof.fCorrelatedXFP =-1; - mtof.fCorrelatedE1 =-1; + mtof.fCorrelatedE1Up =-1; } return 0; } +*/ - +/* float TS800::MCorrelatedOBJ_Ch15() const{ if(mtof.fCorrelatedOBJ_Ch15>-1) return mtof.fObj.at(mtof.fCorrelatedOBJ_Ch15); else return 0; @@ -1184,7 +1368,7 @@ float TS800::MCorrelatedXFP_E1_Ch15(bool corrected) const{ } return 0; } - +*/ float TS800::GetCorrTOF_OBJTAC() const { double afp_cor = GValue::Value("OBJTAC_TOF_CORR_AFP"); @@ -1203,24 +1387,46 @@ float TS800::GetCorrTOF_OBJ() const { float TS800::GetCorrTOF_OBJ_MESY(int i) const { //static double f_afp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); //static double f_xfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); - // if(fGlobalReset) { - static double f_mafp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); - static double f_mxfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); - // } + //if(fGlobalReset) { + f_mafp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); + f_mxfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); + //} return GetTofE1_MTDC(f_mafp_cor,f_mxfp_cor,i); } +//std::vector TS800::GetCorrTOF_OBJ_MESY() const { +float TS800::GetCorrTOF_XFP_MESY(int i) const { + //static double f_afp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); + //static double f_xfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); + //if(fGlobalReset) { + f_mafp_cor = GValue::Value("XFP_MTOF_CORR_AFP"); + f_mxfp_cor = GValue::Value("XFP_MTOF_CORR_XFP"); + //} + return GetTofE1_MTDC_XFP(f_mafp_cor,f_mxfp_cor,i); +} + + +float TS800::GetCorrTOF_RF_MESY(int i) const { + //static double f_afp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); + //static double f_xfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); + //if(fGlobalReset) { + f_mafp_cor = GValue::Value("RF_MTOF_CORR_AFP"); + f_mxfp_cor = GValue::Value("RF_MTOF_CORR_XFP"); + //} + return GetTofE1_MTDC_RF(f_mafp_cor,f_mxfp_cor,i); +} + //float TS800::GetCorrTOF_XFP(){ // double afp_cor = GValue::Value("XFP_TOF_CORR_AFP"); // double xfp_cor = GValue::Value("XFP_TOF_CORR_XFP"); // return GetTofE1_(afp_cor,xfp_cor); //} -//float TS800::GetCorrTOF_XFPTAC(){ -// double afp_cor = GValue::Value("XFPTAC_TOF_CORR_AFP"); -//double xfp_cor = GValue::Value("XFPTAC_TOF_CORR_XFP"); -//return GetTofE1_TAC(afp_cor,xfp_cor); -//} +float TS800::GetCorrTOF_XFPTAC() const{ + double afp_cor = GValue::Value("XFPTAC_TOF_CORR_AFP"); + double xfp_cor = GValue::Value("XFPTAC_TOF_CORR_XFP"); + return GetTofE1_TAC_XFP(afp_cor,xfp_cor); +} // // @@ -1425,3 +1631,78 @@ void TS800::DrawPID_Mesy_Tune(Long_t nentries,int i,TChain *chain){ } + + +double TS800::GetMTofObjE1() const { + // I return the correlated gvalue corrected time-of-flight obj to e1. + double afp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); + double xfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); + if(std::isnan(afp_cor) || std::isnan(xfp_cor)) { + printf(ALERTTEXT "Attmepting to do mtof obj correction without values!" RESET_COLOR "\n"); + fflush(stdout); + return sqrt(-1); + } + return(GetMTof().GetCorrelatedObjE1() + + afp_cor * GetAFP() + xfp_cor * GetCrdc(0).GetDispersiveX()); + +} + +double TS800::GetMTofXfpE1() const { + // I return the correlated gvalue corrected time-of-flight xfp to e1. + double afp_cor = GValue::Value("XFP_MTOF_CORR_AFP"); + double xfp_cor = GValue::Value("XFP_MTOF_CORR_XFP"); + if(std::isnan(afp_cor) || std::isnan(xfp_cor)) { + printf(ALERTTEXT "Attmepting to do mtof xfp correction without values!" RESET_COLOR "\n"); + fflush(stdout); + return sqrt(-1); + } + return(GetMTof().GetCorrelatedXfpE1() + + afp_cor * GetAFP() + xfp_cor * GetCrdc(0).GetDispersiveX()); + + +} + + +/* +float TS800::GetMTOF_ObjE1(unsigned int i,bool find_best) const { + if(!find_best) + return GetCorrTOF_OBJ_MESY(i); + double target = GValue::Value("MTOF_ObjE1"); + if(std::isnan(target)) { + target = GValue::Value("TARGET_MTOF_ObjE1"); + if(std::isnan(target)) { + return GetCorrTOF_OBJ_MESY(i); + } + } + double value = GetMTOF_ObjE1(0,0); + for(int i=1;iCalEnergy(fData.at(x)); + //std::cout << "I am getting to this part" << std::endl; } else{ temp += fData.at(x); + //std::cout << "temp was set to: " << temp << std::endl; + //std::cout << "Instead I am getting here" << std::endl; } } if(temp>0) temp = temp/((float)fData.size()); + //std::cout << "temp is set to: " << temp << std::endl ; return temp; } -float TIonChamber::GetSum(){ +float TIonChamber::GetSum() const { float temp =0.0; //if(fdE==-1.0) { /* @@ -147,6 +162,7 @@ float TIonChamber::GetSum(){ for(int x=0;xCalEnergy(GetData(x)); }else{ temp+=GetData(x); @@ -197,32 +213,30 @@ float TIonChamber::GetSum(){ //TODO: We need to change this function to correct the sum for each event // based on the track through the CRDCs -float TIonChamber::GetdE(){ - //std::cout << "GetdE() NOT IMPLEMENTED! Just returning GetSum()" << std::endl; - return GetSum(); -} - -//Calculate energy loss in Ion Chamber corrected -//for particle track -float TIonChamber::GetdECorr(TCrdc *crdc){ - float sum = GetdE(); +float TIonChamber::GetdE(TCrdc *crdc){ + float sum = GetAve(); float x = crdc->GetDispersiveX(); float y = crdc->GetNonDispersiveY(); + return GetdE(x,y); +} + +float TIonChamber::GetdE(double crdc_1_x, double crdc_1_y){ + float sum = GetAve(); + + //std::cout << "IC address is: " << TDetectorHit::Address() << std::endl; + float xtilt = GValue::Value("IC_DE_XTILT"); float ytilt = GValue::Value("IC_DE_YTILT"); float x0tilt = GValue::Value("IC_DE_X0TILT"); - /* std::cout << "---------------------" << std::endl; - std::cout << " xtilt = " << xtilt << std::endl; - std::cout << " ytilt = " << ytilt << std::endl; - std::cout << " x0tilt = " << x0tilt << std::endl; - std::cout << BLUE << " SUM = " << sum << RESET_COLOR << std::endl; - */ - sum += sum * ytilt * y; - // std::cout << GREEN << " SUM2 = " << sum << RESET_COLOR << std::endl; - sum *= TMath::Exp(xtilt*(x0tilt-x)); - //std::cout << RED << " SUM3 = " << sum << RESET_COLOR << std::endl; + if (std::isnan(xtilt) || std::isnan(ytilt) || std::isnan(x0tilt)){ + std::cout << "Define IC_DE_XTILT, IC_DE_YTILT, and IC_DE_X0TILT before using TIonChamber::GetdE()!\n"; + } + sum += sum * ytilt * crdc_1_y; + if (crdc_1_x < x0tilt){ + sum *= TMath::Exp(xtilt*(x0tilt-crdc_1_x)); + } return sum; } @@ -473,6 +487,8 @@ void TCrdc::Clear(Option_t *opt) { channel.clear(); sample.clear(); data.clear(); + has_cached_dispersive_x = false; + cached_dispersive_x = std::sqrt(-1); } /* @@ -573,9 +589,16 @@ bool TCrdc::IsGoodSample(int i) const { } float TCrdc::GetDispersiveX() const{ + //if(has_cached_dispersive_x) { + // return cached_dispersive_x; + //} + + //std::cout << "CRDCX address is: " << TDetectorHit::Address() << std::endl; + int maxpad = GetMaxPad(); //std::cout << " Before Max Pad Return " << std::endl; if (maxpad ==-1){ + has_cached_dispersive_x = true; return sqrt(-1); } //std::cout << " After Max Pad Return " << std::endl; @@ -631,7 +654,12 @@ float TCrdc::GetDispersiveX() const{ // + 0.5 so that we take the middle of the pad, not the left edge. double mean_chan = weighted_sum/datasum + 0.5; - return (mean_chan*x_slope+x_offset); + double output = (mean_chan*x_slope+x_offset); + + has_cached_dispersive_x = true; + cached_dispersive_x = output; + + return output; } @@ -740,6 +768,7 @@ void TMTof::Copy(TObject &obj) const { mtof.fRf = fRf; mtof.fHodoscope = fHodoscope; mtof.fRef = fRef; + } void TMTof::Clear(Option_t *opt) { @@ -755,13 +784,172 @@ void TMTof::Clear(Option_t *opt) { fHodoscope.clear(); fRef.clear(); - fCorrelatedXFP=-1; - fCorrelatedOBJ=-1; - fCorrelatedE1=-1; - fCorrelatedXFP_Ch15=-1; - fCorrelatedOBJ_Ch15=-1; - fCorrelatedE1_Ch15=-1; + fCorrelatedXFP=sqrt(-1); + fCorrelatedOBJ=sqrt(-1); + fCorrelatedE1Up=sqrt(-1); + fCorrelatedRfE1=sqrt(-1); + fCorrelatedXFPE1=sqrt(-1); + fCorrelatedOBJE1=sqrt(-1); + //fCorrelatedXFP_Ch15=0xffffffff; + //fCorrelatedOBJ_Ch15=0xffffffff; + //fCorrelatedE1_Ch15=0xffffffff; } +//bool TMTof::Correlate() const { +// CorrelateE1Up(); +// CorrelateObj(); +// CorrelateXfp(); +// return true; +//} + +double TMTof::GetCorrelatedObjE1() const{ + double target = GValue::Value("TARGET_MTOF_OBJE1"); + if (std::isnan(target)){ + std::cout << "TARGET_MTOF_OBJE1 not defined! Use fObj.at(0) if you want first.\n"; + fCorrelatedOBJE1 = sqrt(-1); + return fCorrelatedOBJE1 = sqrt(-1); + } + + //shift allows "shifting" of TOF to line up different runs. Necessary when, + //e.g., the voltage on a scintillator changes during an experiment + double shift = GValue::Value("SHIFT_MTOF_OBJE1"); + + if(fObj.size() && fE1Up.size()){ + fCorrelatedOBJE1 = std::numeric_limits::max(); + for(size_t i=0;i::max(); + for(size_t i=0;i::max(); + for(size_t i=0;i+; +#pragma link C++ class TDDASEvent+; #pragma link C++ class TSegaSegmentHit+; #pragma link C++ class std::vector+; #pragma link C++ class TSegaHit+; diff --git a/libraries/TDetSystems/TSega/TSega.cxx b/libraries/TDetSystems/TSega/TSega.cxx index 1807b071..7ca8f43d 100644 --- a/libraries/TDetSystems/TSega/TSega.cxx +++ b/libraries/TDetSystems/TSega/TSega.cxx @@ -1,5 +1,6 @@ #include "TSega.h" +#include #include #include @@ -53,7 +54,8 @@ int TSega::BuildHits(std::vector& raw_data) { SetTimestamp(nscl.GetTimestamp()); - TDDASEvent ddas(nscl.GetPayloadBuffer()); + TSmartBuffer buf = nscl.GetPayloadBuffer(); + TDDASEvent ddas(buf); unsigned int address = ( (1<<24) + (ddas.GetCrateID()<<16) + @@ -210,6 +212,12 @@ void TSega::InsertHit(const TDetectorHit& hit) { } void TSega::SetRunStart(unsigned int unix_time) { + // Only adjust times for production runs in e13701. + if(unix_time < 1453953420 || + unix_time > 1454425200) { + return; + } + // Wed Jan 27 22:57:09 2016 unsigned int previous = fRunStart==0 ? 1453953429 : fRunStart; int tdiff = unix_time - previous; @@ -220,3 +228,10 @@ void TSega::SetRunStart(unsigned int unix_time) { hit.SetTimestamp(timestamp_diff + hit.Timestamp()); } } + +void TSega::SortHitsByTimestamp() { + std::sort(sega_hits.begin(), sega_hits.end(), + [](const TSegaHit& a, const TSegaHit& b) { + return a.Timestamp() < b.Timestamp(); + }); +} diff --git a/libraries/TDetSystems/TSega/TSegaHit.cxx b/libraries/TDetSystems/TSega/TSegaHit.cxx index 1003ef81..f5f0030e 100644 --- a/libraries/TDetSystems/TSega/TSegaHit.cxx +++ b/libraries/TDetSystems/TSega/TSegaHit.cxx @@ -9,6 +9,7 @@ #include "GValue.h" #include "TSega.h" +#include TSegaHit::TSegaHit() { Clear(); @@ -56,7 +57,7 @@ void TSegaHit::DrawTrace(int segnum) { return; } - TH1I hist("hist", "", trace->size(), 0, 10*trace->size()); + GH1D hist("sega_wave", "", trace->size(), 0, 10*trace->size()); hist.SetStats(false); if(segnum==0){ @@ -170,12 +171,17 @@ int TSegaHit::GetMainSegnum() const { return output; } -TVector3 TSegaHit::GetPosition(bool apply_array_offset) const { +TVector3 TSegaHit::GetPosition(bool apply_array_offset, TVector3 array_offset) const { TVector3 array_pos = TSega::GetSegmentPosition(GetDetnum(), GetMainSegnum()); if(apply_array_offset){ - array_pos += TVector3(GValue::Value("Sega_X_offset"), - GValue::Value("Sega_Y_offset"), - GValue::Value("Sega_Z_offset")); + if(std::isnan(array_offset.X()) && + std::isnan(array_offset.Y()) && + std::isnan(array_offset.Z())) { + array_offset = TVector3(GValue::Value("Sega_X_offset"), + GValue::Value("Sega_Y_offset"), + GValue::Value("Sega_Z_offset")); + } + array_pos += array_offset; } return array_pos; } @@ -194,7 +200,7 @@ double TSegaHit::GetDoppler(double beta,const TVector3& particle_vec, const TVec } double gamma = 1/(sqrt(1-pow(beta,2))); - TVector3 pos = GetPosition() + sega_offset; + TVector3 pos = GetPosition(true, sega_offset); double cos_angle = TMath::Cos(pos.Angle(particle_vec)); double dc_en = GetEnergy()*gamma *(1 - beta*cos_angle); return dc_en; diff --git a/libraries/TDetSystems/TUML/LinkDef.h b/libraries/TDetSystems/TUML/LinkDef.h new file mode 100644 index 00000000..e0762a49 --- /dev/null +++ b/libraries/TDetSystems/TUML/LinkDef.h @@ -0,0 +1,14 @@ +// TUML.h TUMLHit.h + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +#pragma link C++ nestedclasses; + +#pragma link C++ class TUMLHit+; +#pragma link C++ class std::vector+; +#pragma link C++ class TUML+; + +#endif diff --git a/libraries/TDetSystems/TUML/TUML.cxx b/libraries/TDetSystems/TUML/TUML.cxx new file mode 100644 index 00000000..eb191355 --- /dev/null +++ b/libraries/TDetSystems/TUML/TUML.cxx @@ -0,0 +1,293 @@ + +#include + +#include + +#include +#include +#include + +ClassImp(TUML) + + +int TUML::BuildHits(std::vector& raw_data) { + for(auto& event : raw_data){ + SetTimestamp(event.GetTimestamp()); + TSmartBuffer buf = event.GetPayloadBuffer(); + int total_size = *(int*)buf.GetData(); + const char* buffer_end = buf.GetData() + total_size; + buf.Advance(sizeof(int)); + buf.Advance(sizeof(short)); // i am now even more confused. extra 0x0000 after first ncsl ts + //buf.Advance(sizeof(int)); // i dont know why this is??? 2019-Pt run pcb. + //int ptr = sizeof(int); + while(buf.GetData() < buffer_end) { + // Constructor advances the buffer to end of each channel + TDDASEvent ddas(buf); + //std::cout << ddas.GetTimestamp() << " ddas.GetAddress(): " << ddas.GetAddress() << std::endl; + + ///////////////// + ///////////////// + ///////////////// + TUMLHit hit; + hit.SetAddress(ddas.GetAddress()); + hit.SetCharge(ddas.GetEnergy()); + hit.SetTime(ddas.GetCFDTime()); + hit.SetTimestamp(ddas.GetTimestamp()); + hit.SetExternalTimestamp(ddas.GetExternalTimestamp()); + //InsertHit(hit); + uml_hits.push_back(hit); + ///////////////// + ///////////////// + ///////////////// + + int ddas_card = ddas.GetSlotID(); + int ddas_channel = ddas.GetChannelID(); + //int ddas_energy = ddas.GetEnergy(); + //unsigned int ddas_address = ddas.GetAddress(); + /* + std::cout << "address\t0x" << std::hex << ddas_address << std::dec << std::endl; + std::cout << "chan \t" << ddas_channel << std::endl; + std::cout << "card \t" << ddas_card << std::endl; + std::cout << "eng \t" << ddas_energy << std::endl; + std::cout << "--------------------- " << std::endl; + */ + + if(ddas_card==2) { // + switch(ddas_channel) { + case 0: //pin1 + fPin1.SetAddress(ddas.GetAddress()); + fPin1.SetCharge(ddas.GetEnergy()); + fPin1.SetTime(ddas.GetCFDTime()); + fPin1.SetTimestamp(ddas.GetTimestamp()); + fPin1.SetExternalTimestamp(ddas.GetExternalTimestamp()); + break; + case 1: //pin2 + fPin2.SetAddress(ddas.GetAddress()); + fPin2.SetCharge(ddas.GetEnergy()); + fPin2.SetTime(ddas.GetCFDTime()); + fPin2.SetTimestamp(ddas.GetTimestamp()); + fPin2.SetExternalTimestamp(ddas.GetExternalTimestamp()); + break; + case 2: //implant + fImplant.SetAddress(ddas.GetAddress()); + fImplant.SetCharge(ddas.GetEnergy()); + fImplant.SetTime(ddas.GetCFDTime()); + fImplant.SetTimestamp(ddas.GetTimestamp()); + fImplant.SetExternalTimestamp(ddas.GetExternalTimestamp()); + break; + case 3: //veto + fVeto.SetAddress(ddas.GetAddress()); + fVeto.SetCharge(ddas.GetEnergy()); + fVeto.SetTime(ddas.GetCFDTime()); + fVeto.SetTimestamp(ddas.GetTimestamp()); + fVeto.SetExternalTimestamp(ddas.GetExternalTimestamp()); + break; + case 4: //xfp cfd + fXfp1.SetAddress(ddas.GetAddress()); + fXfp1.SetCharge(ddas.GetEnergy()); + fXfp1.SetTime(ddas.GetCFDTime()); + fXfp1.SetTimestamp(ddas.GetTimestamp()); + fXfp1.SetExternalTimestamp(ddas.GetExternalTimestamp()); + break; + case 5: //xfp analog + fXfp2.SetAddress(ddas.GetAddress()); + fXfp2.SetCharge(ddas.GetEnergy()); + fXfp2.SetTime(ddas.GetCFDTime()); + fXfp2.SetTimestamp(ddas.GetTimestamp()); + fXfp2.SetExternalTimestamp(ddas.GetExternalTimestamp()); + break; + case 6: //tac1 pin1-xfp + fTac1 = ddas.GetEnergy(); + break; + case 7: //tac2 pin2-xfp + fTac2 = ddas.GetEnergy(); + break; + case 8: //tac3 sssd-xfp + fTac3 = ddas.GetEnergy(); + break; + case 9: //tac4 implant-xfp + fTac4 = ddas.GetEnergy(); + break; + case 10: //tac5 pin1-rf + fTac5 = ddas.GetEnergy(); + break; + case 11: //"pin4 high-gain" -> veto high gain + break; + case 12: //xtal q6p4 + gamma_energy = ddas.GetEnergy(); //! + gamma_time = ddas.GetTimestamp(); //! + //std::cout << "ge: " << gamma_energy << "\t"; + //std::cout << "gt: " << gamma_time << "\n"; + break; + case 13: // + break; + case 14: // + break; + case 15: // low hertz pulser + break; + }; + + + } else if(ddas_card==3) { //sssd detector + TUMLHit hit; + hit.SetAddress(ddas.GetAddress()); + hit.SetCharge(ddas.GetEnergy()); + hit.SetTime(ddas.GetCFDTime()); + hit.SetTimestamp(ddas.GetTimestamp()); + hit.SetExternalTimestamp(ddas.GetExternalTimestamp()); + //InsertHit(hit); + fSssd.push_back(hit); + } + + + } + } + fSize = uml_hits.size(); + return fSize; +} + +double TUML::GetSssdEnergy() const { + double sum = 0.00; + for(size_t i=0;i chan; + std::vector data; + for(size_t i=0;i 10.) { +// double dPoPx = GetXPosition()/GValue::Value("Dispersion"); +// double beta = GValue::Value("Length") * (1 + dPoPx * GValue::Value("Disp_Length") /100.) / GetTof() / GValue::Value("VC"); +// double gamma = Beta_to_Gamma(beta); + if (beta > 0 && beta < 1 ) { +// brho = GValue::Value("Brho0") * ( 1 + dPoPx / 100.); +// if(Z>0) { +// double dZ = GValue::Value("Z_disp") - GetZ(); +// +// double dPoPz = sqrt(fabs(dZ))* GValue::Value("Disp_Z") / 100. ; +// if(dZ<0) dPoPz = -dPoPz; +// +// double dPoP = dPoPz + dPoPx; +// +// brho = GValue::Value("Brho0") * ( 1 + dPoP/100.); +// +// +// } + AoQ_local = brho / 3.1071 / beta / gamma; + } else { + gamma=1; + beta=0; + } + } + return AoQ_local; +} + +double TUML::SetZ() const { + double Z = 0; + double dPoPx = GetXPosition()/GValue::Value("Dispersion"); + if (GetTof() > 0) { + double beta = GValue::Value("Length") * (1 + dPoPx * GValue::Value("Disp_Length") /100.) / GetTof() / GValue::Value("VC"); + double beta2 = beta*beta; + if (beta2 > 0) + { + + double dE_v = -1.+log(5930./(1./beta2-1.))/beta2; + if (dE_v > 0) { + //double dE = GetPin1().GetEnergy()*GValue::Value("Tke_Slope0") + GetPin2().GetEnergy()*GValue::Value("Tke_Slope1") + GetSssdEnergy()*GValue::Value("Tke_Slope2") + GValue::Value("TKE_Offset"); + double dE = GetPin1().GetEnergy()+GetPin2().GetEnergy()+GetSssdEnergy(); + double v = sqrt(dE / dE_v); + Z = v*v*GValue::Value("Z2_slope") + v* GValue::Value("Z_slope")+GValue::Value("Z_offset"); + //int Zi = (double)Z + 0.5; + //dZ = (double)Z - Zi; + } + } + } + //set Z + return Z; +} + + + +void TUML::CalParameters() { + TKE = CalTKE(); + //double beta; //! + double dPoPx = GetXPosition()/GValue::Value("Dispersion"); + brho = GValue::Value("Brho0") * ( 1 + dPoPx / 100.); + if(GetTof()>0) + beta = GValue::Value("Length") * (1 + dPoPx * GValue::Value("Disp_Length") /100.) / GetTof() / GValue::Value("VC"); + else beta = 0; + //double gamma; //! + gamma = Beta_to_Gamma(beta); + //double brho; //! + //double Z; //! + Z = SetZ(); + + if(Z>0) { + double dZ = GValue::Value("Z_disp") - GetZ(); + + double dPoPz = sqrt(fabs(dZ))* GValue::Value("Disp_Z") / 100. ; + if(dZ<0) dPoPz = -dPoPz; + + double dPoP = dPoPz + dPoPx; + + brho = GValue::Value("Brho0") * ( 1 + dPoP/100.); + + + } + + //double AoQ; //! + AoQ = SetAoQ(); + //double Q; //! + if(AoQ > 0 && TKE > 0 && gamma>0) { + Q = TKE / (gamma- 1.) / GValue::Value("AEM") / AoQ; + } +} + + +void TUML::ReCalBrho(){ +} + + + + + + diff --git a/libraries/TDetSystems/TUML/TUMLHit.cxx b/libraries/TDetSystems/TUML/TUMLHit.cxx new file mode 100644 index 00000000..c0cac619 --- /dev/null +++ b/libraries/TDetSystems/TUML/TUMLHit.cxx @@ -0,0 +1,22 @@ + +#include + +ClassImp(TUMLHit) + + +void TUMLHit::SetTrace(unsigned int trace_length, const unsigned short* trace) { + fTrace.reserve(trace_length); + copy(trace,trace+trace_length,back_inserter(fTrace)); + //printf("%s called\t%i\n",__PRETTY_FUNCTION__,Size()); fflush(stdout); +} + + +void TUMLHit::Clear(Option_t *opt) { + TDetectorHit::Clear(opt); + fTrace.clear(); + fExternalTimestamp = -1; +} + + + + diff --git a/libraries/TGRUTUtil/LinkDef.h b/libraries/TGRUTUtil/LinkDef.h index 6e80cd6a..267c9813 100644 --- a/libraries/TGRUTUtil/LinkDef.h +++ b/libraries/TGRUTUtil/LinkDef.h @@ -1,4 +1,4 @@ -//TChannel.h TGRUTUtilities.h TPresetCanvas.h TCalibrator.h +//TChannel.h TGRUTUtilities.h TPresetCanvas.h TCalibrator.h TVariable.h #ifdef __CINT__ #pragma link off all globals; @@ -6,6 +6,8 @@ #pragma link off all functions; #pragma link C++ nestedclasses; +#pragma link C++ class TVariable+; + #pragma link C++ class TChannel-; #pragma link C++ class TCalibrator+; #pragma link C++ struct TCalibrator::Peak+; @@ -19,7 +21,19 @@ #pragma link C++ function MakeVectorFromFile; -#endif + +#pragma link C++ function operator+(const TVariable&,const TVariable&); +#pragma link C++ function operator+(const TVariable&,double); +#pragma link C++ function operator-(const TVariable&,const TVariable&); +#pragma link C++ function operator-(const TVariable&,double); +#pragma link C++ function operator*(const TVariable&,const TVariable&); +#pragma link C++ function operator*(const TVariable&,double); +#pragma link C++ function operator/(const TVariable&,const TVariable&); +#pragma link C++ function operator/(const TVariable&,double); +#pragma link C++ function operator%(const TVariable&,const TVariable&); +#pragma link C++ function operator%(const TVariable&,int); + +#endif diff --git a/libraries/TGRUTUtil/TCalibrator.cxx b/libraries/TGRUTUtil/TCalibrator.cxx index f88a1127..bfcb7072 100644 --- a/libraries/TGRUTUtil/TCalibrator.cxx +++ b/libraries/TGRUTUtil/TCalibrator.cxx @@ -7,11 +7,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -21,25 +23,41 @@ #include #include #include +#include #include #include "combinations.h" ClassImp(TCalibrator) -TCalibrator::TCalibrator() { +TCalibrator::TCalibrator() { linfit=0; efffit=0; - Clear(); + Clear(); } -TCalibrator::~TCalibrator() { +TCalibrator::~TCalibrator() { if(linfit) delete linfit; if(efffit) delete efffit; } void TCalibrator::Copy(TObject &obj) const { } +bool TCalibrator::Check() const { + + if(Size()<2) + return false; + + for(auto it:fPeaks) { + double caleng = it.centroid*GetParameter(1)+GetParameter(0); + double pdiff = std::abs(caleng-it.energy)/it.energy; + if(pdiff>0.05) { + return false; + } + } + return true; +} + void TCalibrator::Print(Option_t *opt) const { int counter=0; printf("\t%2senergy%10scent%10scalc%10sarea%7snuc%8sintensity\n","","","","","",""); @@ -60,7 +78,7 @@ void TCalibrator::Print(Option_t *opt) const { // printf("\t%i\t%.1f\t%.1f\n",counter++,it2.second,it2.first); //} //printf("------------------\n"); - //} + //} //if(linfit) linfit->Print(); } @@ -76,7 +94,7 @@ std::string TCalibrator::PrintEfficency(const char *filename) { counter++,it.energy,it.area,100, (it.intensity/100)*1e5 )); } toprint.append("--------------------------------------\n"); - + if(file.length()) { std::ofstream ofile; ofile.open(file.c_str()); @@ -104,17 +122,18 @@ TGraphErrors &TCalibrator::MakeEffGraph(double seconds,double bq,Option_t *opt) //TNucleus n(it.nucleus.c_str()); energy.push_back(it.energy); error_e.push_back(0.0); - observed.push_back((it.area/seconds)/ ((it.intensity/100)*bq) ); + //observed.push_back((it.area/seconds) / ((it.intensity/100)*bq) ); + observed.push_back(it.area / ((it.intensity/100)*bq*seconds) ); error_o.push_back( observed.back() * (sqrt(it.area)/it.area) ); } - + eff_graph.Clear(); eff_graph = TGraphErrors(fPeaks.size(),energy.data(),observed.data(),error_e.data(),error_o.data()); - + if(efffit) efffit->Delete(); static int counter=0; - efffit = new TF1(Form("eff_fit_%i",counter++),GRootFunctions::GammaEff,0,1500,4); + efffit = new TF1(Form("eff_fit_%i",counter++),GRootFunctions::GammaEff,0,4000,4); eff_graph.Fit(efffit,fitopt.Data()); if(option.Contains("draw",TString::kIgnoreCase)) { @@ -132,19 +151,54 @@ TGraphErrors &TCalibrator::MakeEffGraph(double seconds,double bq,Option_t *opt) return eff_graph; } -void TCalibrator::Clear(Option_t *opt) { + +bool TCalibrator::SaveEffGraph(std::string datafile,std::string fitfile) { + if(!efffit) + return false; + + if(datafile.length()==0) + datafile = Form("%s_data.dat",this->GetName()); + if(fitfile.length()==0) + fitfile = Form("%s_fit.dat",this->GetName()); + + std::ofstream outfile; + outfile.open(datafile.c_str()); + for(int i=0;iGetRange(xmin,xmax); + double range = xmax-xmin; + while(xminEval(xmin) << std::endl; + xmin += range/10000.; + } + outfile << std::endl; + outfile.close(); + return true; + +} + + +void TCalibrator::Clear(Option_t *opt) { fit_graph.Clear(opt); eff_graph.Clear(opt); //all_fits.clear(); - + for(int i=0;i<4;i++) eff_par[i]=0.; - + fPeaks.clear(); total_points=0; } -void TCalibrator::Draw(Option_t *opt) { +void TCalibrator::Draw(Option_t *opt) { //if((graph_of_everything.GetN()<1) && // (all_fits.size()>0)) //MakeCalibrationGraph(); @@ -156,7 +210,7 @@ void TCalibrator::Draw(Option_t *opt) { } void TCalibrator::Fit(int order,bool zerozero) { - + //if((graph_of_everything.GetN()<1) && // (all_fits.size()>0)) MakeCalibrationGraph(zerozero); @@ -180,17 +234,24 @@ void TCalibrator::Fit(int order,bool zerozero) { fit_graph.Fit(linfit); fit_graph.Print(); Print(); - + +} + +double TCalibrator::GetChi2(Option_t *opt) const { + if(!linfit) + return sqrt(-1); + return linfit->GetChisquare()/linfit->GetNDF(); + } double TCalibrator::GetParameter(int i) const { - if(linfit) + if(linfit) return linfit->GetParameter(i); return sqrt(-1); } double TCalibrator::GetEffParameter(int i) const { - if(efffit) + if(efffit) return efffit->GetParameter(i); return sqrt(-1); } @@ -209,18 +270,18 @@ TGraph &TCalibrator::MakeCalibrationGraph(bool zerozero) { //double min_fom) { for(auto it:fPeaks) { xvalues.push_back(it.centroid); yvalues.push_back(it.energy); - } + } fit_graph.Clear(); fit_graph = TGraph(xvalues.size(),xvalues.data(),yvalues.data()); - return fit_graph; + return fit_graph; } std::vector TCalibrator::Calibrate(double min_fom) { std::vector vec; return vec; } -int TCalibrator::AddData(TH1 *data,std::string source, double sigma,double threshold,double error) { - if(!data || !source.length()) { +int TCalibrator::AddData(TH1 *data,std::string source, double sigma,double threshold,bool rm_bg,double error) { + if(!data || !source.length()) { printf("data not added. data = %p \t source = %s\n",(void*)data,source.c_str()); return 0; } @@ -228,7 +289,7 @@ int TCalibrator::AddData(TH1 *data,std::string source, double sigma,double thres return AddData(data,&n,sigma,threshold,error); } -int TCalibrator::AddData(TH1 *data,TNucleus *source, double sigma,double threshold,double error) { +int TCalibrator::AddData(TH1 *data,TNucleus *source, double sigma,double threshold,bool rm_bg,double error) { if(!data || !source) { printf("data not added. data = %p \t source = %p\n",(void*)data,(void*)source); return 0; @@ -244,6 +305,9 @@ int TCalibrator::AddData(TH1 *data,TNucleus *source, double sigma,double thresho else name = Form("%s_%i_%i",source->GetName(),displayed_x_min,displayed_x_max); + TNamed::SetName(Form("%s%s",GetName(),name.c_str())); + + TIter iter(source->GetTransitionList()); std::vector source_energy; std::map src_eng_int; @@ -254,30 +318,65 @@ int TCalibrator::AddData(TH1 *data,TNucleus *source, double sigma,double thresho std::sort(source_energy.begin(),source_energy.end()); TSpectrum spectrum; + if(rm_bg) { + //data = (TH1*)data->Clone(Form("%s_clone",data->GetName())); + TH1 *bg = spectrum.Background(data,20,"Compton"); + data->Add(bg,-1); + } spectrum.Search(data,sigma,"",threshold); - std::vector data_channels; - std::map peak_area;; + while(spectrum.GetNPeaks()>10) { + spectrum.Clear(); + threshold+=.01; + spectrum.Search(data,sigma,"",threshold); + } + //std::vector data_channels; + std::vector peak_positions; + //std::map peak_area;; //std::vector data; for(int x=0;xGetXaxis()->GetBinWidth(1); + //double range = 8*data->GetXaxis()->GetBinWidth(1); //printf(DGREEN "\tlow %.02f \t high %.02f" RESET_COLOR "\n",spectrum.GetPositionX()[x]-range,spectrum.GetPositionX()[x]+range); - GPeak *fit = PhotoPeakFit(data,spectrum.GetPositionX()[x]-range,spectrum.GetPositionX()[x]+range,"no-print"); - //data_channels - //data_channels.push_back(fit.GetCentroid()); - //datatosource[fit->GetCentroid()] = sqrt(-1); - data_channels.push_back(fit->GetCentroid()); - data->GetListOfFunctions()->Remove(fit); - peak_area[fit->GetCentroid()] = fit->GetSum(); + + //GPeak *fit = PhotoPeakFit(data,spectrum.GetPositionX()[x]-range,spectrum.GetPositionX()[x]+range,"no-print"); + //data_channels.push_back(fit->GetCentroid()); + //data->GetListOfFunctions()->Remove(fit); + //peak_area[fit->GetCentroid()] = fit->GetSum(); + + peak_positions.push_back(spectrum.GetPositionX()[x]); + + } - std::map datatosource = Match(data_channels,source_energy);; + //std::map datatosource = Match(data_channels,source_energy);; + std::map datatosource = Match(peak_positions,source_energy);; //PrintMap(datatosource); + double range = 8;//8*data->GetXaxis()->GetBinWidth(1); for(auto it : datatosource) { - AddPeak(it.first,it.second,source->GetName(),peak_area.at(it.first),src_eng_int[it.second]); + + double peak = it.first; + double eng = it.second; + + range = 0.01 * peak; + if(range < 8.) + range = 8.0; + + + // GPeak *fit = PhotoPeakFit(data,peak-range,peak+range/2.,"no-print"); + GGaus *fit = GausFit(data,peak-range,peak+range/2.,"no-print"); + // GGaus *fit = GausFit(data,peak-range,peak+range,"no-print"); + + peak = fit->GetCentroid(); + fit->Print(); + //data_channels.push_back(fit->GetCentroid()); + //data->GetListOfFunctions()->Remove(fit); + //peak_area[fit->GetCentroid()] = fit->GetSum(); + + //AddPeak(it.first,it.second,source->GetName(),peak_area.at(it.first),src_eng_int[it.second]); + AddPeak(fit->GetCentroid(),eng,source->GetName(),fit->GetSum(),src_eng_int[eng],fit->GetParameter(2)*2.355/fit->GetCentroid()); } - + //Print(); int counter =0; for(auto it : datatosource) { @@ -290,7 +389,7 @@ int TCalibrator::AddData(TH1 *data,TNucleus *source, double sigma,double thresho void TCalibrator::ResetMap(std::map &inmap) { for(auto &it:inmap) { it.second = sqrt(-1); - } + } } void TCalibrator::PrintMap(std::map &inmap) { @@ -304,7 +403,7 @@ void TCalibrator::PrintMap(std::map &inmap) { } std::map TCalibrator::Match(std::vector peaks,std::vector source) { - std::map map; + std::map map; std::sort(peaks.begin(),peaks.end()); std::sort(source.begin(),source.end()); @@ -318,7 +417,7 @@ std::map TCalibrator::Match(std::vector peaks,std::vector //std::cout << "Num source: " << source.size() << std::endl; TLinearFitter fitter(1, "1 ++ x"); - + for(size_t num_data_points = peaks.size(); num_data_points > 0; num_data_points--) { double best_chi2 = DBL_MAX; for(auto peak_values : combinations(peaks, num_data_points)) { @@ -328,7 +427,7 @@ std::map TCalibrator::Match(std::vector peaks,std::vector source_values.push_back(0); if(peaks.size()>3) { - double max_err = 0.02; + double max_err = 0.02; double pratio = peak_values.front()/peak_values.at(peak_values.size()-2); double sratio = source_values.front()/source_values.at(source_values.size()-2); //std::cout << "ratio: " << pratio << " - " << sratio << " = " << std::abs(pratio-sratio) << std::endl; @@ -337,7 +436,7 @@ std::map TCalibrator::Match(std::vector peaks,std::vector continue; } } - + fitter.ClearPoints(); fitter.AssignData(source_values.size(), 1, peak_values.data(), source_values.data()); fitter.Eval(); @@ -369,17 +468,17 @@ std::map TCalibrator::Match(std::vector peaks,std::vector fitter.ClearPoints(); fitter.AssignData(source_values.size()-1, 1, peak_values.data(), source_values.data()); fitter.Eval(); - + if(std::abs(fitter.GetParameter(0)) > 10) { map.clear(); break; } - + std::swap(peak_values[skipped_point], peak_values.back()); std::swap(source_values[skipped_point], source_values.back()); } } - + if(map.size()) { return map; } @@ -401,7 +500,7 @@ std::map TCalibrator::Match(std::vector peaks,std::vector - // //for(auto s : source) + // //for(auto s : source) // // printf(" s = %.02f\n",s); @@ -412,7 +511,7 @@ std::map TCalibrator::Match(std::vector peaks,std::vector // std::vector sused; // for(unsigned int i=0;i TCalibrator::Match(std::vector peaks,std::vector // double sratio = source.at(s1)/source.at(s2); // for(unsigned int p1=0;p1 TCalibrator::Match(std::vector peaks,std::vector // max_err = 0.05; - + // for(std::map::iterator mit1=map.begin();mit1!=map.end();mit1++) { // for(std::map::iterator mit2=mit1;mit2!=map.end();mit2++) { // if(mit1==mit2) continue; @@ -475,7 +574,7 @@ std::map TCalibrator::Match(std::vector peaks,std::vector // } // } // } - + // //printf("points.size() = %i\n",points.size()); // std::sort(points.begin(),points.end()); @@ -529,7 +628,7 @@ std::map TCalibrator::Match(std::vector peaks,std::vector bool TCalibrator::CheckMap(std::map inmap) { for(auto it:inmap) { - if(std::isnan(it.second)) + if(std::isnan(it.second)) return false; } return true; @@ -537,16 +636,44 @@ bool TCalibrator::CheckMap(std::map inmap) { -void TCalibrator::UpdateTChannel(TChannel *channel) { } +void TCalibrator::UpdateTChannel(TChannel *channel) { } -void TCalibrator::AddPeak(double cent,double eng,std::string nuc,double a,double inten) { +void TCalibrator::AddPeak(double cent,double eng,std::string nuc,double a,double inten,double reso) { Peak p; p.centroid = cent; p.energy = eng; p.nucleus = nuc; p.area = a; p.intensity = inten; + p.reso = reso; fPeaks.push_back(p); return; } + + + + +TH1 *TCalibrator::ApplyCalibration(TH1 *source,int bins,double range,Option_t *opt) const { + if(fit_graph.GetN()<1) + return 0; + double offset = GetParameter(0); + double gain = GetParameter(1); + std::string hname = Form("%s_cal",source->GetName()); + TH1D *hist = new TH1D(hname.c_str(),hname.c_str(),bins,0,range); + for(int x=1;x<=source->GetNbinsX();x++) { + double value = source->GetXaxis()->GetBinLowEdge(x); + double weight = source->GetBinContent(x); + double j=0.0; + while(j<=weight) { + value = (value+gRandom->Uniform())*gain + offset; + hist->Fill(value); + //printf("bin[%i]: %.0f\t\t%.02f\n",x,j,value); + j++; + } + } + return hist; +} + + + diff --git a/libraries/TGRUTUtil/TChannel.cxx b/libraries/TGRUTUtil/TChannel.cxx index d5a23a17..5fc622d0 100644 --- a/libraries/TGRUTUtil/TChannel.cxx +++ b/libraries/TGRUTUtil/TChannel.cxx @@ -8,9 +8,11 @@ #include #include +#include "TBuffer.h" #include "TRandom.h" #include "GRootFunctions.h" +#include "TGRUTUtilities.h" std::map TChannel::fChannelMap; TChannel *TChannel::fDefaultChannel = new TChannel("TChannel",0xffffffff); @@ -89,6 +91,12 @@ std::ostream& operator<<(std::ostream& out, const TChannel& chan) { } out << "\n"; + //if(chan.GetChannelPosition().Mag()>0) { + out << " X:\t" << chan.GetChannelPosition().X() << "\n"; + out << " Y:\t" << chan.GetChannelPosition().Y() << "\n"; + out << " Z:\t" << chan.GetChannelPosition().Z() << "\n"; + //} + // Close out the rest out << "}\n-----------------------------------\n"; @@ -119,6 +127,7 @@ void TChannel::Copy(TObject &rhs) const { ((TChannel&)rhs).time_coeff = time_coeff; ((TChannel&)rhs).efficiency_coeff = efficiency_coeff; ((TChannel&)rhs).pedestal = pedestal; + ((TChannel&)rhs).fPosition = fPosition; } void TChannel::Clear(Option_t *opt) { @@ -133,6 +142,7 @@ void TChannel::Clear(Option_t *opt) { array_subposition = ""; collected_charge = ""; pedestal = 0; + fPosition.Clear(); } //void TChannel::Compare(const TObject &rhs) const { } @@ -244,22 +254,6 @@ int TChannel::DeleteAllChannels() { return count; } - - -void TChannel::trim(std::string * line, const std::string & trimChars) { - //Removes the the string "trimCars" from the start or end of 'line' - if(line->length() == 0) - return; - - std::size_t found = line->find_first_not_of(trimChars); - if(found != std::string::npos) - *line = line->substr(found, line->length()); - - found = line->find_last_not_of(trimChars); - if(found != std::string::npos) - *line = line->substr(0, found + 1); -} - void TChannel::ClearCalibrations() { ClearEnergyCoeff(); ClearEfficiencyCoeff(); @@ -484,7 +478,7 @@ int TChannel::ParseInputData(std::string &input,Option_t *opt) { while(std::getline(infile,line)) { linenumber++; - trim(&line); + trim(line); size_t comment = line.find("//"); if(comment != std::string::npos) { line = line.substr(0,comment); @@ -523,7 +517,7 @@ int TChannel::ParseInputData(std::string &input,Option_t *opt) { if(openbrace != std::string::npos) { brace_open = true; name = line.substr(0,openbrace).c_str(); - trim(&name); + trim(name); channel = new TChannel(name.c_str()); } //=============================================// @@ -531,14 +525,14 @@ int TChannel::ParseInputData(std::string &input,Option_t *opt) { if(colon != std::string::npos) { // Type is everything up to the colon std::string type = line.substr(0,colon); - trim(&type); + trim(type); for(unsigned int i=0; i> channel->segment; + } else if(type == "X") { + double val = 0; ss >> val; + channel->SetChannelX(val); + } else if(type == "Y") { + double val = 0; ss >> val; + channel->SetChannelY(val); + } else if(type == "Z") { + double val = 0; ss >> val; + channel->SetChannelZ(val); } + } } } diff --git a/libraries/TGRUTUtil/TGRUTUtilities.cxx b/libraries/TGRUTUtil/TGRUTUtilities.cxx index 5acf52fd..8d6abf3f 100644 --- a/libraries/TGRUTUtil/TGRUTUtilities.cxx +++ b/libraries/TGRUTUtil/TGRUTUtilities.cxx @@ -100,3 +100,17 @@ std::string ReplaceAll(std::string str, const std::string& from, const std::stri } return str; } + +void trim(std::string& line, const std::string & trimChars) { + //Removes the the string "trimCars" from the start or end of 'line' + if(line.length() == 0) + return; + + std::size_t found = line.find_first_not_of(trimChars); + if(found != std::string::npos) + line = line.substr(found, line.length()); + + found = line.find_last_not_of(trimChars); + if(found != std::string::npos) + line = line.substr(0, found + 1); +} diff --git a/libraries/TGRUTUtil/TPresetCanvas.cxx b/libraries/TGRUTUtil/TPresetCanvas.cxx index 422383b7..f5410588 100644 --- a/libraries/TGRUTUtil/TPresetCanvas.cxx +++ b/libraries/TGRUTUtil/TPresetCanvas.cxx @@ -9,6 +9,7 @@ #include #include +#include #include ClassImp(TPresetPad) diff --git a/libraries/TGRUTUtil/TVariable.cxx b/libraries/TGRUTUtil/TVariable.cxx new file mode 100644 index 00000000..28967294 --- /dev/null +++ b/libraries/TGRUTUtil/TVariable.cxx @@ -0,0 +1,83 @@ + +#include + +std::map TVariable::fVarMap; + +void TVariable::Copy(TVariable &v) const { + v.fValue = fValue; + v.fName.assign(fName); + +} + +void TVariable::Print(Option_t *opt) const { + printf("%s: %.03f\n",fName.c_str(),fValue); +} + +void TVariable::Clear(Option_t *opt) { + fValue = sqrt(-1); + fName.clear(); +} + +double TVariable::Value(std::string(fName)) { + //if(!var) + // return sqrt(-1); + if(fVarMap.size()) { + if(fVarMap.count(fName)) { + return fVarMap.at(fName)->fValue; + } + } + return sqrt(-1); +} + + +/////////////////////////////////// +/////////////////////////////////// +/////////////////////////////////// +/////////////////////////////////// + +TVariable operator+(const TVariable& lhs,const TVariable& rhs) { + return TVariable(lhs.GetAsDouble()+rhs.GetAsDouble(),lhs.GetName()); +} + +double operator+(const TVariable& lhs,double d) { + return lhs.GetAsDouble()+d; +} + +TVariable operator-(const TVariable& lhs,const TVariable& rhs) { + return TVariable(lhs.GetAsDouble()-rhs.GetAsDouble(),lhs.GetName()); +} + +double operator-(const TVariable& lhs,double d) { + return lhs.GetAsDouble()-d; +} + +TVariable operator*(const TVariable& lhs,const TVariable& rhs) { + return TVariable(lhs.GetAsDouble()*rhs.GetAsDouble(),lhs.GetName()); +} + +double operator*(const TVariable& lhs,double d) { + return lhs.GetAsDouble()*d; +} + +TVariable operator/(const TVariable& lhs,const TVariable& rhs) { + return TVariable(lhs.GetAsDouble()/rhs.GetAsDouble(),lhs.GetName()); +} + +double operator/(const TVariable& lhs,double d) { + return lhs.GetAsDouble()/d; +} + +TVariable operator%(const TVariable& lhs,const TVariable& rhs) { + return TVariable(lhs.GetAsInt()%rhs.GetAsInt(),lhs.GetName()); +} + +int operator%(const TVariable& lhs,int d) { + return lhs.GetAsInt()%d; +} + +std::ostream& operator<<(std::ostream &out,const TVariable& v) { + return out << v.GetName() << "\t" << v(); +} + + + diff --git a/libraries/TGRUTint/TGRUTOptions.cxx b/libraries/TGRUTint/TGRUTOptions.cxx index 965be738..822a8836 100644 --- a/libraries/TGRUTint/TGRUTOptions.cxx +++ b/libraries/TGRUTint/TGRUTOptions.cxx @@ -48,7 +48,10 @@ void TGRUTOptions::Clear(Option_t* opt) { fMakeHistos = false; fSortMultiple = false; + fFSU = false; + fShouldExit = false; + fSuppressErrors = false; } void TGRUTOptions::Print(Option_t* opt) const { } @@ -115,7 +118,7 @@ void TGRUTOptions::Load(int argc, char** argv) { parser.option("t time-sort", &fTimeSortInput) .description("Reorder raw events by time"); parser.option("time-sort-depth",&fTimeSortDepth) - .description("Number of events to hold when time sorting") + .description("Number of events to hold when time sorting; default value 100000") .default_value(100000); parser.option("build-window", &fBuildWindow) .description("Build window, timestamp units") @@ -138,6 +141,11 @@ void TGRUTOptions::Load(int argc, char** argv) { .description("Show this help message"); parser.option("v version", &fShowedVersion) .description("Show version information"); + parser.option("suppress-errors", &fSuppressErrors) + .description("Suppress errors"); + parser.option("fsu",&fFSU) + .description("use FSU style DDAS format") + .default_value(false); // Look for any arguments ending with .info, pass to parser. diff --git a/libraries/TGRUTint/TGRUTTypes.cxx b/libraries/TGRUTint/TGRUTTypes.cxx index fba4b5ae..d995b99f 100644 --- a/libraries/TGRUTint/TGRUTTypes.cxx +++ b/libraries/TGRUTint/TGRUTTypes.cxx @@ -5,14 +5,17 @@ std::map detector_system_map{ {"Sega", kDetectorSystems::SEGA}, {"Gretina", kDetectorSystems::GRETINA}, {"Gretina_Sim", kDetectorSystems::GRETINA_SIM}, - {"Bank29", kDetectorSystems::BANK29}, + {"Bank88", kDetectorSystems::BANK88}, {"Mode3", kDetectorSystems::MODE3}, {"Janus", kDetectorSystems::JANUS}, {"Caesar", kDetectorSystems::CAESAR}, {"Phoswall", kDetectorSystems::PHOSWALL}, {"S800", kDetectorSystems::S800}, {"S800_SIM", kDetectorSystems::S800_SIM}, - {"FastScint", kDetectorSystems::FASTSCINT} + {"FastScint", kDetectorSystems::FASTSCINT}, + {"FSU", kDetectorSystems::FSU}, + {"UML", kDetectorSystems::UML}, + {"OBJ", kDetectorSystems::OBJ} }; diff --git a/libraries/TGRUTint/TGRUTint.cxx b/libraries/TGRUTint/TGRUTint.cxx index 33a685bc..b465a8cb 100644 --- a/libraries/TGRUTint/TGRUTint.cxx +++ b/libraries/TGRUTint/TGRUTint.cxx @@ -105,7 +105,6 @@ void TGRUTint::SplashPopNWait(bool flag) { //WaitLogo(); } - /*********************************/ bool TGRUTInterruptHandler::Notify() { @@ -121,14 +120,14 @@ bool TGRUTInterruptHandler::Notify() { } // Copied from http://stackoverflow.com/a/24315631 -std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) { - size_t start_pos = 0; - while((start_pos = str.find(from, start_pos)) != std::string::npos) { - str.replace(start_pos, from.length(), to); - start_pos += to.length(); // Handles case where 'to' is a substring of 'from' - } - return str; -} +//std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) { +// size_t start_pos = 0; +// while((start_pos = str.find(from, start_pos)) != std::string::npos) { +// str.replace(start_pos, from.length(), to); +// start_pos += to.length(); // Handles case where 'to' is a substring of 'from' +// } +// return str; +//} void TGRUTint::ApplyOptions() { TGRUTOptions* opt = TGRUTOptions::Get(); @@ -290,16 +289,20 @@ TFile* TGRUTint::OpenRootFile(const std::string& filename, Option_t* opt){ // Pass the TFile to the python GUI. if(file && GUIIsRunning()){ - TPython::Bind(file,"tdir"); - ProcessLine("TPython::Exec(\"window.AddDirectory(tdir)\");"); + std::string command = Form("TPython::Bind((TFile*)%luL, \"tdir\");" + "TPython::Exec(\"window.AddDirectory(tdir)\");", + (unsigned long)file); + ProcessLine(command.c_str()); } return file; } void TGRUTint::LoadTCutG(TCutG* cutg) { if(GUIIsRunning()) { - TPython::Bind(cutg, "cutg"); - ProcessLine("TPython::Exec(\"window.LoadCutG(cutg)\");"); + std::string command = Form("TPython::Bind((TCutG*)%luL, \"cutg\");" + "TPython::Exec(\"window.LoadCutG(cutg)\");", + (unsigned long)cutg); + ProcessLine(command.c_str()); } } diff --git a/libraries/THistogramming/TCompiledHistograms.cxx b/libraries/THistogramming/TCompiledHistograms.cxx index a3eb6fb4..4de79072 100644 --- a/libraries/THistogramming/TCompiledHistograms.cxx +++ b/libraries/THistogramming/TCompiledHistograms.cxx @@ -92,15 +92,16 @@ void TCompiledHistograms::Write() { while((dir_obj=dir_next())){ dir_obj->Write(); } + } else { + obj->Write(); } - else obj->Write(); } // objects.Write(); - TPreserveGDirectory preserve; - gDirectory->mkdir("variables")->cd(); + //TPreserveGDirectory preserve; + //gDirectory->mkdir("variables")->cd(); //variables.Write(); } diff --git a/libraries/THistogramming/TRuntimeObjects.cxx b/libraries/THistogramming/TRuntimeObjects.cxx index 1d82c5ca..4023a767 100644 --- a/libraries/THistogramming/TRuntimeObjects.cxx +++ b/libraries/THistogramming/TRuntimeObjects.cxx @@ -5,14 +5,13 @@ #include "TClass.h" #include "TCutG.h" #include "TFile.h" -#include "TH1.h" -#include "TH2.h" +#include "GH1.h" +#include "GH2.h" #include "TDirectoryFile.h" #include "TProfile.h" #include "GH1D.h" #include "GH2D.h" -#include "GH2D.h" #include "GValue.h" @@ -40,10 +39,10 @@ TRuntimeObjects::TRuntimeObjects(TList* objects, TList *gates, } -TH1* TRuntimeObjects::FillHistogram(const char* name, +GH1* TRuntimeObjects::FillHistogram(const char* name, int bins, double low, double high, double value, double weight){ - TH1* hist = (TH1*) GetObjects().FindObject(name); + GH1* hist = (GH1*) GetObjects().FindObject(name); if(!hist){ hist = new GH1D(name,name,bins,low,high); GetObjects().Add(hist); @@ -54,11 +53,25 @@ TH1* TRuntimeObjects::FillHistogram(const char* name, return hist; } -TH2* TRuntimeObjects::FillHistogram(const char* name, +GH1* TRuntimeObjects::FillHistogram(const char* name, + int bins, double low, double high, const char *value, + double weight){ + GH1* hist = (GH1*) GetObjects().FindObject(name); + if(!hist){ + hist = new GH1D(name,name,bins,low,high); + GetObjects().Add(hist); + } + if(value!=0) { + hist->Fill(value, weight); + } + return hist; +} + +GH2* TRuntimeObjects::FillHistogram(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue, double weight){ - TH2* hist = (TH2*) GetObjects().FindObject(name); + GH2* hist = (GH2*) GetObjects().FindObject(name); if(!hist){ hist = new GH2D(name,name, Xbins, Xlow, Xhigh, @@ -71,6 +84,23 @@ TH2* TRuntimeObjects::FillHistogram(const char* name, return hist; } +GH2* TRuntimeObjects::FillHistogram(const char* name, + int Xbins, double Xlow, double Xhigh, const char *Xvalue, + int Ybins, double Ylow, double Yhigh, double Yvalue, + double weight){ + GH2* hist = (GH2*) GetObjects().FindObject(name); + if(!hist){ + hist = new GH2D(name,name, + Xbins, Xlow, Xhigh, + Ybins, Ylow, Yhigh); + GetObjects().Add(hist); + } + if(Xvalue!=0 && !std::isnan(Yvalue)) { + hist->Fill(Xvalue, Yvalue, weight); + } + return hist; +} + TProfile* TRuntimeObjects::FillProfileHist(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, double Yvalue){ @@ -86,10 +116,10 @@ TProfile* TRuntimeObjects::FillProfileHist(const char* name, return prof; } -TH2* TRuntimeObjects::FillHistogramSym(const char* name, +GH2* TRuntimeObjects::FillHistogramSym(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue){ - TH2* hist = (TH2*) GetObjects().FindObject(name); + GH2* hist = (GH2*) GetObjects().FindObject(name); if(!hist){ hist = new GH2D(name,name, Xbins, Xlow, Xhigh, @@ -110,19 +140,17 @@ TH2* TRuntimeObjects::FillHistogramSym(const char* name, TDirectory* TRuntimeObjects::FillHistogram(const char* dirname,const char* name, int bins, double low, double high, double value, double weight){ - - TDirectory *dir = (TDirectory*)GetObjects().FindObject(dirname); if(!dir){ dir = new TDirectory(dirname,dirname); GetObjects().Add(dir); } dir->cd(); - TH1* hist = (TH1*)dir->FindObject(name); + GH1* hist = (GH1*)dir->FindObject(name); if(!hist){ hist = new GH1D(name,name, bins, low, high); - dir->Add(hist); + hist->SetDirectory(dir); // dir->Add(hist); } if(!std::isnan(value)) { @@ -132,35 +160,39 @@ TDirectory* TRuntimeObjects::FillHistogram(const char* dirname,const char* name, //return hist; return dir; - /* - std::cout << "1" << std::endl; - if(!(gDirectory->cd(dirname))){ - gDirectory->mkdir(dirname); - std::cout << "2" << std::endl; +} +TDirectory* TRuntimeObjects::FillHistogram(const char* dirname,const char* name, + int bins, double low, double high, const char *value, + double weight){ + TDirectory *dir = (TDirectory*)GetObjects().FindObject(dirname); + if(!dir){ + dir = new TDirectory(dirname,dirname); + GetObjects().Add(dir); } - std::cout << "3" << std::endl; - TDirectory *dir = gDirectory->GetDirectory(dirname); - //gDirectory->pwd() - std::cout << "4" << std::endl;; - TH1* hist = (TH1*)dir->FindObject(name); - std::cout << "4a" << std::endl; + dir->cd(); + GH1* hist = (GH1*)dir->FindObject(name); if(!hist){ - std::cout << "4b" << std::endl; - hist = new TH1I(name,name,bins,low,high); - // GetObjects().Add(hist); - std::cout << "5" << std::endl; - dir->Add(hist); - std::cout << "6" << std::endl; + hist = new GH1D(name,name, + bins, low, high); + hist->SetDirectory(dir); // dir->Add(hist); } - std::cout << "7" << std::endl; - hist->Fill(value); - std::cout << "8" << std::endl; - gDirectory->cd("../"); - std::cout << "9" << std::endl; + + if(value) { + hist->Fill(value, weight); + } + dir->cd("../"); + //return hist; return dir; - //return hist;*/ + } + + + + + + + TDirectory* TRuntimeObjects::FillHistogram(const char* dirname,const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue, @@ -171,29 +203,43 @@ TDirectory* TRuntimeObjects::FillHistogram(const char* dirname,const char* name, GetObjects().Add(dir); } dir->cd(); - TH2* hist = (TH2*)dir->FindObject(name); + GH2* hist = (GH2*)dir->FindObject(name); if(!hist){ hist = new GH2D(name,name, Xbins, Xlow, Xhigh, Ybins, Ylow, Yhigh); - dir->Add(hist); + hist->SetDirectory(dir); // dir->Add(hist); } if(!std::isnan(Xvalue) && !std::isnan(Yvalue)) { hist->Fill(Xvalue, Yvalue, weight); } dir->cd("../"); - //return hist; - return dir;/* - TH2* hist = (TH2*) GetObjects().FindObject(name); + return dir; +} +TDirectory* TRuntimeObjects::FillHistogram(const char* dirname,const char* name, + int Xbins, double Xlow, double Xhigh, const char *Xvalue, + int Ybins, double Ylow, double Yhigh, double Yvalue, + double weight){ + TDirectory *dir = (TDirectory*)GetObjects().FindObject(dirname); + if(!dir){ + dir = new TDirectory(dirname,dirname); + GetObjects().Add(dir); + } + dir->cd(); + GH2* hist = (GH2*)dir->FindObject(name); if(!hist){ - hist = new GH2D(name.c_str(),name.c_str(), + hist = new GH2D(name,name, Xbins, Xlow, Xhigh, Ybins, Ylow, Yhigh); - GetObjects().Add(hist); + hist->SetDirectory(dir); // dir->Add(hist); } - hist->Fill(Xvalue, Yvalue); - return hist;*/ + + if(Xvalue && !std::isnan(Yvalue)) { + hist->Fill(Xvalue, Yvalue, weight); + } + dir->cd("../"); + return dir; } @@ -230,12 +276,12 @@ TDirectory* TRuntimeObjects::FillHistogramSym(const char* dirname,const char* na GetObjects().Add(dir); } dir->cd(); - TH2* hist = (TH2*)dir->FindObject(name); + GH2* hist = (GH2*)dir->FindObject(name); if(!hist){ hist = new GH2D(name,name, Xbins, Xlow, Xhigh, Ybins, Ylow, Yhigh); - dir->Add(hist); + hist->SetDirectory(dir); // dir->Add(hist); } if(!(std::isnan(Xvalue))){ if(!(std::isnan(Yvalue))){ @@ -246,7 +292,7 @@ TDirectory* TRuntimeObjects::FillHistogramSym(const char* dirname,const char* na dir->cd("../"); //return hist; return dir;/* - TH2* hist = (TH2*) GetObjects().FindObject(name); + GH2* hist = (GH2*) GetObjects().FindObject(name); if(!hist){ hist = new GH2D(name.c_str(),name.c_str(), Xbins, Xlow, Xhigh, diff --git a/libraries/TKinematics/TKinematics.cxx b/libraries/TKinematics/TKinematics.cxx index c426e481..899abdd0 100644 --- a/libraries/TKinematics/TKinematics.cxx +++ b/libraries/TKinematics/TKinematics.cxx @@ -236,27 +236,79 @@ TGraph* TKinematics::Evslab_graph(double thmin, double thmax, double size, int p double rad2deg=180.0/PI; double deg2rad=PI/180.0; - int steps = ((int)(thmax+1) - (int)thmin) / (int)size; // when is size ever needed to be a double?? pcb. + int steps = ((int)(thmax+1) - (int)thmin) / 1.0; // when is size ever needed to be a double?? pcb. // i am under the impression that size should always be 1.0; - // + size = size/steps; //for(int i=0;i<((thmax-thmin)/size);i++){ + std::cout << "steps = " << steps << std::endl; for(int i=0;i (GetMaxAngle(fVcm[part])*rad2deg) -1) + //printf("step[%i] \t lab = %.02f \t tmpangle = %.02f \t tmpeng = %.02f\n",i, tmpangle,tmpeng); + if(tmpangle<1 || tmpangle > (GetMaxAngle(fVcm[part])*rad2deg) -1) { + std::cout << " angle fail?" << std::endl; continue; - if(tmpeng>1e15||tmpeng<0.0) + } + if(tmpeng>1e15||tmpeng<0.0) { + std::cout << " energy fail?" << std::endl; continue; - + } angle.push_back(GetThetalab(part)* (1/deg2rad)); energy.push_back(GetTlab(part) * 1000); + //std::cout << GetThetalab(part)* (1/deg2rad) << "\t" << GetTlab(part) * 1000 << std::endl; + } + + //TGraph *graph = new TGraph(angle.size(), angle.data(), energy.data()); + TGraph *graph = new TGraph(angle.size(), &(angle[0]), &(energy[0])); + //TSpline3* spline = new TSpline3("ETh_lab",&graph); + return graph; +} + + +TGraph* TKinematics::Evslab_graph_reverse(double thmin, double thmax, double size, int part){ + //double* energy = new double[(int)((thmax-thmin)/size)+1]; + //double* angle = new double[(int)((thmax-thmin)/size)+1]; + + if(part<2||part>3) { + printf(ALERTTEXT "WARNING: the function Evslab_graph should use nuclei after the reaction (part 2 or part 3)" RESET_COLOR "\n"); + return 0; } + std::vector energy; + std::vector angle; - TGraph *graph = new TGraph(angle.size(), angle.data(), energy.data()); + double rad2deg=180.0/PI; + double deg2rad=PI/180.0; + + int steps = ((int)(thmax+1) - (int)thmin) / 1.0; // when is size ever needed to be a double?? pcb. + // i am under the impression that size should always be 1.0; + size = size/steps; + //for(int i=0;i<((thmax-thmin)/size);i++){ + std::cout << "steps = " << steps << std::endl; + for(int i=0;i (GetMaxAngle(fVcm[part])*rad2deg) -1) { + std::cout << " angle fail?" << std::endl; + continue; + } + if(tmpeng>1e15||tmpeng<10.0) { + std::cout << " energy fail?" << std::endl; + continue; + } + angle.push_back(-1*(GetThetalab(part)* (1/deg2rad)) + 180); + energy.push_back(GetTlab(part) * 1000); + //std::cout << GetThetalab(part)* (1/deg2rad) << "\t" << GetTlab(part) * 1000 << std::endl; + } + + //TGraph *graph = new TGraph(angle.size(), angle.data(), energy.data()); + TGraph *graph = new TGraph(angle.size(), &(angle[0]), &(energy[0])); //TSpline3* spline = new TSpline3("ETh_lab",&graph); return graph; } @@ -270,6 +322,16 @@ TGraph* TKinematics::Evslab_graph(double thmin, double thmax, double size, int p + + + + + + + + + + TSpline3* TKinematics::Evscm(double thmin, double thmax, double size, int part){ double* energy = new double[(int)((thmax-thmin)/size)+1]; double* angle = new double[(int)((thmax-thmin)/size)+1]; diff --git a/libraries/TLoops/TBuildingLoop.cxx b/libraries/TLoops/TBuildingLoop.cxx index a851c534..00631405 100644 --- a/libraries/TLoops/TBuildingLoop.cxx +++ b/libraries/TLoops/TBuildingLoop.cxx @@ -70,6 +70,16 @@ bool TBuildingLoop::CheckBuildWindow(TRawEvent *event) { if(timestamp == -1){ return false; } + + ////////////////////////// + ////// DDAS offset hack // + // if(event->GetEventType()==0x19) { + // timestamp += 50000.; + // } + ////////////////////////// + + + //std::cout << "Build window: " << build_window << std::endl; if(timestamp > event_start + build_window || timestamp < event_start - build_window) { diff --git a/libraries/TLoops/TDataLoop.cxx b/libraries/TLoops/TDataLoop.cxx index f638f70b..11a1a092 100644 --- a/libraries/TLoops/TDataLoop.cxx +++ b/libraries/TLoops/TDataLoop.cxx @@ -59,6 +59,11 @@ bool TDataLoop::Iteration() { bytes_read = source->Read(evt); } + // static int evtnum = 0; + // std::cout << "Evtnum: " << evtnum++ << std::endl; + // std::cout << "Bytes read: " << bytes_read << std::endl; + // evt.Print(); + if(bytes_read < 0 && fSelfStopping){ // Error, and no point in trying again. printf("finished sorting all input.\n"); diff --git a/libraries/TLoops/TUnpackedEvent.cxx b/libraries/TLoops/TUnpackedEvent.cxx index 5c96fc17..e2f3462d 100644 --- a/libraries/TLoops/TUnpackedEvent.cxx +++ b/libraries/TLoops/TUnpackedEvent.cxx @@ -2,7 +2,7 @@ #include "TClass.h" -#include "TBank29.h" +#include "TBank88.h" #include "TCaesar.h" #include "TGretina.h" #include "TGretSim.h" @@ -15,6 +15,10 @@ #include "TS800Scaler.h" #include "TSega.h" #include "TFastScint.h" +#include "TLenda.h" +#include "TFSU.h" +#include "TUML.h" +#include "TOBJ.h" TUnpackedEvent::TUnpackedEvent() { } @@ -54,8 +58,8 @@ void TUnpackedEvent::Build() { GetDetector(true)->Build(raw_data); break; - case kDetectorSystems::BANK29: - GetDetector(true)->Build(raw_data); + case kDetectorSystems::BANK88: + GetDetector(true)->Build(raw_data); break; case kDetectorSystems::SEGA: @@ -81,6 +85,21 @@ void TUnpackedEvent::Build() { case kDetectorSystems::NSCLSCALERS: GetDetector(true)->Build(raw_data); break; + + case kDetectorSystems::LENDA: + GetDetector(true)->Build(raw_data); + break; + + case kDetectorSystems::UML: + GetDetector(true)->Build(raw_data); + break; + + case kDetectorSystems::OBJ: + GetDetector(true)->Build(raw_data); + break; + + case kDetectorSystems::FSU: + GetDetector(true)->Build(raw_data); default: break; @@ -101,3 +120,19 @@ void TUnpackedEvent::SetRunStart(unsigned int unix_time){ det->SetRunStart(unix_time); } } + + +TDetector* TUnpackedEvent::GetDetector(std::string detname) const { + for(auto det : detectors) { + if(detname.compare(det->IsA()->GetName())==0) { + TDetector* output = det; + if(output){ + return output; + } + } + } + return NULL; +} + + + diff --git a/libraries/TLoops/TUnpackingLoop.cxx b/libraries/TLoops/TUnpackingLoop.cxx index 648aae78..56cd273b 100644 --- a/libraries/TLoops/TUnpackingLoop.cxx +++ b/libraries/TLoops/TUnpackingLoop.cxx @@ -115,7 +115,7 @@ void TUnpackingLoop::HandleNSCLData(TNSCLEvent& event) { case kNSCLEventType::RING_FORMAT: // 0x000C case kNSCLEventType::PHYSICS_EVENT_COUNT: // 0x001F case kNSCLEventType::EVB_FRAGMENT: // 0x0028 - case kNSCLEventType::EVB_UNKNOWN_PAYLOAD: // 0x0029 + case kNSCLEventType::EVB_UNKNOWN_PAYLOAD: // 0x0088 case kNSCLEventType::EVB_GLOM_INFO: // 0x002A case kNSCLEventType::FIRST_USER_ITEM_CODE: // 0x8000 break; @@ -192,7 +192,7 @@ void TUnpackingLoop::HandleGEBData(TGEBEvent& event){ fOutputEvent->AddRawData(event, kDetectorSystems::S800); break; case 8: // Gretina diag. data. - HandleGEBMode3(event, kDetectorSystems::BANK29); + HandleGEBMode3(event, kDetectorSystems::BANK88); break; case 9: //Simulated S800 data, @@ -212,8 +212,18 @@ void TUnpackingLoop::HandleGEBData(TGEBEvent& event){ case 17: //PWall Mode2 equivlant. fOutputEvent->AddRawData(event, kDetectorSystems::PHOSWALL); break; - case 29: // Something. - fOutputEvent->AddRawData(event, kDetectorSystems::BANK29); + case 21: //lenda + fOutputEvent->AddRawData(event, kDetectorSystems::LENDA); + break; + case 22: //fastscint (?) + fOutputEvent->AddRawData(event, kDetectorSystems::FASTSCINT); + break; + case 25: //uml +// fOutputEvent->AddRawData(event, kDetectorSystems::UML); + fOutputEvent->AddRawData(event, kDetectorSystems::OBJ); + break; + case 88: // Something. + fOutputEvent->AddRawData(event, kDetectorSystems::BANK88); break; default: std::cout << "Dance Party EventType: " << type << std::endl; diff --git a/libraries/TLoops/TWriteLoop.cxx b/libraries/TLoops/TWriteLoop.cxx index 3a94735d..94e9b9b8 100644 --- a/libraries/TLoops/TWriteLoop.cxx +++ b/libraries/TLoops/TWriteLoop.cxx @@ -5,11 +5,11 @@ #include "TFile.h" #include "TThread.h" +#include "TString.h" #include "GValue.h" #include "TChannel.h" #include "THistogramLoop.h" -#include "TS800.h" TWriteLoop* TWriteLoop::Get(std::string name, std::string output_filename){ if(name.length()==0){ @@ -122,7 +122,9 @@ void TWriteLoop::AddBranch(TClass* cls){ det_map[cls] = det_pp; // Make a new branch. - TBranch* new_branch = event_tree->Branch(cls->GetName(), cls->GetName(), det_pp); + TString cls_name = cls->GetName(); + cls_name = cls_name; // + '.'; + TBranch* new_branch = event_tree->Branch(cls_name.Data(), cls->GetName(), det_pp); // Fill the new branch up to the point where the tree is filled. // Explanation: diff --git a/libraries/TNSCLFormat/TNSCLEvent.cxx b/libraries/TNSCLFormat/TNSCLEvent.cxx index 2b36c6d8..a4ede833 100644 --- a/libraries/TNSCLFormat/TNSCLEvent.cxx +++ b/libraries/TNSCLFormat/TNSCLEvent.cxx @@ -1,4 +1,5 @@ #include "TNSCLEvent.h" +#include "TGRUTOptions.h" #include @@ -23,6 +24,11 @@ Int_t TNSCLEvent::GetBodyHeaderSize() const { long TNSCLEvent::GetTimestamp() const { if(GetBodyHeaderSize() > 4) { + if(TGRUTOptions::Get()->UseFSU()) { + Long_t tl = *((Int_t*)(GetBody()+8)); + Long_t th = *((Int_t*)(GetBody()+12)); + return ((th<<32) + tl); + } return *((Long_t*)(GetBody()+4)); } else { return -1; diff --git a/libraries/TNucleus/TNucleus.cxx b/libraries/TNucleus/TNucleus.cxx index 5e532a27..9595e223 100644 --- a/libraries/TNucleus/TNucleus.cxx +++ b/libraries/TNucleus/TNucleus.cxx @@ -11,6 +11,7 @@ #include #include "ProgramPath.h" +#include "TGRUTUtilities.h" //#define debug @@ -442,7 +443,7 @@ void TNucleus::Print(Option_t *opt) const{ int counter =0; while(TTransition *tran = (TTransition*)next()) { printf("\t%i\t",counter++); - tran->Print(); + tran->Print(); } } @@ -468,7 +469,7 @@ bool TNucleus::LoadTransitionFile(){ filename = std::string(getenv("GRUTSYS")) + "/libraries/SourceData/"; std::string symbol = this->GetSymbol(); std::transform(symbol.begin(), symbol.end(), symbol.begin(), ::tolower); - filename.append(symbol.c_str()); + filename.append(symbol.c_str()); filename.append(std::to_string(this->GetA())); filename.append(".sou"); @@ -479,11 +480,15 @@ bool TNucleus::LoadTransitionFile(){ return false; } //printf("found %s\n",filename.c_str()); - + std::string line; - + while(getline(transfile,line)) { + trim(line); + //printf("%i\t%s\n",counter++,line.c_str()); + if(!line.length()) + continue; if(!line.compare(0,2,"//")) continue; if(!line.compare(0,1,"#")) @@ -508,7 +513,7 @@ bool TNucleus::LoadTransitionFile(){ } AddTransition(tran); } - + return true; } diff --git a/libraries/TRawFormat/TOrderedRawFile.cxx b/libraries/TRawFormat/TOrderedRawFile.cxx index 46ced2e0..3a1e2352 100644 --- a/libraries/TRawFormat/TOrderedRawFile.cxx +++ b/libraries/TRawFormat/TOrderedRawFile.cxx @@ -30,7 +30,8 @@ int TOrderedRawFile::GetEvent(TRawEvent& event) { } if(oldest_timestamp != -1 && newest_timestamp != -1 && - curr_timestamp < newest_timestamp){ + curr_timestamp < newest_timestamp && + !TGRUTOptions::Get()->SuppressErrors()){ std::cerr << "Sorting failed, insufficient depth " << "(" << curr_timestamp << " < " << newest_timestamp << std::endl; } diff --git a/libraries/TRawFormat/TRawBanks.cxx b/libraries/TRawFormat/TRawBanks.cxx index ee8f9d00..234913ec 100644 --- a/libraries/TRawFormat/TRawBanks.cxx +++ b/libraries/TRawFormat/TRawBanks.cxx @@ -35,6 +35,7 @@ std::ostream& operator<<(std::ostream& os, const TRawEvent::GEBBankType1 &bank) os << "bl poststep = "<< std::setw(8) << bank.poststep << std::endl; os << std::setprecision(ss); os << "pad (error) = "<< std::setw(8) << bank.pad << std::endl; + //for(int x=0;x<16;x++) for(int x=0;x #include +#include +#include #include "TGEBEvent.h" #include "TNSCLEvent.h" @@ -73,7 +75,22 @@ void TRawFileOut::swap(TRawFileOut& other) { } void TRawFileOut::Write(TRawEvent& event) { - WriteBytes((char*)event.GetRawHeader(), sizeof(TRawEvent::RawHeader)); + // static bool kill_next = false; + + // if(kill_next) { + // event.Print("all"); + // } + + if(IsGEBData(event)) { + TRawEvent::RawHeader header; + header.datum1 = event.GetEventType(); + header.datum2 = event.GetPayloadBuffer().GetSize(); + WriteBytes((char*)&header, sizeof(TRawEvent::RawHeader)); + } else { + WriteBytes((char*)event.GetRawHeader(), sizeof(TRawEvent::RawHeader)); + } + + TSmartBuffer buf; if(IsGEBData(event)) { @@ -86,6 +103,15 @@ void TRawFileOut::Write(TRawEvent& event) { buf = event.GetBuffer(); } WriteBytes(buf.GetData(), buf.GetSize()); + + // if(kill_next) { + // exit(5); + // } + // if(event.GetEventType()==8) { + // std::cout << "I haz a card29" << std::endl; + // event.Print("all"); + // kill_next = true; + // } } void TRawFileOut::Write(TUnpackedEvent& event) { @@ -163,9 +189,14 @@ void TRawFileOut::WriteBuiltNSCLEvent(TUnpackedEvent& event) { } void TRawFileOut::WriteBytes(const char* data, size_t size) { + size_t bytes_written = 0; if(raw_file_out) { - fwrite(data, sizeof(char), size, raw_file_out); + bytes_written = fwrite(data, sizeof(char), size, raw_file_out); } else if(gzip_file_out) { - gzwrite(*gzip_file_out, data, size); + bytes_written = gzwrite(*gzip_file_out, data, size); + } + if(bytes_written != size) { + std::cout << "Incorrect amount written: " << bytes_written << " instead of " << size << std::endl; } + assert(bytes_written == size); } diff --git a/makefile b/makefile index f135292e..52fe1fa7 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,6 @@ .SECONDEXPANSION: -PLATFORM:=$(PLATFORM) # EDIT THIS SECTION INCLUDES = include @@ -16,12 +15,15 @@ SRC_SUFFIX = cxx USING_ROOT_6 = $(shell expr $(shell root-config --version | cut -f1 -d.) \>= 6) +PLATFORM:=$(shell uname) +$(info PLATFORM: $(PLATFORM)) + ifeq ($(PLATFORM),Darwin) export __APPLE__:= 1 CFLAGS += -DOS_DARWIN -DHAVE_ZLIB CFLAGS += -I/opt/X11/include -Qunused-arguments CPP = clang++ -SHAREDSWITCH = -install_name # ENDING SPACE +SHAREDSWITCH = -undefined dynamic_lookup -dynamiclib -install_name # ENDING SPACE else export __LINUX__:= 1 CPP = g++ @@ -46,16 +48,17 @@ BLD_STRING= "Building\ " COPY_STRING="Copying\ \ " FIN_STRING="Finished Building" -LIBRARY_DIRS := $(shell find libraries -type d -links 2 2> /dev/null) +LIBRARY_DIRS := $(shell find libraries -type d -exec sh -c "if ! find {} ! -path {} -type d | grep -qe '.*'; then echo {}; fi" \; 2> /dev/null) LIBRARY_NAMES := $(notdir $(LIBRARY_DIRS)) LIBRARY_OUTPUT := $(patsubst %,lib/lib%.so,$(LIBRARY_NAMES)) INCLUDES := $(addprefix -I$(PWD)/,$(INCLUDES)) CFLAGS += $(shell root-config --cflags) CFLAGS += -MMD -MP $(INCLUDES) +CFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 LINKFLAGS += -Llib $(addprefix -l,$(LIBRARY_NAMES)) -Wl,-rpath,\$$ORIGIN/../lib -LINKFLAGS += $(shell root-config --glibs) -lSpectrum -lPyROOT -lMinuit -LINKFLAGS := $(LINKFLAGS_PREFIX) $(LINKFLAGS) $(LINKFLAGS_SUFFIX) $(CFLAGS) +LINKFLAGS += $(shell root-config --glibs) -lSpectrum -lPyROOT -lMinuit -lMathMore +LINKFLAGS := $(LINKFLAGS_PREFIX) $(LINKFLAGS) $(LINKFLAGS_SUFFIX) ROOT_LIBFLAGS := $(shell root-config --cflags) @@ -68,7 +71,7 @@ HISTOGRAM_SO := $(patsubst histos/%.$(SRC_SUFFIX),lib/lib%.so,$(wildcard hist FILTER_SO := $(patsubst filters/%.$(SRC_SUFFIX),lib/lib%.so,$(wildcard filters/*.$(SRC_SUFFIX))) ifdef VERBOSE -run_and_test = @echo $(1) && $(1); +run_and_test = @echo "$(1)" && $(1); else run_and_test =@printf "%b%b%b" " $(3)$(4)$(5)" $(notdir $(2)) "$(NO_COLOR)\r"; \ $(1) 2> $(2).log || touch $(2).error; \ @@ -86,8 +89,9 @@ run_and_test =@printf "%b%b%b" " $(3)$(4)$(5)" $(notdir $(2)) "$(NO_COLOR)\r"; rm -f $(2).log $(2).error endif -all: include/GVersion.h $(EXECUTABLES) $(LIBRARY_OUTPUT) pcm_files bin/grutinizer-config bin/gadd_fast.py\ - $(HISTOGRAM_SO) $(FILTER_SO) extras +all: include/GVersion.h $(EXECUTABLES) $(LIBRARY_OUTPUT) pcm_files \ + bin/grutinizer-config \ + $(HISTOGRAM_SO) $(FILTER_SO) extras lib/libAllGrutinizer.so @printf "$(OK_COLOR)Compilation successful, $(WARN_COLOR)woohoo!$(NO_COLOR)\n" pcm_files: @@ -98,6 +102,10 @@ docs: bin/%: util/% | bin @ln -sf ../$< $@ +.build/util/gadd.o: $(ROOTSYS)/main/src/hadd.cxx + @mkdir -p $(dir $@) + $(call run_and_test,sed s/hadd/gadd/g < $< | $(CPP) -x c++ -fPIC -c -o $@ $(CFLAGS) -,$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) ) + bin/grutinizer: $(MAIN_O_FILES) | $(LIBRARY_OUTPUT) pcm_files bin $(call run_and_test,$(CPP) $^ -o $@ $(LINKFLAGS),$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) ) @@ -110,6 +118,9 @@ bin lib: include/GVersion.h: .git/HEAD .git/index util/gen_version.sh $(call run_and_test,util/gen_version.sh,$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) ) +lib/libAllGrutinizer.so: $(LIBRARY_OUTPUT) + $(call run_and_test,echo | $(CPP) -x c++ - -fPIC -o $@ $(SHAREDSWITCH)$(notdir $@) $(LINKFLAGS),$@,$(BLD_COLOR),$(BLD_STRING),$(OBJ_COLOR) ) + lib/lib%.so: .build/histos/%.o | lib $(call run_and_test,$(CPP) -fPIC $^ $(SHAREDSWITCH)lib$*.so $(ROOT_LIBFLAGS) -o $@,$@,$(BLD_COLOR),$(BLD_STRING),$(OBJ_COLOR) ) @@ -121,7 +132,7 @@ lib/lib%.so: .build/filters/%.o | lib # If a LinkDef.h file is present in the library directory, # a dictionary file will also be generated and added to the library. libdir = $(shell find libraries -name $(1) -type d) -lib_src_files = $(shell find $(call libdir,$(1)) -name "*.$(SRC_SUFFIX)") +lib_src_files = $(if $(call libdir,$(1)), $(shell find $(call libdir,$(1)) -name "*.$(SRC_SUFFIX)"), nonexisting-file.cxx) lib_o_files = $(patsubst %.$(SRC_SUFFIX),.build/%.o,$(call lib_src_files,$(1))) lib_linkdef = $(wildcard $(call libdir,$(1))/LinkDef.h) lib_dictionary = $(patsubst %/LinkDef.h,.build/%/LibDictionary.o,$(call lib_linkdef,$(1))) @@ -137,7 +148,7 @@ lib/lib%.so: $$(call lib_o_files,%) $$(call lib_dictionary,%) | lib @mkdir -p $(dir $@) $(call run_and_test,$(CPP) -fPIC -c $< -o $@ $(CFLAGS),$@,$(COM_COLOR),$(COM_STRING),$(OBJ_COLOR) ) -dict_header_files = $(addprefix $(PWD)/include/,$(subst //,,$(shell head $(1) -n 1 2> /dev/null))) +dict_header_files = $(addprefix $(PWD)/include/,$(subst //,,$(shell head -n 1 $(1) 2> /dev/null))) find_linkdef = $(shell find $(1) -name "*LinkDef.h") # In order for all function names to be unique, rootcint requires unique output names. diff --git a/pygui/AnsiColorText.py b/pygui/AnsiColorText.py index f1855f84..79184439 100644 --- a/pygui/AnsiColorText.py +++ b/pygui/AnsiColorText.py @@ -1,6 +1,6 @@ # author: stefaan.himpe@gmail.com # license: MIT -from Tkinter import Text, END +from tkinter import Text, END import re class AnsiColorText(Text): diff --git a/pygui/grut-view.py b/pygui/grut-view.py index 1ab06d14..f6cba667 100755 --- a/pygui/grut-view.py +++ b/pygui/grut-view.py @@ -3,7 +3,7 @@ import sys import warnings import threading -import Tkinter as tk +import tkinter as tk import time import ROOT @@ -29,7 +29,7 @@ def update(): except tk.TclError: pass except Exception as e: - print e + print(e) def on_close(): global window diff --git a/pygui/hist_tab.py b/pygui/hist_tab.py index 80b1244a..21de3b4b 100755 --- a/pygui/hist_tab.py +++ b/pygui/hist_tab.py @@ -1,8 +1,8 @@ #!/usr/bin/env python2 import itertools -import Tkinter as tk -import ttk +import tkinter as tk +from tkinter import ttk import ROOT ROOT.PyConfig.IgnoreCommandLineOptions = True @@ -30,7 +30,8 @@ def _MakeHistView(self,parent): # Map from treeview name to ROOT object self.hist_lookup = TKeyDict() self.treeview.bind("", self.OnHistClick) - + self.treeview.bind("", self.OnHistButton) + scrollbar = ttk.Scrollbar(parent) scrollbar.pack(side=tk.LEFT,fill=tk.Y) self.treeview.configure(yscrollcommand=scrollbar.set) @@ -48,7 +49,7 @@ def OnHistClick(self,event): color = 1; for name,obj in sorted(histograms.items()): - if isinstance(obj, ROOT.GH2Base): + if isinstance(obj, ROOT.GH2): self._refresh(name, obj) self.main._draw_single(obj,color,len(histograms)) @@ -59,18 +60,23 @@ def OnHistClick(self,event): update_tcanvases() + def OnHistButton(self,event): + self.OnHistClick(event) + self.main.window.lift() + + def _dump_to_tfile(self): for key in self.hist_lookup: self.hist_lookup[key].Write() def _load_compiled_histograms(self, filename): - print 'load compiled histograms called.' + print('load compiled histograms called.') #pipeline = ROOT.GetPipeline(0) #if outfile: # pipeline.SetHistogramLibrary(filename) def _compiled_histogram_filename(self): - print ' _compiled_histogram_filename called.\n' + print(' _compiled_histogram_filename called.\n') #pipeline = ROOT.GetPipeline(0) #if pipeline: # return pipeline.GetLibraryName() @@ -126,9 +132,9 @@ def Insert(self,obj,parent='',objname=None,icon=None): iterable = obj.GetListOfKeys() if not iterable: iterable = obj.GetList() - elif isinstance(obj, ROOT.GH2Base): - iterable = itertools.chain(obj.GetProjections(), - obj.GetSummaryProjections()) + elif isinstance(obj, ROOT.GH2): + iterable = itertools.chain(obj.GetProjections()) + #,obj.GetSummaryProjections()) else: iterable = None diff --git a/pygui/mainwindow.py b/pygui/mainwindow.py index 0b057c40..b760edab 100755 --- a/pygui/mainwindow.py +++ b/pygui/mainwindow.py @@ -1,11 +1,11 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import ast import os import pprint -import Tkinter as tk -import tkFileDialog -import ttk +import tkinter.filedialog +import tkinter as tk +from tkinter import ttk import sys @@ -30,6 +30,8 @@ def __init__(self): self.files = {} self._setup_GUI() + self._setup_keybindings() + def LoadGuiFile(self, filename): with open(filename) as f: @@ -45,7 +47,7 @@ def LoadGuiFile(self, filename): def _save_gui_file(self, filename = None): if filename is None: - filename = tkFileDialog.asksaveasfilename(filetypes=(("GUI File", "*.hist"),)) + filename = tkinter.filedialog.asksaveasfilename(filetypes=(("GUI File", "*.hist"),)) if not filename: return @@ -66,7 +68,7 @@ def _save_gui_file(self, filename = None): def _dump_root_file(self, filename = None, include_histograms = True): if filename is None: - filename = tkFileDialog.asksaveasfilename(filetypes=(("ROOT File", "*.root"),)) + filename = tkinter.filedialog.asksaveasfilename(filetypes=(("ROOT File", "*.root"),)) if not filename: return @@ -190,6 +192,24 @@ def _setup_GUI(self): status = ThreadStatusFrame(self.window) status.pack() + def _setup_keybindings(self): + #self.window.bind("",self.close_all_canvases) + #self.window.bind("",self._keybindings) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + self.window.bind("",self._handleKeyPad) + def _setup_status_bar(self, parent): frame = tk.Frame(parent, height=60) @@ -285,6 +305,8 @@ def _PickIcon(self, obj): if cls.InheritsFrom(ROOT.TH2.Class()): return self.icons['h2_t'] + elif cls.InheritsFrom(ROOT.GH2.Class()): + return self.icons['h2_t'] elif cls.InheritsFrom(ROOT.TH1.Class()): return self.icons['h1_t'] elif cls.InheritsFrom(ROOT.TFile.Class()): @@ -348,12 +370,16 @@ def _MakeZoneMenu(self, menubar): variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="1 x 3",onvalue='1x3', variable=self.predefinedzones,command=self.set_zones) + zonesmenu.add_checkbutton(label="1 x 4",onvalue='1x4', + variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="2 x 1",onvalue='2x1', variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="2 x 2",onvalue='2x2', variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="2 x 3",onvalue='2x3', variable=self.predefinedzones,command=self.set_zones) + zonesmenu.add_checkbutton(label="2 x 4",onvalue='2x4', + variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="2 x 5",onvalue='2x5', variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="3 x 1",onvalue='3x1', @@ -362,14 +388,24 @@ def _MakeZoneMenu(self, menubar): variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="3 x 3",onvalue='3x3', variable=self.predefinedzones,command=self.set_zones) + zonesmenu.add_checkbutton(label="3 x 4",onvalue='3x4', + variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="4 x 4",onvalue='4x4', variable=self.predefinedzones,command=self.set_zones) + zonesmenu.add_checkbutton(label="4 x 3",onvalue='4x3', + variable=self.predefinedzones,command=self.set_zones) + zonesmenu.add_checkbutton(label="4 x 2",onvalue='4x2', + variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="5 x 2",onvalue='5x2', variable=self.predefinedzones,command=self.set_zones) + zonesmenu.add_checkbutton(label="6 x 4",onvalue='6x4', + variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="8 x 3",onvalue='8x3', variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="8 x 4",onvalue='8x4', variable=self.predefinedzones,command=self.set_zones) + zonesmenu.add_checkbutton(label="8 x 6",onvalue='8x6', + variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="9 x 4",onvalue='9x4', variable=self.predefinedzones,command=self.set_zones) zonesmenu.add_checkbutton(label="12 x 12",onvalue='12x12', @@ -384,7 +420,7 @@ def set_zones(self): zones = map(int,zones_str.split("x")) self.zone_cols,self.zone_rows = zones except (IndexError,ValueError): - print 'Cannot set zones to "{}"'.format(zones_str) + print('Cannot set zones to "{}"'.format(zones_str)) def _MakeOptStatMenu(self, menubar): self.optstat_name = tk.BooleanVar(value=True) @@ -519,14 +555,14 @@ def LoadCutFile(self, cutfile): # ("Cuts File", "*.root"))) #if not filename: # return - + #filename = os.path.abspath(filename) - #tfile = ROOT.TFile(filename); + #tfile = ROOT.TFile(filename); self.tcut_tab.AddFile(cutfile) def LoadDataFile(self, filename = None): if filename is None: - filename = tkFileDialog.askopenfilename(filetypes=(("NSCL Evt", "*.evt"), + filename = tkinter.filedialog.askopenfilename(filetypes=(("NSCL Evt", "*.evt"), ("GEB File", "*.dat"), ("GZip File", "*.gz"))) @@ -538,7 +574,7 @@ def LoadDataFile(self, filename = None): def LoadRootFile(self,filename=None): #print "In py LoadRooFile " + filename if filename is None: - filename = tkFileDialog.askopenfilename(filetypes=(("ROOT File", "*.root"),)) + filename = tkinter.filedialog.askopenfilename(filetypes=(("ROOT File", "*.root"),)) if not filename: return @@ -551,11 +587,11 @@ def LoadRootFile(self,filename=None): self.tcut_tab.AddFile(tfile) self.variable_tab.AddFile(tfile) else: - print 'MainWindow.LoadRootFile: Could not open {}'.format(filename) + print('MainWindow.LoadRootFile: Could not open {}'.format(filename)) def LoadWindowFile(self,filename=None): if filename is None: - filename = tkFileDialog.askopenfilename(filetypes=(("Window File","*.win"),)) + filename = tkinter.filedialog.askopenfilename(filetypes=(("Window File","*.win"),)) if not filename: return @@ -580,7 +616,7 @@ def load_library(self, library_name, grut_lib = True): def Snapshot(self): ROOT.GSnapshot.Get().Snapshot() - def close_all_canvases(self): + def close_all_canvases(self,event=0): canvases = ROOT.gROOT.GetListOfCanvases() for canvas in canvases: canvas.Close() @@ -595,7 +631,8 @@ def open_canvas(self,title="",columns=-1,rows=-1,topx=0,topy=0,width=0,height=0) if width*height == 0: array = self.get_canvas_size() - array = map(int,array) + #array = map(int,array) + array = list(map(int,array)) canvas = ROOT.GCanvas(title,title,0,0,array[0],array[1],True) else: canvas = ROOT.GCanvas(title,title,topx,topy,width,height,True) @@ -613,3 +650,47 @@ def open_canvas(self,title="",columns=-1,rows=-1,topx=0,topy=0,width=0,height=0) #ROOT.PyGUIThread.join(0.1) self.canvases.append(canvas) + + + def _handleKeyPad(self,event): + canvas_sizes = dict(KP_1=(1,1), + KP_2=(2,1), + KP_3=(3,1), + KP_4=(1,2), + KP_5=(2,2), + KP_6=(3,2), + KP_7=(1,3), + KP_8=(2,3), + KP_9=(3,3)) + if event.keysym in canvas_sizes: + x,y = canvas_sizes[event.keysym] + self.open_canvas('',x,y) + + canvas_mod = dict(KP_Add=+1, + KP_Enter=-1) + if event.keysym in canvas_mod: + shift = canvas_mod[event.keysym] + if ROOT.gPad: + padnum = ROOT.gPad.GetNumber() + canvas = ROOT.gPad.GetCanvas() + + if padnum+shift == 0: + # Ugly way to find the maximum pad + target_num = 1 + while True: + if not canvas.GetPad(target_num+1): + break + target_num += 1 + elif canvas.GetPad(padnum+shift): + target_num = padnum+shift + else: + target_num = 1 + + canvas.cd(target_num) + + ROOT.gPad.Modified() + ROOT.gPad.Update() + + + + self.window.lift() diff --git a/pygui/status_widget.py b/pygui/status_widget.py index 8f8aaaae..f69bea38 100755 --- a/pygui/status_widget.py +++ b/pygui/status_widget.py @@ -1,8 +1,8 @@ #!/usr/bin/env python2 from collections import namedtuple -import Tkinter as tk -import ttk +import tkinter as tk +from tkinter import ttk import ROOT ROOT.PyConfig.IgnoreCommandLineOptions = True diff --git a/pygui/tcut_tab.py b/pygui/tcut_tab.py index 5d4ee106..1cfa3568 100755 --- a/pygui/tcut_tab.py +++ b/pygui/tcut_tab.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 -import Tkinter as tk -import ttk +import tkinter as tk +from tkinter import ttk import re import ROOT @@ -11,209 +11,204 @@ class TCutTab(object): - def __init__(self, main, frame): - self.main = main - self._setup_GUI(frame) + def __init__(self, main, frame): + self.main = main + self._setup_GUI(frame) - self.cuts = {} - self.detector_classes = {} + self.cuts = {} + self.detector_classes = {} - #frame.after_idle(self._repeatedly_check) + #frame.after_idle(self._repeatedly_check) - def _setup_GUI(self, frame): - self.frame = frame - self._MakeNaming(frame) - self._MakeTreeView(frame) + def _setup_GUI(self, frame): + self.frame = frame + self._MakeNaming(frame) + self._MakeTreeView(frame) - def _repeatedly_check(self): - self._check_for_tcut() - self.frame.after(1000,self._repeatedly_check) + def _repeatedly_check(self): + self._check_for_tcut() + self.frame.after(1000,self._repeatedly_check) - def _dump_to_tfile(self): - for cut in self.cuts.values(): - cut.Write() + def _dump_to_tfile(self): + for cut in self.cuts.values(): + cut.Write() - def _tcut_patterns(self): + def _tcut_patterns(self): output = [] for name, cut in self.cuts.items(): - points = [] - for i in xrange(cut.GetN()): - points.append((cut.GetX()[i], cut.GetY()[i])) + points = [] + for i in xrange(cut.GetN()): + points.append((cut.GetX()[i], cut.GetY()[i])) pattern = {'name':name, - 'points':points, - 'varx':cut.GetVarX(), - 'vary':cut.GetVarY(), - } - output.append(pattern) - return output - - def _load_tcut_patterns(self, patterns): - for pattern in patterns: - cut = ROOT.TCutG(pattern['name'],len(pattern['points'])) - cut.SetVarX(pattern['varx']) - cut.SetVarY(pattern['vary']) - for i,(x,y) in enumerate(pattern['points']): - cut.SetPoint(i, x, y) - self.AddCut(cut) - - def _check_for_tcut(self): - # Does CUTG exist? - cutg = ROOT.gROOT.GetListOfSpecials().FindObject('CUTG') - if not cutg: - return None - - # Does it have 3 or more points? - npoints = cutg.GetN() - if npoints < 3: - return None - - # Is the first point equal to the last point? - xi = cutg.GetX()[0] - yi = cutg.GetY()[0] - xf = cutg.GetX()[npoints-1] - yf = cutg.GetY()[npoints-1] - if xi!=xf or yi!=yf: - return None - - return cutg - - def AddDirectory(self, tdir): - gchain = ROOT.gChain - # If the chain doesn't exist, or if it is empty. - if not gchain or gchain.GetEntries()==0: - return - - for branch in gchain.GetListOfBranches(): - cls_name = branch.GetName() - cls = getattr(ROOT, cls_name) - if cls_name not in self.detector_classes: - top = self.tree.insert('','end', - cls_name, text=cls_name) - self.tree.insert(top,'end', - '{}/Draw PID'.format(cls_name), - text='Draw PID') - self.detector_classes[cls_name] = cls - - def AddFile(self, tfile): - for key in tfile.GetListOfKeys(): - #print key.GetName() - if key.GetClassName()=='TCutG': - obj = key.ReadObj() - #print obj.GetName() - self.AddCut(obj) #key.ReadObj()) - if key.GetClassName()=='GCutG': - obj = key.ReadObj() - #print obj.GetName() - self.AddCut(obj) #key.ReadObj()) - - def AddCut(self, cut, det_type = None): - name = cut.GetName() - full_name = '{}/{}'.format(det_type,name) if det_type is not None else name - cut.SetLineColor(ROOT.kRed) - cut.SetLineWidth(3) - self.cuts[full_name] = cut - - if det_type is None: - parent = '' - else: - parent = det_type - self.detector_classes[det_type].AddGate(cut) - - self.tree.insert(parent, 'end', full_name, text=name, values='2D Cut', - image = self.main.icons['tcutg']) - - if ROOT.gPad: - ROOT.gPad.Modified() - ROOT.gPad.Update() - - def StartCut(self): - ROOT.gROOT.SetEditorMode('CutG') - - def SaveCut(self): - cutg = self._check_for_tcut() - if cutg is None: - return - - ROOT.gROOT.GetListOfSpecials().Remove(cutg) - - cutg.SetName(self._increment_name()) - for prim in ROOT.gPad.GetListOfPrimitives(): - if isinstance(prim, ROOT.TH2): - title = prim.GetName() - det_type = title[:title.index('_')] - break - else: - det_type = None - - self.AddCut(cutg, det_type) - - def DeleteCut(self): - cutg = self._check_for_tcut() - if(cutg is None): - return - - cutg.Delete() - - def CopyCut(self): - cuts = self.tree.selection() - if not cuts: - return - cutname = cuts[0] - tcutg = self.cuts[cutname] - newcut = tcutg.Clone(self._increment_name()) - - xmin = min(newcut.GetX()[i] for i in range(newcut.GetN())) - xmax = max(newcut.GetX()[i] for i in range(newcut.GetN())) - xshift = 0.5*(xmax-xmin) - for i in range(newcut.GetN()): - newcut.GetX()[i] += xshift - - - newcut.Draw('same') - self.AddCut(newcut) - - - def _increment_name(self): - name = self.next_name.get() - self.next_name.set(increment_name(name)) - return name - - def _MakeNaming(self, parent): - self.next_name = tk.StringVar(value='tcutg_0') - frame = tk.Frame(parent) - tk.Label(frame, text='Name:').pack(side=tk.LEFT) - tk.Entry(frame, textvariable=self.next_name).pack(side=tk.LEFT) - frame.pack(fill=tk.X,expand=False) - - frame = tk.Frame(parent) - tk.Button(frame, text='Make Gate', fg="black",bg="light goldenrod", command=self.StartCut).pack(side=tk.LEFT) - tk.Button(frame, text='Save Gate', fg="black",bg="light goldenrod", command=self.SaveCut).pack(side=tk.LEFT) - tk.Button(frame, text='Copy Gate',fg="black",bg="light goldenrod", command=self.CopyCut).pack(side=tk.LEFT) - tk.Button(frame, text='Delete Gate',fg="black",bg="firebrick", command=self.DeleteCut).pack(side=tk.LEFT) - frame.pack(fill=tk.X,expand=False) - - def _MakeTreeView(self, parent): - self.tree = ttk.Treeview(parent, columns=('type',)) - self.tree.column('type', width=50, anchor='e') - self.tree.heading('type', text='Type') - self.tree.pack(fill=tk.BOTH,expand=True) - self.tree.bind("",self.TreeView_OnDoubleClick) - - def _draw_cut(self,tcut): - tcut.Draw('same') - if ROOT.gPad: - ROOT.gPad.Modified() - ROOT.gPad.Update() - - def TreeView_OnDoubleClick(self, event): - selection = event.widget.selection()[0] - if selection in self.cuts: - self._draw_cut(self.cuts[selection]) - else: - if selection.endswith('Draw PID'): - cls_name = selection[:selection.index('/')] - try: - self.detector_classes[cls_name].DrawPID('','',1000) - except AttributeError: - print 'You did not implement {}::DrawPID.\nPlease do so.'.format(cls_name) + 'points':points, + 'varx':cut.GetVarX(), + 'vary':cut.GetVarY(), + } + output.append(pattern) + return output + + def _load_tcut_patterns(self, patterns): + for pattern in patterns: + cut = ROOT.TCutG(pattern['name'],len(pattern['points'])) + cut.SetVarX(pattern['varx']) + cut.SetVarY(pattern['vary']) + for i,(x,y) in enumerate(pattern['points']): + cut.SetPoint(i, x, y) + self.AddCut(cut) + + def _check_for_tcut(self): + # Does CUTG exist? + cutg = ROOT.gROOT.GetListOfSpecials().FindObject('CUTG') + if not cutg: + return None + + # Does it have 3 or more points? + npoints = cutg.GetN() + if npoints < 3: + return None + + # Is the first point equal to the last point? + xi = cutg.GetX()[0] + yi = cutg.GetY()[0] + xf = cutg.GetX()[npoints-1] + yf = cutg.GetY()[npoints-1] + if xi!=xf or yi!=yf: + return None + + return cutg + + def AddDirectory(self, tdir): + gchain = ROOT.gChain + # If the chain doesn't exist, or if it is empty. + if not gchain or gchain.GetEntries()==0: + return + + for branch in gchain.GetListOfBranches(): + cls_name = branch.GetName() + cls = getattr(ROOT, cls_name) + if cls_name not in self.detector_classes: + top = self.tree.insert('','end',cls_name, text=cls_name) + self.tree.insert(top,'end','{}/Draw PID'.format(cls_name),text='Draw PID') + self.detector_classes[cls_name] = cls + + def AddFile(self, tfile): + for key in tfile.GetListOfKeys(): + #print key.GetName() + if key.GetClassName()=='TCutG': + obj = key.ReadObj() + #print obj.GetName() + self.AddCut(obj) #key.ReadObj()) + if key.GetClassName()=='GCutG': + obj = key.ReadObj() + #print obj.GetName() + self.AddCut(obj) #key.ReadObj()) + + def AddCut(self, cut, det_type = None): + name = cut.GetName() + full_name = '{}/{}'.format(det_type,name) if det_type is not None else name + cut.SetLineColor(ROOT.kRed) + cut.SetLineWidth(3) + self.cuts[full_name] = cut + + if det_type is None: + parent = '' + else: + parent = det_type + self.detector_classes[det_type].AddGate(cut) + + self.tree.insert(parent, 'end', full_name, text=name, values='2D Cut',image = self.main.icons['tcutg']) + + if ROOT.gPad: + ROOT.gPad.Modified() + ROOT.gPad.Update() + + def StartCut(self): + ROOT.gROOT.SetEditorMode('CutG') + + def SaveCut(self): + cutg = self._check_for_tcut() + if cutg is None: + return + + ROOT.gROOT.GetListOfSpecials().Remove(cutg) + + cutg.SetName(self._increment_name()) + for prim in ROOT.gPad.GetListOfPrimitives(): + if isinstance(prim, ROOT.GH2): + title = prim.GetName() + det_type = title[:title.index('_')] + break + else: + det_type = None + + self.AddCut(cutg, det_type) + + def DeleteCut(self): + cutg = self._check_for_tcut() + if(cutg is None): + return + + cutg.Delete() + + def CopyCut(self): + cuts = self.tree.selection() + if not cuts: + return + cutname = cuts[0] + tcutg = self.cuts[cutname] + newcut = tcutg.Clone(self._increment_name()) + + xmin = min(newcut.GetX()[i] for i in range(newcut.GetN())) + xmax = max(newcut.GetX()[i] for i in range(newcut.GetN())) + xshift = 0.5*(xmax-xmin) + for i in range(newcut.GetN()): + newcut.GetX()[i] += xshift + + newcut.Draw('same') + self.AddCut(newcut) + + + def _increment_name(self): + name = self.next_name.get() + self.next_name.set(increment_name(name)) + return name + + def _MakeNaming(self, parent): + self.next_name = tk.StringVar(value='tcutg_0') + frame = tk.Frame(parent) + tk.Label(frame, text='Name:').pack(side=tk.LEFT) + tk.Entry(frame, textvariable=self.next_name).pack(side=tk.LEFT) + frame.pack(fill=tk.X,expand=False) + + frame = tk.Frame(parent) + tk.Button(frame, text='Make Gate', fg="black",bg="light goldenrod", command=self.StartCut).pack(side=tk.LEFT) + tk.Button(frame, text='Save Gate', fg="black",bg="light goldenrod", command=self.SaveCut).pack(side=tk.LEFT) + tk.Button(frame, text='Copy Gate',fg="black",bg="light goldenrod", command=self.CopyCut).pack(side=tk.LEFT) + tk.Button(frame, text='Delete Gate',fg="black",bg="firebrick", command=self.DeleteCut).pack(side=tk.LEFT) + frame.pack(fill=tk.X,expand=False) + + def _MakeTreeView(self, parent): + self.tree = ttk.Treeview(parent, columns=('type',)) + self.tree.column('type', width=50, anchor='e') + self.tree.heading('type', text='Type') + self.tree.pack(fill=tk.BOTH,expand=True) + self.tree.bind("",self.TreeView_OnDoubleClick) + + def _draw_cut(self,tcut): + tcut.Draw('same') + if ROOT.gPad: + ROOT.gPad.Modified() + ROOT.gPad.Update() + + def TreeView_OnDoubleClick(self, event): + selection = event.widget.selection()[0] + if selection in self.cuts: + self._draw_cut(self.cuts[selection]) + else: + if selection.endswith('Draw PID'): + cls_name = selection[:selection.index('/')] + try: + self.detector_classes[cls_name].DrawPID('','',1000) + except AttributeError: + print('You did not implement {}::DrawPID.\nPlease do so.'.format(cls_name)) diff --git a/pygui/util.py b/pygui/util.py index 94d4d372..8c51b36d 100755 --- a/pygui/util.py +++ b/pygui/util.py @@ -55,8 +55,11 @@ def __getitem__(self, key): if isinstance(output, ROOT.TKey): output = output.ReadObj() if (isinstance(output, ROOT.TH2) and - not isinstance(output, ROOT.GH2Base)): + not isinstance(output, ROOT.GH2)): output = ROOT.GH2D(output) + elif (isinstance(output, ROOT.TH1) and + not isinstance(output, ROOT.GH1)): + output = ROOT.GH1D(output) self[key] = output return output diff --git a/pygui/variable_tab.py b/pygui/variable_tab.py index 1ff0990e..93db8f6f 100755 --- a/pygui/variable_tab.py +++ b/pygui/variable_tab.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 -import Tkinter as tk -import ttk +import tkinter as tk +from tkinter import ttk import ROOT ROOT.PyConfig.IgnoreCommandLineOptions = True @@ -86,7 +86,7 @@ def OnSetReplaceVariable_Click(self, *args): try: value = float(self.var_value.get()) except ValueError: - print 'Could not convert "{}" to float'.format(self.var_value.get()) + print('Could not convert "{}" to float'.format(self.var_value.get())) return self.SetReplaceVariable(name, value) diff --git a/sandbox/runme.sh b/sandbox/runme.sh new file mode 100755 index 00000000..feb1f050 --- /dev/null +++ b/sandbox/runme.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +currentrundir="/global/data1y/gretina/e15130" +expnumber="e15130" +valfile="~/Programs/GRUTinizer/${expnumber}.val" +calfile="~/Programs/GRUTinizer/${expnumber}.cal" +histlib="~/packages/GRUTinizer6/lib/libMake${expnumber}.so" + + +runnumber=`echo $currentrundir | sed -e s/Run//g` + +ls $currentrundir diff --git a/sandbox/sort.sh b/sandbox/sort.sh new file mode 100755 index 00000000..ae554fa1 --- /dev/null +++ b/sandbox/sort.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# 186Hf runs + +COMMAND="grutinizer -qH " + +INPUTS="e15130.val e15130.cal zcuts_run136.cuts /home/gretinaadmin/Programs/GRUTinizer/lib/libMakee15130_v3.so -o/dev/null " + +#FILES="/global/data1y/gretina/e15130/Run0108/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0109/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0110/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0111/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0112/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0113/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0114/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0115/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0116/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0117/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0118/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0119/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0120/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0121/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0122/Global.dat " +#FILES=$FILES"/global/data1y/gretina/e15130/Run0123/Global.dat " + +FILES=$FILES"/global/data1y/gretina/e15130/Run0132/Global.dat " +FILES=$FILES"/global/data1y/gretina/e15130/Run0133/Global.dat " +FILES=$FILES"/global/data1y/gretina/e15130/Run0134/Global.dat " +FILES=$FILES"/global/data1y/gretina/e15130/Run0135/Global.dat " +FILES=$FILES"/global/data1y/gretina/e15130/Run0136/Global.dat " +FILES=$FILES"/global/data1y/gretina/e15130/Run0137/Global.dat " +FILES=$FILES"/global/data1y/gretina/e15130/Run0138/Global.dat " +FILES=$FILES"/global/data1y/gretina/e15130/Run0139/Global.dat " + + + +#parallel -j2 $COMMAND ::: $INPUTS ::: $FILES + +for i in $FILES +do + grutinizer -qH $i /home/gretinaadmin/Programs/GRUTinizer/lib/libMakee15130_v3.so e15130.val e15130.cal zcuts_run136.cuts -o /dev/null +done diff --git a/thisgrut.sh b/thisgrut.sh index 7e68fb5f..73c57069 100755 --- a/thisgrut.sh +++ b/thisgrut.sh @@ -1,12 +1,3 @@ -# Source this script to set up the grutSort build that this script is part of. -# -# Conveniently an alias like this can be defined in .bashrc: -# alias thisgrut=". bin/thisgrut.sh" -# -# This script if for the bash like shells, see thisgrut.csh for csh like shells. -# -# Author: Fons Rademakers, 18/8/2006 -# Adapted by Ryan Dunlop, 8/9/2015 drop_from_path() { diff --git a/util/CalibrateCaesar.cxx b/util/CalibrateCaesar.cxx deleted file mode 100644 index 4bdc78c6..00000000 --- a/util/CalibrateCaesar.cxx +++ /dev/null @@ -1,643 +0,0 @@ -#define VERBOSE 0 -#define N_KNOWN_SOURCES 6 // Number of Known Sources to be used in Source Class -#define N_RINGS 10 // Number of Caesar Rings -#define MAX_DETS 24 // Maximum number of detectors in a ring -#define MAX_PEAKS 2 // Maximum number of peaks in a source spectrum -#define TOTAL_PEAKS_TO_FIT 8 // Maximum number of peaks to find for each detector -#define FIT_PADDING 15 // Distance to go to left and right of peak for fitting with gaussian -#define FIND_PADDING 100 // for ensuring correct energy is found from rough estimate -#define FIT_ORDER 2 - -#define HIGH_CH_LIMIT_Y88_PEAK_1 330 //Helps fit y88 by checking whether found peaks are in correct -#define LOW_CH_LIMIT_Y88_PEAK_2 400 //range - -#include -#include -#include -#include -#include -#include -#include "TH1D.h" -#include "TFile.h" -#include "TF1.h" -#include "TSpectrum.h" -#include "TTree.h" -#include "TGraph.h" -#include "TCaesar.h" - -#include "TChannel.h" - -//The Source class allows easy organization of different source runs by source -//name and number without having to always explicitly give the energies, etc. -//of the sources. -class Source { - public: - Source(std::string in_name, int in_run_number, int in_n_peaks, double in_peak_finder_threshold, - double in_energies[MAX_PEAKS], double in_peak_finder_sigma, int in_low_ch_limit, int in_high_ch_limit);//Full constructor - - //For known sources should have constructor that automatically adds energies - //and number of peaks. - Source(std::string name, double run_number, double peak_finder_threshold, - double peak_finder_sigma);//Constructor for known sources - - ~Source(){ - } - - bool isValid(){ - return is_valid; - } - - std::string name; - int n_peaks; //number of expected gamma peaks for source - double peak_finder_threshold;//Thresholds for using TSpectrum - double energies[MAX_PEAKS]; - double peak_finder_sigma;//Determined from preliminary gauss fit to data - int run_number;//number of run from which the source came - int low_ch_limit; - int high_ch_limit; - - private: - std::vector known_source_names; - double known_energies[N_KNOWN_SOURCES][MAX_PEAKS]; - int known_n_peaks[N_KNOWN_SOURCES]; - int known_ranges[N_KNOWN_SOURCES][2];//Expected Low/High Limis for Fits - bool is_valid; - - void fillKnownSourceNames(){ - this->known_source_names.push_back("y88"); - this->known_source_names.push_back("co60"); - this->known_source_names.push_back("na22"); - this->known_source_names.push_back("cs137"); - this->known_source_names.push_back("ba133"); - this->known_source_names.push_back("bg"); - } - void fillKnownEnergies(){ - this->known_energies[0][0] = 898.042; - this->known_energies[0][1] = 1836.063; //88Y - - this->known_energies[1][0] = 1173.228; - this->known_energies[1][1] = 1332.492; //60Co - - this->known_energies[2][0] = 511.0; - this->known_energies[2][1] = 1274.537; //22Na - - this->known_energies[3][0] = 661.657; //137Cs (1 peak) - this->known_energies[3][1] = 0; - -// this->known_energies[4][0] = 80.9979; //Might be unable to fit this one - this->known_energies[4][0] = 356.0129; //133Ba - this->known_energies[4][1] = 0; //133Ba - - this->known_energies[5][0] = 1460.822; //40K - this->known_energies[5][1] = 0;//keep failing to find this peak -// this->known_energies[5][1] = 2614.511; //208Tl - } - void fillKnownNPeaks(){ - known_n_peaks[0] = 2;//Y88 - known_n_peaks[1] = 2;//60Co - known_n_peaks[2] = 2;//22Na - known_n_peaks[3] = 1;//137Cs - known_n_peaks[4] = 1;//133Ba - known_n_peaks[5] = 1;//Bg - } - void fillKnownRanges(){ //Low/High X-Axis Values for Ease of Finding Peaks - known_ranges[0][0] = 150; - known_ranges[0][1] = 2000; - - known_ranges[1][0] = 150; - known_ranges[1][1] = 2000; - - known_ranges[2][0] = 80; - known_ranges[2][1] = 2000; - - known_ranges[3][0] = 150; - known_ranges[3][1] = 2000; - - known_ranges[4][0] = 150; - known_ranges[4][1] = 2000; - - known_ranges[5][0] = 150; - known_ranges[5][1] = 2000; - } -}; - -Source::Source(std::string in_name, int in_run_number, int in_n_peaks, double in_peak_finder_threshold, - double in_energies[MAX_PEAKS], double in_peak_finder_sigma, int in_low_ch_limit, int in_high_ch_limit){ - this->is_valid = true; - this->name = in_name; - this->n_peaks = in_n_peaks; - this->peak_finder_threshold = in_peak_finder_threshold; - this->run_number = in_run_number; - for (int i = 0; i < MAX_PEAKS; i++){ - this->energies[i] = in_energies[i]; - } - this->peak_finder_sigma = in_peak_finder_sigma; - this->low_ch_limit = in_low_ch_limit; - this->high_ch_limit = in_high_ch_limit; - }//Full constructor - - //For known sources should have constructor that automatically adds energies - //and number of peaks. - -Source::Source(std::string name, double run_number, double peak_finder_threshold, - double peak_finder_sigma){ - this->fillKnownSourceNames(); - this->fillKnownEnergies(); - this->fillKnownNPeaks(); - this->fillKnownRanges(); - //Find location of source name in known source list - std::vector::iterator string_iter = std::find(known_source_names.begin(), - known_source_names.end(), - name); - if (string_iter != known_source_names.end()){ - std::cout << "Found source name: " << name << std::endl; - this->is_valid = true; - int index = std::distance(known_source_names.begin(), string_iter); -// Source(name, run_number, known_n_peaks[index], peak_finder_threshold, -// known_energies[index], peak_finder_sigma, known_ranges[index][0], -// known_ranges[index][1]); - this->name = name; - this->n_peaks = known_n_peaks[index]; - this->peak_finder_threshold = peak_finder_threshold; - this->run_number = run_number; - for (int i = 0; i < MAX_PEAKS; i++){ - this->energies[i] = known_energies[index][i]; - } - this->peak_finder_sigma = peak_finder_sigma; - this->low_ch_limit = known_ranges[index][0]; - this->high_ch_limit = known_ranges[index][1]; - } - else{ - std::cout << "Failed to find source " << name << "!" << std::endl; - this->is_valid = false; - } - }//Constructor for known sources - - -double getEnergy(double ch, double cal_par[4]){ - //Convert a channel value to an energy value - double en = cal_par[0]; - en += cal_par[1] * ch; - en += cal_par[2] * ch*ch; - en += cal_par[3] * ch*ch*ch; - return en; -} -void saveCalibration(double data_to_save[N_RINGS][MAX_DETS][4], char *out_cal_file_name){ - char ring_name[N_RINGS][100] = { - "Caesar.Ring.a", - "Caesar.Ring.b", - "Caesar.Ring.c", - "Caesar.Ring.d", - "Caesar.Ring.e", - "Caesar.Ring.f", - "Caesar.Ring.g", - "Caesar.Ring.h", - "Caesar.Ring.i", - "Caesar.Ring.j" - }; - int det_per_ring[N_RINGS] = { - 10, 14, 24, 24, 24, - 24, 24, 24, 14, 10 - }; - - std::ofstream out_file; - out_file.open(out_cal_file_name); - for (int ring = 0; ring < N_RINGS; ring++){ - for(int det = 0; det < det_per_ring[ring]; det++){ - out_file << ring_name[ring] << ".e_a0." << det+1 << ": " << data_to_save[ring][det][0] << std::endl; - out_file << ring_name[ring] << ".e_a1." << det+1 << ": " << data_to_save[ring][det][1] << std::endl; - out_file << ring_name[ring] << ".e_a2." << det+1 << ": " << data_to_save[ring][det][2] << std::endl; - out_file << ring_name[ring] << ".e_a3." << det+1 << ": " << data_to_save[ring][det][3] << std::endl; - } - } - out_file.close(); -} - -//saveChannels will create a TChannel file for GRUTinizer Calibration purposes -//If current cal file name is passed, the cal file will be opened and energy coefficient -//data inside will be overwritten with the fitted data (useful when you have already done -//a time calibration!) - -void saveChannels(double data_to_save[N_RINGS][MAX_DETS][4], char *out_cal_file_name, std::string cal_file_name =""){ - if (!cal_file_name.empty()){ - TChannel::ReadCalFile(cal_file_name.c_str()); - } - TCaesar *caesar = new TCaesar(); //gets us access to VSN mapping - - TChannel *tchan; - std::vector energy_coeff; - - - for (int vsn = 0; vsn < MAX_VSN; vsn++){ - for (int chan = 0; chan < MAX_CHN; chan++){ - energy_coeff.clear(); - int ring = caesar->vsnchn_ring_map_energy[vsn][chan]; - int det = caesar->vsnchn_det_map_energy[vsn][chan]; - unsigned int address = ((37<<24) + (vsn << 16)+ chan); - - for (int par = 0; par < 4; par++){ - energy_coeff.push_back(data_to_save[ring][det][par]); - } - - if (!cal_file_name.empty()){ - tchan = TChannel::Get(address); - tchan->SetEnergyCoeff(energy_coeff); - } - else{ - tchan = new TChannel(Form("RING%02dDET%02d",ring,det), address); - tchan->SetEnergyCoeff(energy_coeff); - TChannel::AddChannel(tchan); - } - }//loop over channels - }//loop over vsn - - TChannel::WriteCalFile(out_cal_file_name); -} - -void readInitialCalibration(char *in_par_file_name, double cal_par[N_RINGS][MAX_DETS][4]){ - std::ifstream in_par_file; - in_par_file.open(in_par_file_name); - if (!in_par_file){ - std::cout << "Failed to open input calibrations!" << std::endl; - exit(5); - } - - std::string line; - char ring_name; - int fit_order; - int det_id; - int ring_id; - double cal_par_val;//the actual calibration parameter value - while (std::getline(in_par_file,line)){ - sscanf(line.c_str(), "Caesar.Ring.%c.e_a%d.%d: %lf", &ring_name, &fit_order, &det_id, &cal_par_val); - det_id = det_id -1; //want det_id to start from 0 - ring_id = ring_name - 'a';//forces ring_id to start from 0 - cal_par[ring_id][det_id][fit_order] = cal_par_val; - } - in_par_file.close(); - return; -} -void readInitialCalibration_GRUTinizer(char *in_cal_file_name, double cal_par[N_RINGS][MAX_DETS][4]){ - - TChannel::ReadCalFile(in_cal_file_name); - if(!TChannel::Size()){ - std::cout << "Failed to get channels from in_cal_file_name: " << in_cal_file_name << std::endl; - return; - } - std::vector energy_coeff; - TChannel *tchan; - TCaesar *caesar = new TCaesar(); - for (int vsn = 0; vsn < MAX_VSN; vsn++){ - for (int chan = 0; chan < MAX_CHN; chan++){ - energy_coeff.clear(); - int ring = caesar->vsnchn_ring_map_energy[vsn][chan]; - int det = caesar->vsnchn_det_map_energy[vsn][chan]; - unsigned int address = ((37<<24) + (vsn << 16)+ chan); - - tchan = TChannel::Get(address); - energy_coeff = tchan->GetEnergyCoeff(); - - for (unsigned int par = 0; par < energy_coeff.size(); par++){ - cal_par[ring][det][par] = energy_coeff.at(par); - } - }//loop over channels - }//loop over VSN - - delete caesar; - return; -} -//Used as follows: -//(Note: All ring/det #'s start from 0!) -//in_hist_file_name is a file containing the energy histograms for the sources organized by the names -// sourcename_run_#_ring_#_det_# (e.g., y88_run_76__ring_1_det_8) -// -//in_source_list is a flat text file containing informations about the sources in the form -// source_name run_# peak_finder_threshold peak_finder_sigma -// (e.g. y88 76 12.5 5.5) -// For more information about threshold/sigma parameters, see the TSpectrum webpage - -//in_par_file is a file containing an intial guess at the calibration where each line is in the form: -//Caesar.Ring.a.e_a0.1: #, where 1 is the det_id (1,..,24), a is the ring name, and E = a0+a1*E_raw+a2*E_raw^2 -//or as a tchannel file! -// -//in_cal_file_name is the file containing the time calibration that you want to append the energy -//coefficients to -void CalibrateCaesar(char *in_hist_file_name, char *in_source_list, char *out_cal_file_name, - char *out_hist_file_name, char *in_cal_file_name = NULL, char *in_par_file_name =NULL){ - unsigned int det_per_ring[N_RINGS] = { - 10, 14, 24, 24, 24, - 24, 24, 24, 14, 10 - }; - - std::vector source_list;//Sources to be read in from file - double cal_par[N_RINGS][MAX_DETS][4]; //calibration parameters for each ring & detector - double peak_locations[10]; //locations of peaks found by TSpectrum - double peak_energy; //energy of peak location from two-point fit - bool found_y88_peaks;//if not found, cannot continue calibration - bool failed_calibration;//if failed calibration for non-Y88 peaks - int peaks_found; //# peaks found by tspectrum; not all will be used - int peaks_fit;//# of found peaks that have been fit - std::vector fit_means; - std::vector expected_energy; - std::vector y88_indices;//allows easy finding of y88 for 2-Point Calibration - const int REBINNING_FACTOR = 4; - - - //Initialize array to 0 - for (int ring = 0; ring < N_RINGS; ring++){ - for(int det = 0; det < MAX_DETS; det++){ - cal_par[ring][det][0] = 0; - cal_par[ring][det][1] = 1; - cal_par[ring][det][2] = 0; - cal_par[ring][det][3] = 0; - } - } - - //Read in source list - std::string line;//for parsing file - int lines_read = 0; - std::ifstream source_list_file; - source_list_file.open(in_source_list); - - if (!source_list_file.is_open()){ - std::cout << "Failed opening file!" << std::endl; - return; - } - - //Each line of source list file should be in form - - while(std::getline(source_list_file,line)){ - std::string source_name; - int run_number; - double peak_finder_threshold; - double peak_finder_sigma; - - std::stringstream ss(line); - ss >> source_name; - ss >> run_number; - ss >> peak_finder_threshold; - ss >> peak_finder_sigma; - source_list.push_back(Source(source_name, run_number, peak_finder_threshold, - peak_finder_sigma)); - if (source_name == "y88"){ - y88_indices.push_back(lines_read); - } - - if (!source_list[lines_read].isValid()){ - std::cout << source_name << " " << run_number << " " << peak_finder_threshold - << " " << peak_finder_sigma << std::endl; - std::cout << "Failed reading source list for this line! Exiting... " << std::endl; - source_list_file.close(); - return; - } - lines_read++; - } - source_list_file.close(); - - - //Open file containing histograms in form sourcename_ring_#_det_# - TFile *in_hist_file = new TFile(in_hist_file_name, "read"); - - //Create an output file will store all histograms and graphs for inspection of fits - TFile *out_hist_file = new TFile(out_hist_file_name, "recreate"); - - TSpectrum y88_peak_finder(2); //Used just to find peaks for initial 2-point fit - TSpectrum peak_finder; //Finds all peaks in a spectrum - - TH1D *in_hist;//Histogram grabbed from file - std::vector out_hists;//Histogram for sanity check of fits - std::vector out_graphs; - - //First, do a 2-point fit on 88-yttrium to get a base calibration, unless - //initial calibration is given. - //Then, using this very rough approximation, we can distinguish between - //the peaks TSpectrum finds to determine the correct peak locations for - //fitting. - - TF1 *gaus_fit_1 = new TF1("gaus_fit_1", "gaus"); //need two gaussian functions defined - //because TH1::Fit overwrites the function - //with the given name, and need to retain - //the parameters - - if (in_par_file_name != NULL){ - //readInitialCalibration(in_par_file_name, cal_par); - readInitialCalibration_GRUTinizer(in_par_file_name, cal_par); - } - - for (unsigned int ring = 0; ring < N_RINGS; ring++){ - for (unsigned int det = 0; det < det_per_ring[ring]; det++){ - failed_calibration = false; - found_y88_peaks = false; - if (in_par_file_name == NULL){ - //Find all y88 runs for the first two point fit - for (unsigned int i = 0; i < y88_indices.size(); i++){ - in_hist = (TH1D*)in_hist_file->Get(Form("%s_run_%d_ring_%d_det_%d", source_list[y88_indices[i]].name.c_str(), - source_list[y88_indices[i]].run_number, ring, det)); - in_hist->Rebin(REBINNING_FACTOR); - if (in_hist == NULL){ - std::cout << "Histogram: " << (source_list[y88_indices[i]].name).c_str() << "_run_" << - source_list[y88_indices[i]].run_number << "_ring_" << ring << - "_det_" << det << " not found!" << std::endl; - failed_calibration = true; - break; - } - - if (in_hist->Integral() == 0){ - std::cout << "Histogram is empty for ring " << ring << " and det " << det << std::endl; - failed_calibration = true; - break; - } - - in_hist->GetXaxis()->SetRangeUser(source_list[y88_indices[i]].low_ch_limit, source_list[y88_indices[i]].high_ch_limit); - // std::cout << "low_ch_limit: " << source_list[y88_indices[i]].low_ch_limit << std::endl; - // std::cout << "high_ch_limit: " << source_list[y88_indices[i]].high_ch_limit << std::endl; - // std::cout << "peak_finder_sigma: " << source_list[y88_indices[i]].peak_finder_sigma << std::endl; - // std::cout << "peak_finder_threshold: " << source_list[y88_indices[i]].peak_finder_threshold << std::endl; - y88_peak_finder.Search(in_hist, source_list[y88_indices[i]].peak_finder_sigma, - "nodraw", source_list[y88_indices[i]].peak_finder_threshold); - - if (y88_peak_finder.GetPositionX()[0] > source_list[y88_indices[i]].low_ch_limit && - y88_peak_finder.GetPositionX()[0] < HIGH_CH_LIMIT_Y88_PEAK_1 && - y88_peak_finder.GetPositionX()[1] > LOW_CH_LIMIT_Y88_PEAK_2 && - y88_peak_finder.GetPositionX()[1] < source_list[y88_indices[i]].high_ch_limit){ - - found_y88_peaks = true; - - in_hist->Fit(gaus_fit_1,"Q+","", y88_peak_finder.GetPositionX()[0] - FIT_PADDING, - y88_peak_finder.GetPositionX()[0] + FIT_PADDING); - fit_means.push_back(in_hist->GetFunction("gaus_fit_1")->GetParameter(1)); - expected_energy.push_back(source_list[y88_indices[i]].energies[0]); - - in_hist->Fit("gaus","Q+","", y88_peak_finder.GetPositionX()[1] - FIT_PADDING, - y88_peak_finder.GetPositionX()[1] + FIT_PADDING); - fit_means.push_back(in_hist->GetFunction("gaus")->GetParameter(1)); - expected_energy.push_back(source_list[y88_indices[i]].energies[1]); - - out_hists.push_back((TH1D*)in_hist->Clone(Form("%s_run_%d_ring_%d_det_%d_fitted", source_list[y88_indices[i]].name.c_str(), - source_list[y88_indices[i]].run_number, ring, det))); - out_hists.back()->SetDirectory(out_hist_file); - }//Found correct peaks for y88 - else{ - std::cout << "\tlow_ch_limit: " << source_list[y88_indices[i]].low_ch_limit << std::endl; - std::cout << "\thigh_ch_limit: " << source_list[y88_indices[i]].high_ch_limit << std::endl; - std::cout << "HIGH_CH_LIMIT_Y88_PEAK_1: " << HIGH_CH_LIMIT_Y88_PEAK_1 << std::endl; - std::cout << "LOW_CH_LIMIT_Y88_PEAK_2: " << LOW_CH_LIMIT_Y88_PEAK_2 << std::endl; - std::cout << "Found positions: " << y88_peak_finder.GetPositionX()[0] << " and " << y88_peak_finder.GetPositionX()[1] << std::endl; - - } - - }//Loop over Y88 Indices - - if (!found_y88_peaks){ - std::cout << "Failed calibration for Y88 for ring " << ring << " and det " << det << std::endl; - break; - } - - TGraph y88_graph(fit_means.size(), &fit_means[0], &expected_energy[0]); - TF1 *test_poly1_fit = new TF1(Form("test_poly_fit_ring_%d_det_%d", ring, det), Form("pol%d",1)); - test_poly1_fit->SetParameter(0,30); - test_poly1_fit->SetParameter(1,4); - test_poly1_fit->SetParLimits(0,-60,60); - test_poly1_fit->SetParLimits(1,3,4); - y88_graph.Fit(test_poly1_fit, "QME"); - cal_par[ring][det][0] = y88_graph.GetFunction(Form("test_poly_fit_ring_%d_det_%d",ring,det))->GetParameter(0); - cal_par[ring][det][1] = y88_graph.GetFunction(Form("test_poly_fit_ring_%d_det_%d",ring,det))->GetParameter(1); - }//if there is no in_par_file - else { - found_y88_peaks = true; - }//get input parameters from file - - //Now that we have initial fit, we can fit the other sources - for (unsigned int source = 0; source < source_list.size(); source++){ //Loop over non-Y88 sources! - if (in_par_file_name == NULL){ - if (std::find(y88_indices.begin(), y88_indices.end(), source) != y88_indices.end()){ - continue;//skip y88, if it's already been calibrated - } - } - - in_hist = (TH1D*)in_hist_file->Get(Form("%s_run_%d_ring_%d_det_%d", source_list[source].name.c_str(), - source_list[source].run_number, ring, det)); - if (in_hist == NULL){ - std::cout << "Histogram: " << source_list[source].name << "_run_" << source_list[source].run_number << - "_ring_" << ring << "_det_" << det << " not found!" << std::endl; - failed_calibration = true; - break; - } - in_hist->Rebin(REBINNING_FACTOR); - - if (in_hist->Integral() == 0){ - std::cout << "Histogram: " << source_list[source].name << "_run_" << source_list[source].run_number << - "_ring_" << ring << "_det_" << det << " is empty!" << std::endl; - failed_calibration = true; - break; - } - in_hist->GetXaxis()->SetRangeUser(source_list[source].low_ch_limit, source_list[source].high_ch_limit); - peak_finder.Search(in_hist, source_list[source].peak_finder_sigma, - "nodraw", source_list[source].peak_finder_threshold); - peaks_found = peak_finder.GetNPeaks(); - for (int peak = 0; peak < peaks_found; peak++){ - peak_locations[peak] = peak_finder.GetPositionX()[peak]; - } - peaks_fit = 0; - - for (int i = 0; i < peaks_found; i++){ - //Use simple fit to get approximate energy to compare to expected energies! - peak_energy = getEnergy(peak_locations[i],cal_par[ring][det]); - - if (peak_energy < source_list[source].energies[0] + FIND_PADDING && - peak_energy > source_list[source].energies[0] - FIND_PADDING){ - in_hist->Fit(gaus_fit_1,"Q+","",peak_locations[i] - FIT_PADDING, peak_locations[i] + FIT_PADDING); - fit_means.push_back(in_hist->GetFunction("gaus_fit_1")->GetParameter(1)); - expected_energy.push_back(source_list[source].energies[0]); - peaks_fit++; - }//is peak 1 - else if (peak_energy < source_list[source].energies[1] + FIND_PADDING && - peak_energy > source_list[source].energies[1] - FIND_PADDING){ - in_hist->Fit("gaus","Q+","",peak_locations[i] - FIT_PADDING, peak_locations[i] + FIT_PADDING); - fit_means.push_back(in_hist->GetFunction("gaus")->GetParameter(1)); - expected_energy.push_back(source_list[source].energies[1]); - peaks_fit++; - }//is peak 2 - if (i == peaks_found-1 && peaks_fit != source_list[source].n_peaks){//failed to fit all peaks - std::cout << "Failed calibration for source " << source_list[source].name << " with " << peaks_fit << " peaks fit" << std::endl; - std::cout << "out of " << peaks_found << " peaks found " << "for ring: " << ring << " det: " << det << " run number: " - << source_list[source].run_number << std::endl; - std::cout << "Found peak_energy = " << peak_energy << std::endl; - }//peaks fit not enough - }//loop over peaks_found - if (peaks_fit != source_list[source].n_peaks){ - failed_calibration = true; //forces to skip to next detector - break; - } - out_hists.push_back((TH1D*)in_hist->Clone(Form("%s_run_%d_ring_%d_det_%d_fitted", source_list[source].name.c_str(), - source_list[source].run_number, ring, det))); - (out_hists.back())->SetDirectory(out_hist_file); - }//loop over non-y88 sources - - if (!found_y88_peaks || failed_calibration){ - continue; //Have to do this detector by hand; either - //failed y88 or other source calibration - }//if failed calibration - - //Now do the full fit for this detector - TGraph fit_graph(fit_means.size(), &fit_means[0], &expected_energy[0]); - TF1 *poly_fit = new TF1(Form("poly_fit_ring_%d_det_%d", ring, det), Form("pol%d",FIT_ORDER)); - for (int par = 0; par < FIT_ORDER+1; par++){ - poly_fit->SetParameter(par, cal_par[ring][det][par]); - } - poly_fit->SetParameter(1,4); - poly_fit->SetParameter(2,-0.0003); -// poly_fit->SetParameter(1,4); -// poly_fit->SetParLimits(0,-60,60); -// poly_fit->SetParLimits(1,3,5); - fit_graph.Fit(poly_fit, "Q"); - //fit_graph.Fit(Form("pol%d", FIT_ORDER), "Q"); - for (int par = 0; par < FIT_ORDER+1; par++){ -// std::cout << "Before Fit: a" << par << " = " << cal_par[ring][det][par] << std::endl; - cal_par[ring][det][par] = fit_graph.GetFunction(Form("poly_fit_ring_%d_det_%d",ring,det))->GetParameter(par); -// std::cout << "After Fit : a" << par << " = " << cal_par[ring][det][par] << std::endl; - } - if (FIT_ORDER == 1){ - cal_par[ring][det][2] = 0; - cal_par[ring][det][3] = 0; - } - out_graphs.push_back((TGraph*)fit_graph.Clone(Form("ring_%d_det_%d_polyfit", ring,det))); - (out_graphs.back())->Write(); - delete poly_fit; - fit_means.clear(); - expected_energy.clear(); - }//loop over det - }//loop over rings - -// saveCalibration(cal_par, out_cal_file_name); - saveChannels(cal_par, out_cal_file_name, in_cal_file_name); - - out_hist_file->Write(); - out_hist_file->Close(); - in_hist_file->Close(); - - -}//end of function - - -#ifndef __CINT__ - -int main(int argc, char**argv){ - if (argc < 5 || argc > 7){ - std::cout << "Incorrect number of arguements!" << std::endl; - std::cout << "USAGE: CalibrateCaesar in_hists.root in_source_lists.dat out_cal_file_name.dat out_fitted_hists.root [tcal file] [starting_pars.dat]" << std::endl; - return -1; - } - if (argc == 7){ - CalibrateCaesar(argv[1],argv[2],argv[3],argv[4],argv[5],argv[6]); - } - if (argc == 6){ - CalibrateCaesar(argv[1],argv[2],argv[3],argv[4],argv[5]); - } - if (argc == 5){ - CalibrateCaesar(argv[1],argv[2],argv[3],argv[4]); - } - return 0; -} - -#endif diff --git a/util/CheckUnCalCRDCY.C b/util/CheckUnCalCRDCY.C index ceee6bf7..5431ae5e 100644 --- a/util/CheckUnCalCRDCY.C +++ b/util/CheckUnCalCRDCY.C @@ -4,36 +4,59 @@ vector YTA_Centroid; vector ATA_Offsets; vector BTA_Offsets; vector ATABTA_Run; +vector RunNumbers; -bool GetATABTAOffsets(const char* outfile){ + +bool GetATABTAOffsets(string Directory, double InitialVal = 0.0/*degrees*/){ if(!(ATA_Offsets.size()) || !(BTA_Offsets.size())) return 0; - ofstream outFile; - outFile.open(outfile); + // outFile.open(outfile); for(int i=0;iGetListOfFiles(); int NumFiles = FileList->GetSize(); @@ -46,17 +69,25 @@ TList *CheckATABTA(float lowa=0,float higha=0,float lowb=0,float highb=0){ TCanvas *TACanv = new TCanvas("TACanv","Target Angle Canvas"); // 2D plots TCanvas *ATACanv = new TCanvas("ATACanv","ATA Canvas"); // 1d ATA TCanvas *BTACanv = new TCanvas("BTACanv","BTA Canvas"); // 1d BTA + + if(RunNumbers.size()>0) + RunNumbers.clear(); - if(NumFiles%2==0){ - int FirstDivide = NumFiles/2; - TACanv->Divide(FirstDivide,2); - ATACanv->Divide(FirstDivide,2); - BTACanv->Divide(FirstDivide,2); + if(NumFiles%4==0){ + int FirstDivide = NumFiles/4; + TACanv->Divide(FirstDivide,4); + ATACanv->Divide(FirstDivide,4); + BTACanv->Divide(FirstDivide,4); }else if(NumFiles%3==0){ int FirstDivide = NumFiles/3; TACanv->Divide(FirstDivide,3); ATACanv->Divide(FirstDivide,3); BTACanv->Divide(FirstDivide,3); + }else if(NumFiles%2==0){ + int FirstDivide = NumFiles/2; + TACanv->Divide(FirstDivide,2); + ATACanv->Divide(FirstDivide,2); + BTACanv->Divide(FirstDivide,2); } else{ TACanv->Divide(NumFiles); ATACanv->Divide(NumFiles); @@ -77,6 +108,11 @@ TList *CheckATABTA(float lowa=0,float higha=0,float lowb=0,float highb=0){ double highCentATA=0; double highCentBTA=0; double lowRun=0,highRun=0; + double ATA_mean=0.0; + double BTA_mean=0.0; + double ATA_stdev=0.0; + double BTA_stdev=0.0; + for(int i=0;iAt(i); @@ -128,7 +164,11 @@ TList *CheckATABTA(float lowa=0,float higha=0,float lowb=0,float highb=0){ TH1D *ProjATA = ATA_vs_BTA->ProjectionX(Form("ATA_Run%s",run.c_str())); TH1D *ProjBTA = ATA_vs_BTA->ProjectionY(Form("BTA_Run%s",run.c_str())); - + if(rebin!=0){ + UseMean = false; + ProjATA->Rebin(rebin); + ProjBTA->Rebin(rebin); + } double ProjATA_yMax = ProjATA->GetMaximum(); double ProjBTA_yMax = ProjBTA->GetMaximum(); @@ -144,9 +184,17 @@ TList *CheckATABTA(float lowa=0,float higha=0,float lowb=0,float highb=0){ LineATA->SetLineStyle(kDashed); LineATA->SetLineWidth(3); LineATA->Draw("Same"); - GausFit(ProjATA,lowa,higha); - double CentATA = GetCentroid(ProjATA); + std::cout << " Low A = " << lowa << std::endl; + std::cout << " High A = " << higha << std::endl; + if(!UseMean){ + GGaus *g1 = GausFit(ProjATA,lowa,higha); + double CentATA = g1->GetCentroid(); + }else{ + CentATA = ProjATA->GetMean(); + } + ATA_mean += CentATA; ATA_Offsets.push_back(-CentATA); // Do I want to do this? + RunNumbers.push_back(runNumb); ProjATA->SetTitle(Form("ATA Run%s Centoid = %.4f",run.c_str(),CentATA)); ATAGraph->SetPoint(i,runNumb,CentATA); ATABTA_Run.push_back(runNumb); @@ -158,8 +206,15 @@ TList *CheckATABTA(float lowa=0,float higha=0,float lowb=0,float highb=0){ LineBTA->SetLineStyle(kDashed); LineBTA->SetLineWidth(3); LineBTA->Draw("Same"); - GausFit(ProjBTA,lowb,highb); - double CentBTA = GetCentroid(-ProjBTA); + std::cout << " Low B = " << lowb << std::endl; + std::cout << " High B = " << highb << std::endl; + if(!UseMean){ + GGaus *g2 = GausFit(ProjBTA,lowb,highb); + double CentBTA = g2->GetCentroid(); + }else{ + CentBTA= ProjBTA->GetMean(); + } + BTA_mean += CentBTA; BTA_Offsets.push_back(CentBTA); // Do I want to do this? ProjBTA->SetTitle(Form("BTA Run%s Centoid = %.4f",run.c_str(),CentBTA)); BTAGraph->SetPoint(i,runNumb,CentBTA); @@ -224,11 +279,27 @@ TList *CheckATABTA(float lowa=0,float higha=0,float lowb=0,float highb=0){ HistList->Add(ATAGraph); HistList->Add(BTAGraph); + + double N = (double)(BTA_Offsets.size()); + BTA_mean = BTA_mean / N; + ATA_mean = ATA_mean / N; + for(int j=0;jGetListOfFiles(); int NumFiles = FileList->GetSize(); @@ -237,12 +308,15 @@ TList *CheckYTA(float low=0,float high=0){ YTAGraph->SetName("YTA_Graph"); TCanvas *YTACanv = new TCanvas("YTACanv","YTA Canvas"); - if(NumFiles%2==0){ - int FirstDivide = NumFiles/2; - YTACanv->Divide(FirstDivide,2); + if(NumFiles%4==0){ + int FirstDivide = NumFiles/4; + YTACanv->Divide(FirstDivide,4); }else if(NumFiles%3==0){ int FirstDivide = NumFiles/3; YTACanv->Divide(FirstDivide,3); + }else if(NumFiles%2==0){ + int FirstDivide = NumFiles/2; + YTACanv->Divide(FirstDivide,2); } else{ YTACanv->Divide(NumFiles); } @@ -251,6 +325,9 @@ TList *CheckYTA(float low=0,float high=0){ low=-20; high=20; } + + double mean = 0.0; + double stdev = 0.0; double lowRun=0,highRun=0; double lowCent1=0,highCent1=0; @@ -290,7 +367,7 @@ TList *CheckYTA(float low=0,float high=0){ WorkingFile->cd("InverseMap"); - TH1I *Proj1 = S800_YTA; + GH1D *Proj1 = S800_YTA; Proj1->GetXaxis()->SetRangeUser(low-10,high+10); double Proj1_yMax = Proj1->GetMaximum(); @@ -301,10 +378,15 @@ TList *CheckYTA(float low=0,float high=0){ Line1->SetLineStyle(kDashed); Line1->SetLineWidth(3); Line1->Draw("Same"); - TF1 *gfit = new TF1("gfit","gaus",low,high); - Proj1->Fit(gfit); - double Cent1 = gfit->GetParameter("Mean"); + if(!UseMean){ + TF1 *gfit = new TF1("gfit","gaus",low,high); + Proj1->Fit(gfit); + double Cent1 = gfit->GetParameter("Mean"); + }else{ + double Cent1 = Proj1->GetMean(); + } YTA_Centroid.push_back(Cent1); + mean += Cent1; Proj1->SetTitle(Form("YTA Run%s Centoid = %.6f",run.c_str(),Cent1)); YTAGraph->SetPoint(i,runNumb,Cent1); @@ -349,20 +431,58 @@ TList *CheckYTA(float low=0,float high=0){ Line3->Draw("same"); HistList->Add(YTAGraph); + + double N = (double)(YTA_Centroid.size()); + mean = mean / N; + for(int j=0;j Part1; + std::vector Part2; + std::vector Part3; + if(!(fileName.empty())){ + inFile.open(fileName.c_str()); + int inFile_counter = 0; + while(!(inFile.eof())){ + string eat; + getline(inFile,eat); + Part1.push_back(eat); + getline(inFile,eat); + Part2.push_back(eat); + getline(inFile,eat); + Part3.push_back(eat); + getline(inFile,eat); + + // std::cout << " -----------" << std::endl; + // std::cout << Part1.at(inFile_counter) << std::endl; + // std::cout << Part2.at(inFile_counter) << std::endl; + // std::cout << Part3.at(inFile_counter) << std::endl; + inFile_counter++; + } + } + + //return false; double NewSlope1; double NewSlope2; - double UnCalVal1=0; - double UnCalVal2=0; + double UnCalVal1=0.0; + double UnCalVal2=0.0; int Centroids = CRDC1_Y_Centroid.size(); printf("------ CRDC 1 Old Slope = %.5f -- Old Offset = %.5f ------\n",slope1,offset1); printf("------ CRDC 2 Old Slope = %.5f -- Old Offset = %.5f ------\n",slope2,offset2); @@ -373,18 +493,44 @@ bool GetNewSlopes(double slope1=1,double offset1=0,double slope2=0,double offset NewSlope1 = (-offset1/UnCalVal1); NewSlope2 = (-offset2/UnCalVal2); - - printf(" - - - Run %f - - - \n",i); + + printf(" - - - Run %f - - - \n",RunNumbers.at(i)); printf(" CRDC1 : New Slope = %.5f \n",NewSlope1); printf(" CRDC2 : New Slope = %.5f \n",NewSlope2); - + + ofstream outfile; + outfile.open(Form("values_run%04i.val",RunNumbers.at(i))); + for(int j=0;jGetListOfFiles(); @@ -401,31 +547,57 @@ TList *CheckCalibratedCRDCY(int low=0,int high=0){ TCanvas *TwoDCanvas2 = new TCanvas("TwoDCanvas2","2D Canvas CRDC 2"); TCanvas *CRDC1 = new TCanvas("CRDC1","CRDC1"); TCanvas *CRDC2 = new TCanvas("CRDC2","CRDC2"); + + if(RunNumbers.size()>0) + RunNumbers.clear(); + + std::cout << " NumFiles = " << NumFiles << std::endl; + std::cout << " NumFiles%4 = " << NumFiles%4 << std::endl; - if(NumFiles%2==0){ - int FirstDivide = NumFiles/2; - TwoDCanvas1->Divide(FirstDivide,2); - TwoDCanvas2->Divide(FirstDivide,2); - CRDC1->Divide(FirstDivide,2); - CRDC2->Divide(FirstDivide,2); - }else if(NumFiles%3==0){ + if(NumFiles%4==0){ + int FirstDivide = NumFiles/4; + TwoDCanvas1->Divide(FirstDivide,4); + TwoDCanvas2->Divide(FirstDivide,4); + CRDC1->Divide(FirstDivide,4); + CRDC2->Divide(FirstDivide,4); + }else if(NumFiles%3==0 && NumFiles%4!=0){ int FirstDivide = NumFiles/3; TwoDCanvas1->Divide(FirstDivide,3); TwoDCanvas2->Divide(FirstDivide,3); CRDC1->Divide(FirstDivide,3); CRDC2->Divide(FirstDivide,3); - } else{ + }else if(NumFiles%2==0 && NumFiles%4!=0 && NumFiles%3!=0){ + int FirstDivide = NumFiles/2; + TwoDCanvas1->Divide(FirstDivide,2); + TwoDCanvas2->Divide(FirstDivide,2); + CRDC1->Divide(FirstDivide,2); + CRDC2->Divide(FirstDivide,2); + }else{ TwoDCanvas1->Divide(NumFiles); TwoDCanvas2->Divide(NumFiles); CRDC1->Divide(NumFiles); CRDC2->Divide(NumFiles); } - + + + int low1 = 0; + int low2 = 0; + int high1 = 0; + int high2 = 0; if(low==0 && high==0){ - low=-400; - high=400; + low1 =-400; + high1 =400; + low2 =-400; + high2 =400; + }else{ + low1 =low; + high1 =high; + low2 =-low; + high2 =-high; + } + double lowRun=0,highRun=0; double lowCent1=0,highCent1=0; double lowCent2=0,highCent2=0; @@ -469,10 +641,14 @@ TList *CheckCalibratedCRDCY(int low=0,int high=0){ Line0->SetLineStyle(kDashed); Line0->SetLineWidth(3); CRDC1_Y_vs_S800Timestamp->SetTitle(Form("CRDC1 Calibrated Y Run%s vs Timestamp",run.c_str())); + if(UseZoom) + CRDC1_Y_vs_S800Timestamp->GetYaxis()->SetRangeUser(low1-10,high1+10); CRDC1_Y_vs_S800Timestamp->Draw(); Line0->Draw("same"); TwoDCanvas2->cd(i+1); CRDC2_Y_vs_S800Timestamp->SetTitle(Form("CRDC2 Calibrated Y Run%s vs Timestamp",run.c_str())); + if(UseZoom) + CRDC2_Y_vs_S800Timestamp->GetYaxis()->SetRangeUser(low2-10,high2+10); CRDC2_Y_vs_S800Timestamp->Draw(); Line0->Draw("same"); @@ -494,9 +670,14 @@ TList *CheckCalibratedCRDCY(int low=0,int high=0){ Line1->SetLineStyle(kDashed); Line1->SetLineWidth(3); Line1->Draw("Same"); - GausFit(Proj1,low,high); - double Cent1 = GetCentroid(Proj1); + if(!UseMean){ + GGaus *g1 = GausFit(Proj1,low1,high1); + double Cent1 = g1->GetCentroid();//(Proj1); + } else{ + double Cent1 = Proj1->GetMean(1); + } CRDC1_Y_Centroid.push_back(Cent1); + RunNumbers.push_back(runNumb); Proj1->SetTitle(Form("CRDC1 Calibrated Y Run%s Centoid = %.4f",run.c_str(),Cent1)); CRDC1Graph->SetPoint(i,runNumb,Cent1); @@ -507,8 +688,12 @@ TList *CheckCalibratedCRDCY(int low=0,int high=0){ Line2->SetLineStyle(kDashed); Line2->SetLineWidth(3); Line2->Draw("same"); - GausFit(Proj2,low,high); - double Cent2 = GetCentroid(Proj2); + if(!UseMean){ + GGaus *g2 = GausFit(Proj2,low2,high2); + double Cent2 = g2->GetCentroid();//Proj2); + } else{ + double Cent2 = Proj2->GetMean(1); + } CRDC2_Y_Centroid.push_back(Cent2); Proj2->SetTitle(Form("CRDC2 Calibrated Y Run%s Centoid = %.4f",run.c_str(),Cent2)); CRDC2Graph->SetPoint(i,runNumb,Cent2); @@ -691,8 +876,8 @@ TList *CheckUnShiftedCRDCY(int low=0,int high=0){ Line1->SetLineStyle(kDashed); Line1->SetLineWidth(3); Line1->Draw("Same"); - GausFit(Proj1,low1,high1); - double Cent1 = GetCentroid(Proj1); + GGaus *g1 = GausFit(Proj1,low1,high1); + double Cent1 = g1->GetCentroid();//Proj1); Proj1->SetTitle(Form("CRDC1 UnShifted Y Run%s Centoid = %.2f",run.c_str(),Cent1)); CRDC1Graph->SetPoint(i,runNumb,Cent1); @@ -703,8 +888,8 @@ TList *CheckUnShiftedCRDCY(int low=0,int high=0){ Line2->SetLineStyle(kDashed); Line2->SetLineWidth(3); Line2->Draw("same"); - GausFit(Proj2,low2,high2); - double Cent2 = GetCentroid(Proj2); + GGaus *g2 = GausFit(Proj2,low2,high2); + double Cent2 = g2->GetCentroid();//Proj2); Proj2->SetTitle(Form("CRDC2 UnShifted Y Run%s Centoid = %.2f",run.c_str(),Cent2)); CRDC2Graph->SetPoint(i,runNumb,Cent2); @@ -852,8 +1037,8 @@ TList *CheckRawCrdcY(int low=0,int high=0){ Line1->SetLineStyle(kDashed); Line1->SetLineWidth(3); //Line1->Draw("Same"); - GausFit(Proj1,low,high); - double Cent1 = GetCentroid(Proj1); + GGaus *g1 = GausFit(Proj1,low,high); + double Cent1 = g1->GetCentroid();//Proj1); Proj1->SetTitle(Form("CRDC1 Raw Y Run%s Centoid = %.2f",run.c_str(),Cent1)); CRDC1Graph->SetPoint(i,runNumb,Cent1); @@ -864,8 +1049,8 @@ TList *CheckRawCrdcY(int low=0,int high=0){ Line2->SetLineStyle(kDashed); Line2->SetLineWidth(3); //Line2->Draw("same"); - GausFit(Proj2,low,high); - double Cent2 = GetCentroid(Proj2); + GGaus *g2 = GausFit(Proj2,low,high); + double Cent2 = g2->GetCentroid();//Proj2); Proj2->SetTitle(Form("CRDC2 Raw Y Run%s Centoid = %.2f",run.c_str(),Cent2)); CRDC2Graph->SetPoint(i,runNumb,Cent2); diff --git a/util/Check_TOF.C b/util/Check_TOF.C new file mode 100644 index 00000000..3adb4386 --- /dev/null +++ b/util/Check_TOF.C @@ -0,0 +1,122 @@ +//std::vector Proj_vect; + +TList *CheckTOF_vs_Time(double lineX1=0,double lineX2=6000,double lineY1=-1050,double lineY2=-1050){ + TList *HistList = new TList; + TList *FileList = gROOT->GetListOfFiles(); + int NumFiles = FileList->GetSize(); + TLegend *leg = new TLegend(0.2,0.2,0.5,0.5); + TLegend *leg2 = new TLegend(0.2,0.2,0.5,0.5); + + int MostEvents_Location = 0; + int MostEvents = 0; + + TCanvas *TwoDCanvas = new TCanvas("TwoDCanvas","2D Canvas TOF vs S800 Timestamp"); + TCanvas *ProjCanvas = new TCanvas("ProjCanvas","1D TOF Projection"); + TCanvas *StackCanvas = new TCanvas("StackCanvas","1D TOF Projection Stacked"); + TCanvas *ScaledCanv = new TCanvas("ScaledCanv","Scaled Canvas"); + if(NumFiles%4==0){ + int FirstDivide = NumFiles/4; + TwoDCanvas->Divide(FirstDivide,4); + ProjCanvas->Divide(FirstDivide,4); + }else if(NumFiles%3==0 && NumFiles%4!=0){ + int FirstDivide = NumFiles/3; + TwoDCanvas->Divide(FirstDivide,3); + ProjCanvas->Divide(FirstDivide,3); + }else if(NumFiles%2==0 && NumFiles%4!=0 && NumFiles%3!=0){ + int FirstDivide = NumFiles/2; + TwoDCanvas->Divide(FirstDivide,2); + ProjCanvas->Divide(FirstDivide,2); + }else{ + TwoDCanvas->Divide(NumFiles); + ProjCanvas->Divide(NumFiles); + } + + for(int i=0;iAt(i); + + string FileName = WorkingFile->GetName(); + cout << " File Name = " << FileName << endl; + size_t found = FileName.find_last_of("."); + string run = FileName.substr(found-4,4); + stringstream runSS; + double runNumb =0; + runSS << run; + runSS >> runNumb; + if(runNumb==0){ + run = FileName.substr(found-3,3); + stringstream runSS2; + runSS2 << run; + runSS2 >> runNumb; + } + + if(runNumb==0){ + run = FileName.substr(found-2,2); + stringstream runSS3; + runSS3 << run; + runSS3 >> runNumb; + } + + if(runNumb==0){ + run = FileName.substr(found-1,1); + stringstream runSS3; + runSS3 << run; + runSS3 >> runNumb; + } + + + + WorkingFile->cd("CorrelatedMESY"); + TwoDCanvas->cd(i+1); + TOF_vs_S800Timestamp->SetTitle(Form("Corrected OBJ TOF vs S800 Timestamp Run %s",run.c_str())); + TOF_vs_S800Timestamp->GetYaxis()->SetRangeUser(-1050,-900); + TOF_vs_S800Timestamp->Draw(); + TLine *line1 = new TLine(lineX1,lineY1,lineX2,lineY2); + line1->SetLineStyle(kDashed); + line1->SetLineWidth(3); + line1->Draw(); + GH1D *Proj1 = TOF_vs_S800Timestamp->ProjectionY(Form("Corrected OBJ TOF Run %s",run.c_str())); + Proj1->SetTitle(Form("Corrected OBJ TOF Run %s",run.c_str())); + double Proj1_yMax = Proj1->GetMaximum(); + ProjCanvas->cd(i+1); + Proj1->Draw(); + + StackCanvas->cd(); + Proj1->SetLineColor(i+1); + Proj1->SetTitle(""); + leg->AddEntry(Proj1,Form("Run%s",run.c_str()),"l"); + if(i==0) + Proj1->Draw(); + else + Proj1->Draw("same"); + + GH1D *Proj_Clone = (GH1D*)Proj1->Clone(); + if(i<4){ + Proj_Clone->SetLineColor(i%4+1); + + }else if(i>3 && i<8){ + Proj_Clone->SetLineColor(i%4+1); + Proj_Clone->SetLineStyle(2); + }else if(i>7 && i<12){ + Proj_Clone->SetLineColor(i%4+1); + Proj_Clone->SetLineStyle(3); + }else{ + Proj_Clone->SetLineColor(i%4+1); + Proj_Clone->SetLineStyle(4); + } + + ScaledCanv->cd(); + Proj_Clone->Scale(1.0/Proj_Clone->Integral()); + if(i==0) + Proj_Clone->Draw(); + else + Proj_Clone->Draw("same"); + + leg2->AddEntry(Proj_Clone,Form("Run%s",run.c_str()),"l"); + } + + + StackCanvas->cd(); + leg->Draw("same"); + ScaledCanv->cd(); + leg2->Draw("same"); +} diff --git a/util/FitRawY.cxx b/util/FitRawY.cxx index 92266347..54257dd8 100644 --- a/util/FitRawY.cxx +++ b/util/FitRawY.cxx @@ -8,6 +8,7 @@ #include "TH1.h" #include "TList.h" #include "TH2.h" +#include "GH2.h" #include "TF1.h" #include "TGraphErrors.h" #include "TMath.h" @@ -42,8 +43,12 @@ TList *FitRawY(TH1 *hist,bool draw=false,bool is_core=false,double threshold=.18 } list = new TList; list->Add(hist); + //std::cout << "(1) I am crashing here, dude!" << std::endl ; TH1 *newhist = (TH1*)hist->Clone(Form("%s_bgsub",hist->GetName())); + //std::cout << "(1++) I am crashing here, dude!" << std::endl ; if(sub) { + + //std::cout << "(2) I am crashing here, dude!" << std::endl ; TH1 *bg = hist->ShowBackground(100,""); bg->SetNameTitle(Form("%s_bg",hist->GetName()),Form("%s_bg",hist->GetName())); list->Add(bg); @@ -53,9 +58,12 @@ TList *FitRawY(TH1 *hist,bool draw=false,bool is_core=false,double threshold=.18 list->Add(newhist); if(is_core){ + // std::cout << "(3) I am crashing here, dude!" << std::endl ; hist->GetXaxis()->SetRangeUser(500,hist->GetXaxis()->GetXmax()); newhist->GetXaxis()->SetRangeUser(500,newhist->GetXaxis()->GetXmax()); + } else { + // std::cout << "(4) I am crashing here, dude!" << std::endl ; hist->GetXaxis()->SetRangeUser(2000,hist->GetXaxis()->GetXmax()); newhist->GetXaxis()->SetRangeUser(2000,newhist->GetXaxis()->GetXmax()); } @@ -196,7 +204,9 @@ TH2 *MakeFWHMSummary(TH2 *hist,int hole,int cryl){ } */ -TList *MakeSummary(TH2 *hist,int qnum){ +// changed this to GH2. Was TH2 (06/04/19 - Mark). + +TList *MakeSummary(GH2 *hist,int qnum){ if(!hist) return 0; TList *list = new TList; @@ -222,7 +232,10 @@ TList *MakeSummary(TH2 *hist,int qnum){ std::string HistName = Form("%s_%i",hist->GetName(),i); printf("%s\n",HistName.c_str()); - TH1D *raw = hist->ProjectionY(HistName.c_str(),i,i); + +// We had to add (TH1D*) to make this work. 06/04/19 (Mark) + + TH1D *raw = (TH1D*)hist->ProjectionY(HistName.c_str(),i,i); fit_attempts = 0; TList *fit_list; @@ -341,7 +354,10 @@ int my_function(const char *filename) { // break; TKey *key = (TKey*)(file->GetListOfKeys()->At(x)); if(TClass::GetClass(key->GetClassName())->InheritsFrom("TH2")) { - TH2 *h = (TH2*)key->ReadObj(); + +// changed this to GH2. Was TH2 (06/04/19 - Mark). + + GH2 *h = (GH2*)key->ReadObj(); string name = h->GetName(); //int hole = atoi(name.substr(4,2).c_str()); //int cryl = atoi(name.substr(7,1).c_str()); diff --git a/util/MakeCaesarCalibrationHists.cxx b/util/MakeCaesarCalibrationHists.cxx deleted file mode 100644 index 4927c77a..00000000 --- a/util/MakeCaesarCalibrationHists.cxx +++ /dev/null @@ -1,139 +0,0 @@ -#define N_RINGS 10 -#define MAX_DETS 24 - -//CHANGE THIS -#define NUM_FILES 4 -#include -#include -#include -#include -#include "TTree.h" -#include "TCaesar.h" -#include "TCaesarHit.h" -#include "GValue.h" -#include "TChannel.h" -#include "TFile.h" -#include "TH1D.h" - -//Usage: makeCalibrationHists input_file_list.dat output_hists.root -//input_file_list should contain the list of files that will be used for the calibration - -//NUM_FILES, run_numbers, and source_names must be changed by hand! -int main(int argc, char *argv[]){ - if (argc < 3){ - std::cout << "Usaged: MakeCalibrationHists input_filelist.dat output_file.root" << std::endl; - return -1; - } - - //CHANGE THIS - std::string source_name[NUM_FILES] = { - "cs137", - "y88", - "ba133", - "co60" - }; - - //CHANGE THIS - int run_numbers[NUM_FILES] = { - 24,25,26,27 - }; - int det_per_ring[N_RINGS] = { - 10, 14, 24, 24, 24, - 24, 24, 24, 14, 10 - }; - - std::vector input_file_names; - std::vector files; - std::string line; - std::ifstream input_file; - - TH1D* output_hists[NUM_FILES][N_RINGS][MAX_DETS]; - TFile *out_file = new TFile(argv[2], "recreate"); - - TCaesar *caesar = 0; - - Int_t det; - Int_t ring; - Int_t n_gamma; - Int_t n_entries; - Double_t energy; - - Int_t hist_high_x = 4096; - Int_t hist_low_x = 0; - Int_t hist_n_bins_x = hist_high_x; - - - //open cut file and background files. Cut file will be used to apply - //time cut to each histogram. - - //Open list of files to parse - input_file.open(argv[1]); - if (!input_file.is_open()){ - std::cout << "Failed opening file!" << std::endl; - return 1; - } - - while (std::getline(input_file, line)){ - input_file_names.push_back(line); - } - input_file.close(); - - for (unsigned int i = 0; i < input_file_names.size(); i++){ - files.push_back(new TFile(input_file_names.at(i).c_str(),"read")); - } - if (files.size() != NUM_FILES){ - std::cout << "ERROR: Found incorrect number of files!" << std::endl; - } - - //Make all histograms with format: - //sourcename_ring_#_det_# - for (int file = 0; file < NUM_FILES; file++){ - for (int ring = 0; ring < N_RINGS; ring++){ - for (int det = 0; det < det_per_ring[ring]; det++){ - output_hists[file][ring][det] = new TH1D(Form("%s_run_%d_ring_%d_det_%d",source_name[file].c_str(), run_numbers[file],ring,det), - Form("%s_run_%d_ring_%d_det_%d",source_name[file].c_str(), run_numbers[file],ring,det), hist_n_bins_x, hist_low_x, hist_high_x); - output_hists[file][ring][det]->SetDirectory(out_file); - } - } - } - - - Int_t cur_source = 0; - for (unsigned int file = 0; file < NUM_FILES; file++){ - std::cout << "Currently parsing tree from: " << input_file_names.at(file) << std::endl; - TTree *cur_tree = (TTree*)files.at(file)->Get("EventTree"); - cur_tree->SetBranchAddress("TCaesar", &caesar); - GValue *gvalues = (GValue*)files.at(file)->Get("GValue"); - TChannel *tchannels = (TChannel*)files.at(file)->Get("TChannel"); - if (!gvalues || !tchannels){ - std::cout << "Missing GValue or TChannel for file = " << file << std::endl; - } - n_entries = cur_tree->GetEntries(); - for (int entry = 0; entry < n_entries; entry++){ - caesar->Clear(); - cur_tree->GetEvent(entry); - if (!caesar){ - continue; - } - - n_gamma = caesar->Size(); - for (int gamma = 0; gamma < n_gamma; gamma++){ - TCaesarHit hit = caesar->GetCaesarHit(gamma); - if (!hit.IsValid()){ - continue; - } - energy = hit.Charge();//raw data, no calibrations - det = hit.GetDetectorNumber(); - ring = hit.GetRingNumber(); - output_hists[cur_source][ring][det]->Fill(energy); - }//cycle through gamma multiplicity - }//cycle through tree entries - std::cout << "Finished with file: " << input_file_names.at(file) << std::endl; - cur_source += 1; - delete cur_tree; - }//cycle through files in chain - - out_file->Write(); - out_file->Close(); -} - diff --git a/util/MakeCaesarCalibrationHists_Brandon.cxx b/util/MakeCaesarCalibrationHists_Brandon.cxx deleted file mode 100644 index d8eb2555..00000000 --- a/util/MakeCaesarCalibrationHists_Brandon.cxx +++ /dev/null @@ -1,154 +0,0 @@ -#define N_RINGS 10 -#define MAX_DETS 24 - -//CHANGE THIS -#define NUM_FILES 4 -#include -#include -#include -#include -#include "TTree.h" -#include "TCaesar.h" -#include "TCaesarHit.h" -#include "GValue.h" -#include "TChannel.h" -#include "TFile.h" -#include "TH1D.h" -#include "TCutG.h" - -//Usage: makeCalibrationHists input_file_list.dat output_hists.root -//input_file_list should contain the list of files that will be used for the calibration - -//NUM_FILES, run_numbers, and source_names must be changed by hand! -int main(int argc, char *argv[]){ - if (argc < 3){ - std::cout << "Usaged: MakeCalibrationHists input_filelist.dat output_file.root" << std::endl; - return -1; - } - - //CHANGE THIS - std::string source_name[NUM_FILES] = { - "na22", - "y88", - "co60", - "cs137" - }; - - //CHANGE THIS - int run_numbers[NUM_FILES] = { - 363,362,366,365 - }; - int det_per_ring[N_RINGS] = { - 10, 14, 24, 24, 24, - 24, 24, 24, 14, 10 - }; - - std::vector input_file_names; - std::vector files; - std::string line; - std::ifstream input_file; - - TH1D* output_hists[NUM_FILES][N_RINGS][MAX_DETS]; - TFile *out_file = new TFile(argv[2], "recreate"); - - TCaesar *caesar = 0; - - Int_t det; - Int_t ring; - Int_t n_gamma; - Int_t n_entries; - Double_t charge; - Double_t time; - - Int_t hist_high_x = 2048; - Int_t hist_low_x = 0; - Int_t hist_n_bins_x = hist_high_x; - - - //Open cut file for TCut - TFile *cut_file = new TFile("/mnt/analysis/pecan-gade/elman/source_runs_endofexperiment/tcut_file_endofexp.root","read"); - if (!cut_file){ - std::cout << "Failed to open cut file" << std::endl; - return 1; - } - TCutG *tcut = (TCutG*)cut_file->Get("sample_tcut"); - if (!tcut){ - std::cout << "Failed to get tcut file" << std::endl; - return 1; - } - - //Open list of files to parse - input_file.open(argv[1]); - if (!input_file.is_open()){ - std::cout << "Failed opening file!" << std::endl; - return 1; - } - - while (std::getline(input_file, line)){ - input_file_names.push_back(line); - } - input_file.close(); - - for (unsigned int i = 0; i < input_file_names.size(); i++){ - files.push_back(new TFile(input_file_names.at(i).c_str(),"read")); - } - if (files.size() != NUM_FILES){ - std::cout << "ERROR: Found incorrect number of files ("<SetDirectory(out_file); - } - } - } - - - Int_t cur_source = 0; - for (unsigned int file = 0; file < NUM_FILES; file++){ - std::cout << "Currently parsing tree from: " << input_file_names.at(file) << std::endl; - TTree *cur_tree = (TTree*)files.at(file)->Get("EventTree"); - cur_tree->SetBranchAddress("TCaesar", &caesar); - -// GValue *gvalues = (GValue*)files.at(file)->Get("GValue"); - TChannel *tchannels = (TChannel*)files.at(file)->Get("TChannel"); - if (!tchannels){ - std::cout << "Missing GValue or TChannel for file = " << file << std::endl; - } - - n_entries = cur_tree->GetEntries(); - for (int entry = 0; entry < n_entries; entry++){ - caesar->Clear(); - cur_tree->GetEvent(entry); - if (!caesar){ - continue; - } - n_gamma = caesar->Size(); - for (int gamma = 0; gamma < n_gamma; gamma++){ - TCaesarHit hit = caesar->GetCaesarHit(gamma); - if (!hit.IsValid() || hit.IsOverflow()){ - continue; - } - charge = hit.Charge();//raw data, no calibrations - time = hit.GetTime(); - det = hit.GetDetectorNumber(); - ring = hit.GetRingNumber(); - if (tcut->IsInside(time, charge)){ - output_hists[cur_source][ring][det]->Fill(charge); - } - }//cycle through gamma multiplicity - }//cycle through tree entries - std::cout << "Finished with file: " << input_file_names.at(file) << std::endl; - cur_source += 1; - delete cur_tree; - }//cycle through files in chain - - out_file->Write(); - out_file->Close(); -} - diff --git a/util/Root2Rad.cxx b/util/Root2Rad.cxx new file mode 100644 index 00000000..5609f0af --- /dev/null +++ b/util/Root2Rad.cxx @@ -0,0 +1,375 @@ +// g++ Root2Rad.cxx `root-config --cflags --libs` -oRoot2Rad +// +// Author: P.C. Bender, +// * +// * * Please indicate changes with your initials. +// * +// +// Short and sweet program. Finds all the 1d (and 2d) histograms in a tfile by +// itterating over the keys, than turn each of them into a fortran formatted +// .spei/.mat file used by radware. +// +// If histograms are larger than 16384 bins, it trys to be smart to decide +// whether to truncate or compress the hist to fit the 16384 radwar limit. +// +// Matrices are all truncated to 4096 or padded to 4096 if there are to few +// bins. +// +// +// to compile: +// g++ Root2Rad.cxx -oRoot2Rad `root-config --cflags --libs` +// +// to run: +// ./Root2Rad rootfile.root +// + +#include +#include +#include + +#include + +#include +#include + +#include "TFile.h" +#include "TH1.h" +#include "TH2.h" +#include "TSystem.h" +#include "TList.h" +#include "TClass.h" +#include "TKey.h" +#include "TTimeStamp.h" +#include "THnSparse.h" + +#include "Globals.h" +//#include "GHSym.h" + +struct SpeHeader { + int32_t buffsize; /*fortran file, each record starts with record size */ // 14 + char label[8]; + int32_t size; + int32_t junk1; + int32_t junk2; + int32_t junk3; + int32_t buffcheck; /*fortran file, record ends with record size :) */ // 14 +} __attribute__((packed)); + +// the above would be followed by an integer of bin size * 4 +// the value of all bins in int sizes +// an integer os bin size * 4 ------- number of char in the histogram. + +void AddToList(TList*, TH2*, bool, bool); +void WriteHist(TH1*, std::fstream*); +void WriteMat(TH2*, std::fstream*); +void WriteM4b(TH2*, std::fstream*); +void WriteM8k(TH2*, std::fstream*); + +int main(int argc, char** argv) +{ + TFile* infile = nullptr; + if(argc < 2 || (infile = TFile::Open(argv[1], "read")) == nullptr) { + std::cout<<"problem opening file."<GetName(); + path.erase(path.find_last_of('.')); + +#if defined(OS_DARWIN) + struct stat st = {0, 0, 0, 0, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, {0, 0}, 0, 0, 0, 0, 0, 0, {0}}; +#elif defined(__clang__) + struct stat st = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, {0, 0}}; +#else + struct stat st = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +#endif + + if(stat(path.c_str(), &st) == -1) { + mkdir(path.c_str(), 0755); + } + + // std::string outfilename = infile->GetName(); + // outfilename.erase(outfilename.find_last_of('.')); + // outfilename.append(".spe"); + // std::fstream outfile; + // outfile.open(outfilename.c_str(), std::ios::out | std::ios::binary); + + TList* keys = infile->GetListOfKeys(); + keys->Sort(); + TIter next(keys); + auto* histsToWrite = new TList(); + auto* matsToWrite = new TList(); + auto* m4bsToWrite = new TList(); + // int counter = 1; + while(TKey* currentkey = dynamic_cast(next())) { + std::string keytype = currentkey->ReadObj()->IsA()->GetName(); + if(keytype.compare(0, 3, "TH1") == 0) { + // printf("%i currentkey->GetName() = %s\n",counter++, currentkey->GetName()); + // if((counter-1)%4==0) + // printf("*****************************\n"); + histsToWrite->Add(currentkey->ReadObj()); + } else if(keytype.compare(0, 4, "TH2C") == 0 || keytype.compare(0, 4, "TH2S") == 0) { + AddToList(matsToWrite, dynamic_cast(currentkey->ReadObj()), split, compress); + } else if(keytype.compare(0, 3, "TH2") == 0) { + AddToList(m4bsToWrite, dynamic_cast(currentkey->ReadObj()), split, compress); + } else if(keytype.compare(0, 3, "THn") == 0) { + THnSparse* hist = (dynamic_cast(currentkey->ReadObj())); + if(hist->GetNdimensions() == 1) { + histsToWrite->Add(hist->Projection(0)); + } else if(hist->GetNdimensions() == 2) { + if(keytype.compare(17, 1, "C") == 0 || keytype.compare(17, 1, "S") == 0) { + AddToList(matsToWrite, hist->Projection(0, 1), split, compress); + } else { + AddToList(m4bsToWrite, hist->Projection(0, 1), split, compress); + } + } + } else { + std::cout<<"skipping "<GetSize() = %i\n", histsToWrite->GetSize()); + + TIter nexthist(histsToWrite); + while(TH1* currenthist = dynamic_cast(nexthist())) { + std::string outfilename = path + "/"; + outfilename.append(currenthist->GetName()); + outfilename.append(".spe"); + std::fstream outfile; + outfile.open(outfilename.c_str(), std::ios::out | std::ios::binary); + WriteHist(currenthist, &outfile); + printf("\t%s written to file %s.\n", currenthist->GetName(), outfilename.c_str()); + outfile.close(); + } + + TIter nextmat(matsToWrite); + while(TH2* currentmat = dynamic_cast(nextmat())) { + std::string outfilename = path + "/"; + outfilename.append(currentmat->GetName()); + outfilename.append(".mat"); + std::fstream outfile; + outfile.open(outfilename.c_str(), std::ios::out | std::ios::binary); + WriteMat(currentmat, &outfile); + printf("\t%s written to file %s.\n", currentmat->GetName(), outfilename.c_str()); + outfile.close(); + } + + TIter nextm4b(m4bsToWrite); + while(TH2* currentm4b = dynamic_cast(nextm4b())) { + std::string outfilename = path + "/"; + outfilename.append(currentm4b->GetName()); + if(bigMatrix) { + outfilename.append(".m8k"); + } else { + outfilename.append(".m4b"); + } + std::fstream outfile; + outfile.open(outfilename.c_str(), std::ios::out | std::ios::binary); + if(bigMatrix) { + WriteM8k(currentm4b, &outfile); + } else { + WriteM4b(currentm4b, &outfile); + } + printf("\t%s written to file %s.\n", currentm4b->GetName(), outfilename.c_str()); + outfile.close(); + } + + // printf("closing file %s.\n",outfilename.c_str()); + // outfile.close(); + + return 0; +} + +void AddToList(TList* list, TH2* hist, bool split, bool compress) +{ + if((!split && !compress) || hist->GetXaxis()->GetNbins() <= 4096) { + list->Add(hist); + return; + } + if(split && compress) { + TH2* splitHist = static_cast(hist->IsA()->New()); + splitHist->SetBins(4096, 0., 4096., 4096, 0., 4096.); + splitHist->SetName(Form("%s_low", hist->GetName())); + for(int binx = 1; binx <= 4096; ++binx) { + for(int biny = 1; biny <= 4096; ++biny) { + // ignore overflow cells + if(binx <= hist->GetXaxis()->GetNbins() && biny <= hist->GetYaxis()->GetNbins()) { + splitHist->SetBinContent(binx, biny, hist->GetBinContent(binx, biny)); + } + } + } + list->Add(splitHist); + int rebin = (hist->GetXaxis()->GetNbins() + 4095) / 4096; + std::cout<<"rebinning "<GetName()<<" by "<Add(hist->Rebin2D(rebin, rebin)); + return; + } else if(split) { + int nofSplits = (hist->GetXaxis()->GetNbins() + 4095) / 4096; + TH2* splitHist = static_cast(hist->IsA()->New()); + splitHist->SetBins(4096, 0., 4096., 4096, 0., 4096.); + for(int i = 0; i < nofSplits; ++i) { + for(int j = 0; j <= i; ++j) { + std::cout<GetName()<<": x = "<Reset(); + splitHist->SetName(Form("%s_%d_%d", hist->GetName(), i, j)); + for(int binx = 1; binx <= 4096; ++binx) { + for(int biny = 1; biny <= 4096; ++biny) { + // ignore overflow cells + if(i * 4096 + binx <= hist->GetXaxis()->GetNbins() && + j * 4096 + biny <= hist->GetYaxis()->GetNbins()) { + splitHist->SetBinContent(binx, biny, hist->GetBinContent(i * 4096 + binx, j * 4096 + biny)); + } + } + } + list->Add(splitHist->Clone(Form("%s_%d_%d", hist->GetName(), i, j))); + } + } + return; + } + // only option left now is compress + int rebin = (hist->GetXaxis()->GetNbins() + 4095) / 4096; + std::cout<<"rebinning "<GetName()<<" by "<SetName(Form("%s_rebin%d", hist->GetName(), rebin)); + list->Add(hist->Rebin2D(rebin, rebin)); +} + +void WriteMat(TH2* mat, std::fstream* outfile) +{ + int xbins = mat->GetXaxis()->GetNbins(); + int ybins = mat->GetYaxis()->GetNbins(); + + auto* empty = new TH1D("empty", "empty", 4096, 0., 4096.); + + for(int y = 1; y <= 4096; ++y) { + uint16_t buffer[4096] = {0}; + TH1D* proj; + if(y <= ybins) { + proj = mat->ProjectionX("proj", y, y); + } else { + proj = empty; + } + for(int x = 1; x <= 4096; ++x) { + if(x <= xbins) { + buffer[x - 1] = static_cast(proj->GetBinContent(x)); // mat->GetBinContent(x,y)); + } else { + buffer[x - 1] = 0; + } + } + outfile->write(reinterpret_cast(&buffer), sizeof(buffer)); + } + delete empty; +} + +void WriteM4b(TH2* mat, std::fstream* outfile) +{ + int xbins = mat->GetXaxis()->GetNbins(); + int ybins = mat->GetYaxis()->GetNbins(); + + auto* empty = new TH1D("empty", "empty", 4096, 0., 4096.); + + for(int y = 1; y <= 4096; ++y) { + uint32_t buffer[4096] = {0}; + TH1D* proj; + if(y <= ybins) { + proj = mat->ProjectionX("proj", y, y); + } else { + proj = empty; + } + for(int x = 1; x <= 4096; ++x) { + if(x <= xbins) { + buffer[x - 1] = static_cast(proj->GetBinContent(x)); // mat->GetBinContent(x,y)); + } else { + buffer[x - 1] = 0; + } + } + outfile->write(reinterpret_cast(&buffer), sizeof(buffer)); + } + delete empty; +} + +void WriteM8k(TH2* mat, std::fstream* outfile) +{ + int xbins = mat->GetXaxis()->GetNbins(); + int ybins = mat->GetYaxis()->GetNbins(); + + auto* empty = new TH1D("empty", "empty", 8192, 0., 8192.); + + for(int y = 1; y <= 8192; ++y) { + uint32_t buffer[8192] = {0}; + TH1D* proj; + if(y <= ybins) { + proj = mat->ProjectionX("proj", y, y); + } else { + proj = empty; + } + for(int x = 1; x <= 8192; ++x) { + if(x <= xbins) { + buffer[x - 1] = static_cast(proj->GetBinContent(x)); // mat->GetBinContent(x,y)); + } else { + buffer[x - 1] = 0; + } + } + outfile->write(reinterpret_cast(&buffer), sizeof(buffer)); + } + delete empty; +} + +void WriteHist(TH1* hist, std::fstream* outfile) +{ + SpeHeader spehead; + spehead.buffsize = 24; + strncpy(spehead.label, hist->GetName(), 8); + + if(hist->GetRMS() > 16384 / 2) { + while(hist->GetNbinsX() > 16384) { + hist = hist->Rebin(2); + printf(DBLUE "\t!! %s has been compressed by 2." RESET_COLOR "\n", hist->GetName()); + } + spehead.size = hist->GetNbinsX(); + } else if(hist->GetNbinsX() > 16384) { + spehead.size = 16384; + } else { + spehead.size = hist->GetNbinsX(); + } + + spehead.junk1 = 1; + spehead.junk2 = 1; + spehead.junk3 = 1; + spehead.buffcheck = 24; /*fortran file, record ends with record size :) */ // 14 + + outfile->write(reinterpret_cast(&spehead), sizeof(SpeHeader)); + + int32_t histsizeinbytes = spehead.size * 4; + + outfile->write(reinterpret_cast(&histsizeinbytes), sizeof(int32_t)); + float bin = 0.0; + for(int x = 1; x <= spehead.size; ++x) { + if(x <= hist->GetNbinsX()) { + bin = static_cast(hist->GetBinContent(x)); + outfile->write(reinterpret_cast(&bin), sizeof(int32_t)); + } else { + bin = 0.0; + outfile->write(reinterpret_cast(&bin), sizeof(int32_t)); + } + } + + outfile->write(reinterpret_cast(&histsizeinbytes), sizeof(int32_t)); +} diff --git a/util/correctCaesarTime.cxx b/util/correctCaesarTime.cxx deleted file mode 100644 index e293e3bd..00000000 --- a/util/correctCaesarTime.cxx +++ /dev/null @@ -1,148 +0,0 @@ -#include -#include -#include //for getenv and atoi -#include -#include - -#include "TChannel.h" -#include "TEnv.h" -#include "TH2D.h" -#include "TFile.h" -#include "TF1.h" -#include "TSpectrum.h" -#include "TCaesar.h" - -#define MAX_CHN 16 -#define MAX_VSN 12 -#define N_RINGS 10 //total number of rings -#define N_DETS 192 //total number of detectors - -//correctCaesarTime cycles through all the bins of the -//"time2d" histogram whose x-axis is the absolute detector number (see -//TCaesarHit::GetAbsoluteDetectorNumber()) and whose y-axis is the CAESAR raw times. -//It finds the centroid of the peak of the 1d projection and stores it in -//a file called "centroids.dat". It then computes the difference between -//all the centroids and the centroid of a detector that one wants to compare -//to, and gives the offsets in an output cal file. The offsets can either be -//relative to 0 or relative to the current offset in the input cal file by -//setting add_cur_offset to false or true, respectively. -// -//i.e. the reported offset for detector i will either be: -// centroid_compdet-centroid_i or (centroid_compdet-centroid_i)+TIMECOEFF_OFFSET -// -// -// INPUT: -// -// -// OUTPUT: -// -// - -void correctCaesarTime(TH2D* time2d, int comp_det, std::string cal_file_name, - bool subtract_current_offset=true){ - - TCaesar *caesar = new TCaesar();//this automatically fills the VSN mapping! - - TSpectrum peakfinder(1); - const int TOTAL_DET_IN_PREV_RINGS[10] = {0,10,24,48,72,96,120,144,168,182}; - const int FIT_PADDING = 30; //determines distance to left/right of peak for fitting - double centroids[N_DETS]; - std::string out_chan_filename("correctTimeOffsets.cal"); - - std::vector time_coeff;//for storing offsets before saving to file - if (!cal_file_name.empty()){ - TChannel::ReadCalFile(cal_file_name.c_str()); - } - - //First cycle through histogram and determine centroids - for (int bin= 1; bin <= N_DETS; bin++){ - TH1D *hist_1d = (TH1D*)time2d->ProjectionY("name",bin,bin); - if (!hist_1d){ - std::cout << "ERROR: Failed to get projection for bin " << bin << std::endl; - return; - } - //Setting axis range allows us to avoid including the overflow peak - hist_1d->GetXaxis()->SetRangeUser(50,800); - peakfinder.Search(hist_1d); - hist_1d->Fit("gaus","M","",peakfinder.GetPositionX()[0] - FIT_PADDING, - peakfinder.GetPositionX()[0] + FIT_PADDING); - - //Parameter 1 in "gaus" is the mean - centroids[bin-1] = ((TF1*)hist_1d->FindObject("gaus"))->GetParameter(1); - delete hist_1d; - } - - //Now cycle through cal file and enter the offsets! - for (int vsn = 0; vsn < MAX_VSN; vsn++){ - for (int chan = 0; chan < MAX_CHN; chan++){ - time_coeff.clear(); - int ring = caesar->vsnchn_ring_map_energy[vsn][chan]; - int det = caesar->vsnchn_det_map_energy[vsn][chan]; - double offset = 0; - unsigned int address = ((37<<24) + (vsn << 16)+ chan); - int absolute_detector_number = det+TOTAL_DET_IN_PREV_RINGS[ring]; - - TChannel *tchan; - //std::cout << "TChan : " << tchan <GetTimeCoeff(); - time_coeff[0] = offset+time_coeff.at(0); - tchan->SetTimeCoeff(time_coeff); - }//update current channel - else{ - tchan = new TChannel(Form("RING%02dDET%02d",ring,det), address); - time_coeff.push_back(offset); - time_coeff.push_back(1);//we don't want to change slope! - tchan->SetTimeCoeff(time_coeff); - TChannel::AddChannel(tchan); - }//no channel exists so add one to TChannel! - }//loop over channels - }//loop over VSN - - TChannel::WriteCalFile(out_chan_filename); - return; -} - -#ifndef __CINT__ -int main(int argc, char **argv){ - std::string usage("USAGE: correctCaesarTime [hist_file] [hist_name] "); - usage += "[Detector to Compare To] [Cal file name] "; - usage += "[Subtract Curr Offset?]"; - if (argc < 4 || argc > 6) { - std::cout << "incorrect number of arguments: " << argc << std::endl; - std::cout << usage << std::endl; - return -1; - } - - - TFile *input_file = new TFile(argv[1], "read"); - if (!input_file){ - std::cout << "Failed to open input file with name " << argv[1] << std::endl; - return -1; - } - TH2D *time2d_hist = (TH2D*)input_file->Get(argv[2]); - if (!time2d_hist){ - std::cout << "Failed to open input file with name " << argv[1] << std::endl; - return -1; - } - - int comp_det = atoi(argv[3]); - - if (argc == 6){ - std::string cal_file_name(argv[4]); - bool subtract_current_offset = (atoi(argv[5]) != 0); - correctCaesarTime(time2d_hist, comp_det, cal_file_name, subtract_current_offset); - } - if (argc == 5){ - std::string cal_file_name(argv[4]); - correctCaesarTime(time2d_hist, comp_det, cal_file_name, false); - } - if (argc == 4){ - correctCaesarTime(time2d_hist, comp_det, "", false); - } -} -#endif - diff --git a/util/detmap_Q9.txt b/util/detmap_Q9.txt new file mode 100644 index 00000000..a37067d4 --- /dev/null +++ b/util/detmap_Q9.txt @@ -0,0 +1,160 @@ +-0.00247653 0.362385 +0.00189623 0.345472 +-0.000222837 0.352354 +0.00432761 0.357245 +-26.0818 0.543887 +-0.000257153 0.350257 +0.0174223 0.357846 +0.00191742 0.342612 +0.000109158 0.361307 +-1.90877e-05 0.380487 +-0.000788567 0.357811 +0.00485535 0.34764 +0.0280939 0.358477 +0.00183122 0.355293 +-0.00111429 0.349756 +0.00128518 0.347231 +0.000339405 0.353359 +-0.00478447 0.338318 +0.0029152 0.351277 +0 -19516.4 +0.00173613 0.354244 +0.0024942 0.333286 +-0.00113684 0.352294 +0.00502636 0.352407 +0.00207796 0.320065 +-0.00112551 0.352464 +0.00256511 0.35515 +0.0177563 0.351511 +0.00196 0.359126 +-5.53415e-05 0.101303 +0.00623493 0.337427 +0.00450771 0.332889 +0.00183831 0.349666 +-23.252 0.61652 +0.000956157 0.349779 +0.0515287 0.355055 +0.014921 0.351821 +0.0017104 0.355598 +0.00166905 0.36164 +-1.4015e-05 0.191617 +0.00237521 0.336268 +-0.000511074 0.364066 +0.00132519 0.344512 +0.00104597 0.329958 +0.00464079 0.335146 +0.000808433 0.348852 +0.000407539 0.347271 +0.00058522 0.335413 +0.00406318 0.341122 +2.1218e-05 0.378884 +0.005648 0.336655 +0.00339422 0.325937 +-0.000300328 0.350374 +0.00208439 0.334707 +0.00168958 0.33124 +0.00396285 0.341828 +0.00222847 0.330667 +0.00406782 0.335056 +-0.00189308 0.324619 +3.3152e+21 7.24487e+34 +0.00313896 0.345332 +0.000470597 0.357769 +-7.90446 0.404422 +0.00475909 0.32448 +0.000817411 0.355717 +0.00280734 0.337444 +-0.00233642 0.354424 +0.00332824 0.338724 +-0.000401493 0.324757 +-2.32085e-06 0.0947295 +0.00135104 0.334037 +-8.38114e-05 0.339693 +-15.6026 0.537352 +-17.9673 0.604382 +0.00460161 0.349023 +-4.22037 0.624696 +0.0108382 0.331374 +0.0122194 0.3329 +0.00487435 0.341985 +1.20683e-05 0.182983 +0.00182033 0.348794 +0.000589364 0.350686 +0.000647784 0.346526 +0.00275696 0.339977 +-4.42438 0.416034 +-0.000104293 0.342175 +0.0039618 0.357802 +0.000711307 0.348552 +-0.000171065 0.358773 +-5.97803e-05 0.379095 +0.000731067 0.343748 +0.00183496 0.352887 +0.0337243 0.341684 +0.00396227 0.3301 +0.00660712 0.355933 +0.00041553 0.350493 +0.000273442 0.3563 +0.00020896 0.360596 +0.004783 0.327789 +0 -28284.1 +0.00228738 0.349998 +0.00805287 0.353811 +0.000815153 0.350647 +0.00201461 0.351161 +0.00188333 0.344819 +0.00125448 0.331411 +-0.000923123 0.356933 +-0.00230952 0.353238 +0.00354919 0.348779 +-4.17299e-06 0.0958468 +0.00494595 0.353208 +-0.0010928 0.362748 +0.00169421 0.328561 +-0.00468963 0.36428 +0.0023507 0.342643 +0.0119356 0.345905 +0.0101609 0.354732 +0.000299947 0.356683 +0.00104404 0.345682 +-3.54761e-05 0.185433 +0.00186038 0.334715 +0.00021339 0.320837 +0.00109578 0.340523 +0.00214335 0.324696 +0.000897812 0.337731 +0.00232424 0.336179 +0.00404958 0.330282 +0.00242459 0.320313 +0.00241281 0.34727 +-2.52127e-05 0.363844 +-0.00288828 0.325419 +-0.000310696 0.346047 +0.00625973 0.334854 +0.00704559 0.33473 +-0.000154769 0.332874 +0.00151536 0.34581 +0.00373869 0.323309 +0.00204981 0.328605 +0.00258009 0.335757 +-4.18396e-05 0.375615 +0.00194418 0.331966 +0.0112861 0.331065 +0.000991122 0.339162 +0.00505189 0.315029 +0.004352 0.333921 +0.0027608 0.33651 +0.00572112 0.337266 +0.00379039 0.349086 +0.00289571 0.337227 +-1.51917e-05 0.0932913 +0.00346942 0.337783 +0.000781996 0.33192 +0.00889731 0.343707 +0.0142388 0.351276 +-0.00609502 0.323104 +0.0124254 0.335903 +0.0296764 0.322222 +0.00668077 0.331295 +0.0144337 0.351096 +-6.70151e-05 0.182919 diff --git a/util/filtertree.C b/util/filtertree.C new file mode 100644 index 00000000..85d62348 --- /dev/null +++ b/util/filtertree.C @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include + + +void filterTree(TTree* gChain,const char* opf){ + TS800 *s800; + TGretina *gretina; + gChain->SetBranchAddress("TS800",&s800); + gChain->SetBranchAddress("TGretina",&gretina); + + Double_t tof; + Double_t dE; + Int_t ng; + Double_t gammae[20]; + Double_t tdiff[20]; + Double_t theta[20]; + + TFile *opfile = new TFile(opf,"RECREATE"); + TTree *opt = new TTree("opt","opt"); + opt->Branch("tof",&tof,"tof/D"); + opt->Branch("dE",&dE,"dE/D"); + opt->Branch("ng",&ng,"ng/I"); + opt->Branch("gammae",&gammae,"gammae[ng]/D"); + opt->Branch("tdiff",&tdiff,"tdiff[ng]/D"); + opt->Branch("theta",&theta,"theta[ng]/D"); + + for(long long i = 0; iGetEntries(); i++){ + gChain->GetEntry(i); + if(s800->Size() == 0 || gretina->Size() == 0) return; + + ng = gretina->Size(); + tof = s800->GetCorrTOF_OBJ_MESY(); + dE = s800->GetIonChamber().GetdE(&s800->GetCrdc(0)); + + for(size_t x = 0; xSize();x++){ + tdiff[x] = s800->Timestamp()-gretina->GetGretinaHit(x).Timestamp(); + gammae[x] = gretina->GetGretinaHit(x).GetEnergy(); + theta [x] = gretina->GetGretinaHit(x).GetTheta(); + } + opt->Fill(); + } + opt->Write(); + opfile->Close(); +} diff --git a/util/fitCoulexGRUT_Kr90all.cxx b/util/fitCoulexGRUT_Kr90all.cxx deleted file mode 100644 index 3c56e1a7..00000000 --- a/util/fitCoulexGRUT_Kr90all.cxx +++ /dev/null @@ -1,730 +0,0 @@ -#include -#include -#include -#include -#include - -#include "TF1.h" -#include "FitDoubleExpo_Gaus.C" -#include "TEnv.h" -#include "TH1.h" -#include "TH1F.h" -#include "TFile.h" -#include "TMath.h" -#include "TTree.h" -#include "TGraph.h" -#include "TCanvas.h" -#include "TLine.h" -#include "TSpline.h" -#include "TCutG.h" -#include "TStyle.h" -#include "TChannel.h" -#include "GValue.h" -#include "TLegend.h" -#include "TPaveText.h" - -#include "TCaesarHit.h" -#include "TS800Hit.h" -#include "TCaesar.h" -#include "TS800.h" - -#include "GH1D.h" -//This program takes as input a config file containing: -// - directory containing necessary input root tree files (INPUT_DIR) -// - number of parameters to use in the fit (NUM_PARS) -// - set of initial parameters for the fit (PAR.#) where # starts with 0 -// - file containing cuts (CUT_FILE_NAME) -// - Ranges for histogramming (DATA_LOW_X, DATA_HIGH_X) -// - Ranges for fitting (FIT_LOW_X, FIT_HIGH_X) -// - Binning (KEV_PER_BIN) - -//All files must contain a tree called "EventTree", i.e. they must be made by GRUTinizer. -//Usage: fitCoulex [CONFIG FILE] - - - -void getFileList(std::string &search_string, std::vector &file_list){ - glob_t glob_result; - - if (glob(search_string.c_str(),GLOB_ERR,NULL,&glob_result) == GLOB_NOMATCH){ - std::cout << "GLOB failed to find pattern matching: " << search_string << std::endl; - return; - } - - std::cout << "Found " << glob_result.gl_pathc << " files matching " << search_string << ":"<< std::endl; - for (unsigned int i = 0; i < glob_result.gl_pathc; ++i){ - file_list.push_back( glob_result.gl_pathv[i] ); - std::cout << "\t" << glob_result.gl_pathv[i] << std::endl; - } - - return; -} - -void getHistograms(std::vector &data_hists, std::vector &angles, - TFile *&input_file, const double START_ANGLE, - const double FINAL_ANGLE, const double ANGLE_STEPS, - int data_low_x, int data_high_x, int kev_per_bin){ - const int TOTAL_ANGLES = (FINAL_ANGLE-START_ANGLE)/ANGLE_STEPS + 1; - double temp_angle = START_ANGLE; - for (int i = 0; i < TOTAL_ANGLES; i++){ - std::stringstream ss; - ss << "fit_angle_" << temp_angle; - std::string data_hist_name = ss.str(); - input_file->cd("Fits"); -// input_file->Print(); - std::cout << "Getting histogram: " << data_hist_name << std::endl; - std::cout << (TH1F*)gDirectory->Get(data_hist_name.c_str()) << std::endl; - data_hists.push_back((TH1F*)gDirectory->Get(data_hist_name.c_str())); - if (data_hists.at(i)->GetNbinsX() != data_hists.at(i)->GetXaxis()->GetXmax()){ - std::cout << "Number of bins ("<GetNbinsX()<<") does not equal x-axis length (" - << data_hists.at(i)->GetXaxis()->GetXmax()<<") so should not rebin!" << std::endl; - exit(1); - } - data_hists.at(i)->GetXaxis()->SetRangeUser(data_low_x,data_high_x); - data_hists.at(i)->Rebin(kev_per_bin); - angles.push_back(temp_angle); - temp_angle += ANGLE_STEPS; - } -} - -void getGeantHistograms(std::vector &geant_hists, std::vector &geant_file_names){ - for (unsigned int i = 0; i < geant_file_names.size(); i++){ - TFile *geant_file = new TFile(geant_file_names.at(i).c_str(),"read"); - if (!geant_file){ - std::cout << "Failed loading geant file: " << geant_file_names.at(i) << std::endl; - return; - } - std::string geant_hist_name("all_dop"); - std::string geant_fep_hist_name("all_dop_fep"); - - TH1F *geant_fep_hist = (TH1F*)geant_file->Get(geant_fep_hist_name.c_str()); -// TH1F *geant_compton = (TH1F*)geant_hists.at(i*2)->Clone("geant_compton"); - TH1F *geant_compton = (TH1F*)(((TH1F*)geant_file->Get(geant_hist_name.c_str()))->Clone("geant_compton")); - if (i == 0){ - geant_hists.push_back( (TH1F*)geant_file->Get(geant_fep_hist_name.c_str())); - } -// else if (i == 1){ -// geant_hists.push_back( (TH1F*)geant_file->Get(geant_hist_name.c_str())); -// } - else{ - geant_hists.push_back( (TH1F*)geant_file->Get(geant_hist_name.c_str())); - } - geant_compton->Add(geant_fep_hist,-1); - geant_hists.push_back(geant_compton); - } - return; -} - -void getFiles(std::vector &files, std::vector &file_list){ - for (unsigned int i = 0; i < file_list.size(); i++){ - files.push_back(new TFile(file_list.at(i).c_str(),"read")); - } - if (files.size() != file_list.size()){ - std::cout << "Unexpected number of trees: " << files.size() - << " compared to number of files: " << file_list.size() << std::endl; - } - return; -} -int fitCoulex(const char *cfg_file_name){ - - ////////////////////////////////////////////////// - //All Variables - const int MAX_PARS = 15; - //These angles determine the maximum angle cut that will be used -//const double START_ANGLE = 2.4; -//const double FINAL_ANGLE = 2.4; - const double START_ANGLE = 180; - const double FINAL_ANGLE = 180; - const double ANGLE_STEPS = 0.1; - const int TOTAL_ANGLES = (FINAL_ANGLE-START_ANGLE)/ANGLE_STEPS + 1; - - double init_pars[MAX_PARS]; - for (int i = 0; i < MAX_PARS; i++){ - init_pars[i] = 0; - } - - TEnv *cfg = new TEnv(cfg_file_name); - std::vector file_list; - std::ofstream out_file; - - std::vector files; - std::vector data_hists; - //the structure of the geant vector will be: - //geant_hists.at(0) = fep geant hist for main peak - //geant_hists.at(1) = compton only (full - fep) - //geant_hists.at(2) = full geant hist for 2nd peak - //geant_hists.at(3) = compton for that 2nd peak - std::vector geant_hists; - std::vector angles; - data_hists.reserve(TOTAL_ANGLES);//Want one histogram for every angle cut - angles.reserve(TOTAL_ANGLES); - - //Fitting Arrays - double hist_constant[TOTAL_ANGLES][6]; - double fit_error[TOTAL_ANGLES]; - double chi_squared[TOTAL_ANGLES]; - - //Config File Settings - std::string isotope_name; - std::string input_file_name; - std::string out_file_name; - std::vector geant_file_names; - - int data_low_x; - int data_high_x; - int peak_low_x; - int peak_high_x; - int fit_low_x; - int fit_high_x; - - int kev_per_bin; - int num_pars; - int num_geant_files; - - ////////////////////////////////////////////////// - //Get configuration values from file - isotope_name = cfg->GetValue("ISOTOPE_NAME", ""); - if (isotope_name.empty()){ - std::cout << "ERROR: Failed to get ISOTOPE_NAME from cfg file: " << cfg_file_name << std::endl; - return -1; - } - input_file_name = cfg->GetValue("INPUT_FILE", ""); - if (input_file_name.empty()){ - std::cout << "ERROR: Failed to get INPUT_FILE from cfg file: " << cfg_file_name << std::endl; - return -1; - } - - out_file_name = cfg->GetValue("OUT_FILE_NAME", ""); - if (out_file_name.empty()){ - std::cout << "ERROR: Failed to get OUT_FILE_NAME from cfg file: " << cfg_file_name << std::endl; - return -1; - } - - num_geant_files = cfg->GetValue("NUM_GEANT_FILES", 0); - if (num_geant_files > 5 || num_geant_files < 1){ - std::cout << "ERROR: Failed to get correct number of geant files from cfg file: " << cfg_file_name << std::endl; - return -1; - } - - for (int i = 0; i < num_geant_files; i++){ - std::string geant_file_name = cfg->GetValue(Form("GEANT_FILE_NAME_%d",i), ""); - if (geant_file_name.empty()){ - std::cout << "ERROR: Failed to get GEANT_FILE_NAME_"<GetValue("DATA_LOW_X", -1); - if (data_low_x == -1){ - std::cout << "ERROR: Bad data_low_x Value : " << data_low_x << std::endl; - return -1; - } - data_high_x = cfg->GetValue("DATA_HIGH_X", 0); - if (data_high_x == 0){ - std::cout << "ERROR: Bad data_high_x Value : " << data_high_x << std::endl; - return -1; - } - peak_low_x = cfg->GetValue("PEAK_LOW_X", -1); - if (peak_low_x == -1){ - std::cout << "ERROR: Bad PEAK_LOW_X Value : " << peak_low_x << std::endl; - return -1; - } - peak_high_x = cfg->GetValue("PEAK_HIGH_X", 0); - if (peak_high_x == 0){ - std::cout << "ERROR: Bad PEAK_HIGH_X Value : " << peak_high_x << std::endl; - return -1; - } - fit_low_x = cfg->GetValue("FIT_LOW_X", -1); - if (fit_low_x == -1){ - std::cout << "ERROR: Bad fit_low_x Value : " << fit_low_x << std::endl; - return -1; - } - fit_high_x = cfg->GetValue("FIT_HIGH_X", 0); - if (fit_high_x == 0){ - std::cout << "ERROR: Bad fit_high_x Value : " << fit_high_x << std::endl; - return -1; - } - kev_per_bin = cfg->GetValue("KEV_PER_BIN", 0); - if (kev_per_bin == 0){ - std::cout << "ERROR: Bad kev_per_bin Value : " << kev_per_bin << std::endl; - return -1; - } - - num_pars = cfg->GetValue("NUM_PARS",0); - if (num_pars > 11 || num_pars < 8){ - std::cout << "ERROR: Bad NUM_PARS Value : " << num_pars << std::endl; - return -1; - } - - std::cout << "Using " << num_pars << " parameters: " << std::endl; - for (int i = 0; i < num_pars; i++){ - init_pars[i] = cfg->GetValue(Form("PAR.%d", i), 0.0); - std::cout << "Parameter " << i << " = " << init_pars[i] << std::endl; - if (TMath::Abs(init_pars[i]) < 1e-08){ - std::cout << "ERROR: Failed to get parameter = " << i - << " from cfg file with num_pars = " << num_pars << std::endl; - return -1; - } - } - - //Finished parsing cfg file - //////////////////////////////////////////////////////////////////////////////////////////////////// - - //Open file containing histograms - std::cout << "Opening input file: " << input_file_name.c_str() << std::endl; - TFile *input_file = new TFile(input_file_name.c_str(), "read"); - if (!input_file){ - std::cout << "ERROR: Failed to open input file." << std::endl; - return -1; - } - - //Open Output file which will contain the histogram results - std::cout << "Opening output file: " << out_file_name.c_str() << std::endl; - out_file.open(out_file_name.c_str()); - if (!out_file){ - std::cout << "ERROR: Failed to open out_file!" << std::endl; - return -1; - } - if (num_geant_files == 1){ - out_file << "Angle\tFEP Scaling\tCompton Scaling\tFit Error\tChi Squared\tResidual Sum\tResSumInPeak\tPeakSum" << std::endl; - } - else if (num_geant_files == 2){ - out_file << "Angle\t Fep Scaling\t Compton Scaling\t 2nd-2Plus Scaling\t FitError\t ChiSquared\t ResSum\t ResSumInPeak\t PeakSum" << std::endl; - } - else if (num_geant_files == 3){ - out_file << "Angle\t Fep Scaling\t Compton Scaling\t655 Scaling\t1362 Scaling\tFitError\t ChiSquared\t ResSum\t ResSumInPeak\t PeakSum" << std::endl; - } - else if (num_geant_files == 4){ - out_file << "Angle\t Fep Scaling\t Compton Scaling\t655/1365 Scaling\t1362 Rel. Scaling\t1542 Scaling\tFitError\t ChiSquared\t ResSum\t ResSumInPeak\t PeakSum" << std::endl; - } - else if (num_geant_files == 5){ - out_file << "Angle\tFep Scaling\tCompton Scaling\t802 Scaling\t1440 Scaling" - << "\t1577 Scaling\t1644 Scaling\t FitError\t ChiSquared\t ResSum" - << "\t ResSumInPeak\t PeakSum" << std::endl; - } - - //////////////////////////////////////////////////////////////////////////////////////////////////// - //GET GEANT HISTOGRAMS - - std::cout << "Getting Geant Histograms" << std::endl; - getGeantHistograms(geant_hists,geant_file_names); - if (geant_hists.size() != (unsigned int)num_geant_files*2){ - std::cout << "ERROR: Incorrect number of histograms ("<GetXaxis()->SetRangeUser(data_low_x,data_high_x); - geant_hists.at(geant_file)->Rebin(kev_per_bin); - geant_hists.at(geant_file+1)->GetXaxis()->SetRangeUser(data_low_x,data_high_x); - geant_hists.at(geant_file+1)->Rebin(kev_per_bin); - } - //DONE GETTING GEANT HISTOGRAMS - //////////////////////////////////////////////////////////////////////////////////////////////////// - - std::cout << "Getting data histograms.." << std::endl; - getHistograms(data_hists, angles, input_file, START_ANGLE, FINAL_ANGLE,ANGLE_STEPS, - data_low_x, data_high_x, kev_per_bin); - std::cout << "Done getting histograms." << std::endl; - - //////////////////////////////////////////////////// - //Now Starting Fitting Routine - int num_res_points = (fit_high_x - fit_low_x)/kev_per_bin; - std::vector residuals; - std::vector normed_residuals; - std::vector bin_centers; - std::vector peak_sum; - residuals.resize(num_res_points); - normed_residuals.resize(num_res_points); - bin_centers.resize(num_res_points); - peak_sum.resize(TOTAL_ANGLES); - - TF1 *used_fit_function = new TF1("double_expo_fit", - "[0]*([1]*TMath::Exp([2]*x)+[3]*TMath::Exp([4]*x))", - data_low_x,data_high_x); - - //Setting parameters for double exponential! - for (int i = 1; i <= 4; i++){ - used_fit_function->SetParameter(i, init_pars[num_geant_files+i+1]); - } -//if (num_geant_files ==1){ -// used_fit_function->SetParameter(1,init_pars[3]); -// used_fit_function->SetParameter(2,init_pars[4]); -// used_fit_function->SetParameter(3,init_pars[5]); -// used_fit_function->SetParameter(4,init_pars[6]); -//} -//if (num_geant_files ==2){ -// used_fit_function->SetParameter(1,init_pars[4]); -// used_fit_function->SetParameter(2,init_pars[5]); -// used_fit_function->SetParameter(3,init_pars[6]); -// used_fit_function->SetParameter(4,init_pars[7]); -//} - TFile *out_hist_file = new TFile("output_fit_hists.root","recreate"); - for (int angle_index = 0; angle_index < TOTAL_ANGLES; angle_index++){ - peak_sum[angle_index] = 0; - TF1 *fit_func = 0; - if (num_geant_files == 1){ - fit_func = FitDoubleExpTwoHist(data_hists.at(angle_index), geant_hists.at(0), - geant_hists.at(1), fit_low_x, fit_high_x, init_pars); - } - else if (num_geant_files == 2){ - fit_func = FitDoubleExpThreeHist(data_hists.at(angle_index), geant_hists.at(0), - geant_hists.at(1), geant_hists.at(2), fit_low_x, fit_high_x, init_pars); - } - else if (num_geant_files == 3){ - fit_func = FitDoubleExpFourHist(data_hists.at(angle_index), geant_hists.at(0), - geant_hists.at(1), geant_hists.at(2), geant_hists.at(4), fit_low_x, - fit_high_x, init_pars); - } - else if (num_geant_files == 4){ - fit_func = FitDoubleExpFiveHist(data_hists.at(angle_index), geant_hists.at(0), - geant_hists.at(1), geant_hists.at(2), geant_hists.at(4), geant_hists.at(6), - fit_low_x, fit_high_x, init_pars); - } - else if (num_geant_files == 5){ - fit_func = FitDoubleExpSixHist(data_hists.at(angle_index), geant_hists.at(0), - geant_hists.at(1), geant_hists.at(2), geant_hists.at(4), geant_hists.at(6), - geant_hists.at(8), fit_low_x, fit_high_x, init_pars); - } - else { - std::cout << "Unknown reason for num_geant_files = " << num_geant_files << std::endl; - } - - //GH1D *fit_func_hist = new GH1D(*fit_func, 512,0,8192); - GH1D *fit_func_hist = new GH1D(*fit_func, 8192./kev_per_bin,0,8192); - //fit_func_hist->Rebin(kev_per_bin); - TSpline3 *fit_func_spline = new TSpline3(fit_func_hist); -// std::cout << "Parameters from Fit Function are: " << std::endl; -// fit_func->Print(); - data_hists.at(angle_index)->SetTitle(Form("Fit to %s with Scatter Cut (< %3.3f)", isotope_name.c_str(),angles.at(angle_index))); - data_hists.at(angle_index)->GetXaxis()->SetTitle("Energy (keV)"); - data_hists.at(angle_index)->GetYaxis()->SetTitle(Form("Counts / %d keV", kev_per_bin)); - - fit_error[angle_index] = fit_func->GetParError(0); - chi_squared[angle_index] = fit_func->GetChisquare(); - - hist_constant[angle_index][0] = fit_func->GetParameter(0); - hist_constant[angle_index][1] = fit_func->GetParameter(1); - hist_constant[angle_index][2] = 0; - hist_constant[angle_index][3] = 0; - hist_constant[angle_index][4] = 0; - hist_constant[angle_index][5] = 0; - if (num_geant_files == 2){ - hist_constant[angle_index][2] = fit_func->GetParameter(2); - } - if (num_geant_files == 3){ - hist_constant[angle_index][2] = fit_func->GetParameter(2); - hist_constant[angle_index][3] = fit_func->GetParameter(3); - } - if (num_geant_files == 4){ - hist_constant[angle_index][2] = fit_func->GetParameter(2); - hist_constant[angle_index][3] = fit_func->GetParameter(3); - hist_constant[angle_index][4] = fit_func->GetParameter(4); - } - else if (num_geant_files == 5){ - hist_constant[angle_index][2] = fit_func->GetParameter(2); - hist_constant[angle_index][3] = fit_func->GetParameter(3); - hist_constant[angle_index][4] = fit_func->GetParameter(4); - hist_constant[angle_index][5] = fit_func->GetParameter(5); - } - //Now we get residuals - double res_sum = 0; - double res_sum_in_peak = 0; - - int start_bin = data_hists[angle_index]->FindBin(fit_low_x); - int end_bin = data_hists[angle_index]->FindBin(fit_high_x); - used_fit_function->SetParameter(0, fit_func->GetParameter(num_geant_files+1));//set double exponential scaling factor - - for (int bin = start_bin; bin < end_bin; bin++){ - bin_centers[bin-start_bin] = data_hists.at(angle_index)->GetBinCenter(bin); - residuals[bin-start_bin] = data_hists.at(angle_index)->GetBinContent(bin) - - fit_func->Eval(bin_centers[bin-start_bin]); - res_sum += residuals[bin-start_bin]; - normed_residuals[bin-start_bin] = residuals[bin-start_bin]/TMath::Sqrt(data_hists[angle_index]->GetBinContent(bin)); - - if (bin_centers[bin-start_bin] >= peak_low_x && bin_centers[bin-start_bin] <= peak_high_x){ - TH1D geant_compton_hist1; - geant_compton_hist1 = *((TH1D*)geant_hists.at(1)->Clone("geant_compton_hist1")); - geant_compton_hist1.Scale(hist_constant[angle_index][1]*hist_constant[angle_index][0]); - - peak_sum[angle_index] += (fit_func->Eval(bin_centers[bin-start_bin]) - - used_fit_function->Eval(bin_centers[bin-start_bin]) - - geant_compton_hist1.GetBinContent(bin)); - if (num_geant_files == 2){ - TH1D geant_compton_hist2; - geant_compton_hist2 = *((TH1D*)geant_hists.at(3)->Clone("geant_compton_hist2")); - geant_compton_hist2.Scale(hist_constant[angle_index][2]); - peak_sum[angle_index] -= geant_compton_hist2.GetBinContent(bin); - }//2 geant files - else if (num_geant_files == 3){ - TH1D geant_compton_hist2; - geant_compton_hist2 = *((TH1D*)geant_hists.at(3)->Clone("geant_compton_hist2")); - geant_compton_hist2.Scale(hist_constant[angle_index][2]); - peak_sum[angle_index] -= geant_compton_hist2.GetBinContent(bin); - - TH1D geant_compton_hist3; - geant_compton_hist3 = *((TH1D*)geant_hists.at(5)->Clone("geant_compton_hist3")); - geant_compton_hist3.Scale(hist_constant[angle_index][3]); - peak_sum[angle_index] -= geant_compton_hist3.GetBinContent(bin); - }//2 geant files - else if (num_geant_files == 4){ - TH1D geant_compton_hist2; - geant_compton_hist2 = *((TH1D*)geant_hists.at(3)->Clone("geant_compton_hist2")); - geant_compton_hist2.Scale(hist_constant[angle_index][2]*0.68); - peak_sum[angle_index] -= geant_compton_hist2.GetBinContent(bin); - - TH1D geant_compton_hist3; - geant_compton_hist3 = *((TH1D*)geant_hists.at(5)->Clone("geant_compton_hist3")); - geant_compton_hist3.Scale(hist_constant[angle_index][2]); - peak_sum[angle_index] -= geant_compton_hist3.GetBinContent(bin); - - TH1D geant_compton_hist4; - geant_compton_hist4 = *((TH1D*)geant_hists.at(7)->Clone("geant_compton_hist4")); - geant_compton_hist4.Scale(hist_constant[angle_index][4]); - peak_sum[angle_index] -= geant_compton_hist4.GetBinContent(bin); - }//2 geant files - else if (num_geant_files == 5){ - TH1D geant_compton_hist2; - geant_compton_hist2 = *((TH1D*)geant_hists.at(3)->Clone("geant_compton_hist2")); - geant_compton_hist2.Scale(hist_constant[angle_index][2]); - peak_sum[angle_index] -= geant_compton_hist2.GetBinContent(bin); - - TH1D geant_compton_hist3; - geant_compton_hist3 = *((TH1D*)geant_hists.at(5)->Clone("geant_compton_hist3")); - geant_compton_hist3.Scale(hist_constant[angle_index][3]); - peak_sum[angle_index] -= geant_compton_hist3.GetBinContent(bin); - - TH1D geant_compton_hist4; - geant_compton_hist4 = *((TH1D*)geant_hists.at(7)->Clone("geant_compton_hist4")); - geant_compton_hist4.Scale(hist_constant[angle_index][4]); - peak_sum[angle_index] -= geant_compton_hist4.GetBinContent(bin); - - TH1D geant_compton_hist5; - geant_compton_hist5 = *((TH1D*)geant_hists.at(9)->Clone("geant_compton_hist5")); - geant_compton_hist5.Scale(hist_constant[angle_index][5]); - peak_sum[angle_index] -= geant_compton_hist5.GetBinContent(bin); - }//5 geant files - res_sum_in_peak += residuals[bin-start_bin]; - } - }//bin loop - - - TGraph *residual_plot = new TGraph(num_res_points, &bin_centers[0], &residuals[0]); - residual_plot->SetName(Form("res_plot_angle_%f", angles.at(angle_index))); - TGraph *norm_residual_plot = new TGraph(num_res_points, &bin_centers[0], &normed_residuals[0]); - norm_residual_plot->SetName(Form("norm_res_plot_angle_%f", angles.at(angle_index))); - - out_file << angles[angle_index] <<"\t"<cd(); - residual_plot->Write(); - norm_residual_plot->Write(); - data_hists[angle_index]->Write(); - - TCanvas *disentangled_can = new TCanvas(Form("dis_can_%1.1f",angles[angle_index]),Form("dis_can_%f",angles[angle_index]), 800,600); - disentangled_can->cd(); - data_hists[angle_index]->Draw("HIST"); - data_hists[angle_index]->SetLineWidth(2); - TLine *fit_low = new TLine(fit_low_x, 0, fit_low_x, 780); - TLine *fit_high = new TLine(fit_high_x, 0, fit_high_x, 780); - TLine *peak_low = new TLine(peak_low_x, 0, peak_low_x, 780); - TLine *peak_high = new TLine(peak_high_x, 0, peak_high_x, 780); - fit_low->SetLineStyle(2); - fit_high->SetLineStyle(2); - peak_low->SetLineStyle(3); - peak_high->SetLineStyle(3); - fit_low->Draw(); - fit_high->Draw(); - peak_low->Draw(); - peak_high->Draw(); - - geant_hists.at(0)->SetLineColor(kGreen+2); - geant_hists.at(1)->SetLineColor(kRed); - if (num_geant_files ==2 ){ - geant_hists.at(2)->SetLineColor(kMagenta); - } - used_fit_function->SetLineColor(kBlack); - fit_func_spline->SetLineColor(kCyan+2); - - geant_hists.at(0)->SetLineWidth(3); - geant_hists.at(1)->SetLineWidth(3); - if (num_geant_files ==2 ){ - geant_hists.at(2)->SetLineWidth(3); - } - used_fit_function->SetLineWidth(3); - fit_func_spline->SetLineWidth(3); - - TH1D fep_hist = *((TH1D*)geant_hists.at(0)->Clone("fep_hist")); - fep_hist.Scale(hist_constant[angle_index][0]); - fep_hist.Draw("same"); - - TH1D compton_hist = *((TH1D*)geant_hists.at(1)->Clone("compton_hist")); - compton_hist.Scale(hist_constant[angle_index][1]*hist_constant[angle_index][0]); - compton_hist.Draw("same"); - - TH1D second_2plus_hist; - - TH1D hist_1362; - TH1D hist_655; - TH1D hist_802; - TH1D hist_1440; - TH1D hist_1542; - TH1D hist_1577; - TH1D hist_1644; - - if (num_geant_files ==2 ){ - geant_hists.at(2)->SetLineWidth(3); - second_2plus_hist = *((TH1D*)geant_hists.at(2)->Clone("second_2plus_hist")); - second_2plus_hist.Scale(hist_constant[angle_index][2]); - second_2plus_hist.Draw("same"); - } - else if (num_geant_files ==3){ - geant_hists.at(2)->SetLineWidth(3); - hist_655 = *((TH1D*)geant_hists.at(2)->Clone("hist_655")); - hist_655.Scale(hist_constant[angle_index][2]); - hist_655.Draw("same"); - geant_hists.at(4)->SetLineWidth(3); - hist_1362 = *((TH1D*)geant_hists.at(4)->Clone("hist_1362")); - hist_1362.Scale(hist_constant[angle_index][3]); - hist_1362.Draw("same"); - } - else if (num_geant_files ==4){ - geant_hists.at(2)->SetLineWidth(3); - hist_655 = *((TH1D*)geant_hists.at(2)->Clone("hist_655")); - hist_655.Scale(hist_constant[angle_index][2]*0.68); - hist_655.Draw("same"); - geant_hists.at(4)->SetLineWidth(3); - hist_1362 = *((TH1D*)geant_hists.at(4)->Clone("hist_1362")); - hist_1362.Scale(hist_constant[angle_index][2]); - hist_1362.Draw("same"); - geant_hists.at(6)->SetLineWidth(3); - hist_1542 = *((TH1D*)geant_hists.at(6)->Clone("hist_1542")); - hist_1542.Scale(hist_constant[angle_index][4]); - hist_1542.Draw("same"); - } - else if (num_geant_files == 5){ - geant_hists.at(2)->SetLineWidth(3); - hist_802 = *((TH1D*)geant_hists.at(2)->Clone("hist_802")); - hist_802.Scale(hist_constant[angle_index][2]); - hist_802.Draw("same"); - geant_hists.at(4)->SetLineWidth(3); - hist_1440 = *((TH1D*)geant_hists.at(4)->Clone("hist_1440")); - hist_1440.Scale(hist_constant[angle_index][3]); - hist_1440.Draw("same"); - geant_hists.at(6)->SetLineWidth(3); - hist_1577 = *((TH1D*)geant_hists.at(6)->Clone("hist_1577")); - hist_1577.Scale(hist_constant[angle_index][4]); - hist_1577.Draw("same"); - geant_hists.at(8)->SetLineWidth(3); - hist_1644 = *((TH1D*)geant_hists.at(8)->Clone("hist_1644")); - hist_1644.Scale(hist_constant[angle_index][5]); - hist_1644.Draw("same"); - } - if (!used_fit_function){ - std::cout << "Fit function doesn't exist." << std::endl; - } - else{ - used_fit_function->Draw("same"); - } -// fit_func->Draw("same"); - fit_func_spline->SetNpx(1000); - fit_func_spline->Draw("same"); - - out_hist_file->cd(); - gStyle->SetOptStat(0); - gStyle->SetOptFit(1); - disentangled_can->Write(); - - - TCanvas *residual_with_hists_can = new TCanvas(Form("res_can_%1.1f",angles[angle_index]),Form("res_can_%1.1f",angles[angle_index]), 800,600); - residual_with_hists_can->Divide(1,2); - residual_with_hists_can->cd(1); - data_hists[angle_index]->SetLineWidth(3); - fit_func_hist->SetLineWidth(3); - data_hists[angle_index]->SetLineColor(kBlue); - fit_func_hist->SetLineColor(kRed); - data_hists[angle_index]->Draw("HIST"); - TLegend leg(0.5,0.5,0.8,0.7); - leg.AddEntry(fit_func_hist, "Fit Function", "l"); - leg.AddEntry(data_hists[angle_index], "Data", "l"); - leg.Draw(); - fit_func_hist->Draw("same"); - - - residual_with_hists_can->cd(2); - TH1D *res_sub_hist = (TH1D*)data_hists[angle_index]->Clone("res_sub_hist"); - res_sub_hist->Add(fit_func_hist,-1); - res_sub_hist->Draw("HIST"); - res_sub_hist->SetTitle("Residuals"); - TPaveText *pt = new TPaveText(0.65,0.15,0.85,0.30, "NDC"); - TLine *peak_low_ressub = new TLine(peak_low_x, -50, peak_low_x, 50); - TLine *peak_high_ressub = new TLine(peak_high_x, -50, peak_high_x, 50); - peak_low_ressub->SetLineStyle(3); - peak_high_ressub->SetLineStyle(3); - peak_low_ressub->SetLineWidth(3); - peak_high_ressub->SetLineWidth(3); - peak_low_ressub->Draw(); - peak_high_ressub->Draw(); - - int peak_low_bin = res_sub_hist->FindBin(peak_low_x); - int peak_high_bin = res_sub_hist->FindBin(peak_high_x); - pt->AddText(Form("Residual Sum in Peak: %1.1f",res_sub_hist->Integral(peak_low_bin,peak_high_bin-1))); - pt->AddText(Form("Total Peak Sum: %1.1f",peak_sum.at(angle_index))); - pt->Draw(); - - residual_with_hists_can->Write(); - - delete residual_plot; - delete norm_residual_plot; - delete fit_func; - delete fit_func_spline; - delete fit_func_hist; - delete disentangled_can; - delete residual_with_hists_can; - delete pt; - if (angle_index % 10 == 0){ - std::cout << " Completed Angle " << angles[angle_index] << std::endl; - } - } - out_file.close(); - //END OF OLD FILE - //////////////////////////////////////////////////////////////////////////////////////////////////// - return 0; -}//End of Function - -#ifndef __CINT__ -int main(int argc, char **argv){ - if (argc != 2){ - std::cout << "Error! Incorrect number of arguments: " << argc << std::endl; - std::cout << "Usage: fitCoulex CFG_FILE"; - return 1; - } - - fitCoulex(argv[1]); -} -#endif diff --git a/util/gadd.cxx b/util/gadd.cxx deleted file mode 100644 index 4ebd5008..00000000 --- a/util/gadd.cxx +++ /dev/null @@ -1,250 +0,0 @@ -/* - - This program will add histograms (see note) and Trees from a list of root files and write them - to a target root file. The target file is newly created and must not be - identical to one of the source files. - - Syntax: - - gadd targetfile source1 source2 ... - or - gadd -f targetfile source1 source2 ... - (targetfile is overwritten if it exists) - - When the -f option is specified, one can also specify the compression - level of the target file. By default the compression level is 1, but - if "-f0" is specified, the target file will not be compressed. - if "-f6" is specified, the compression level 6 will be used. - - For example assume 3 files f1, f2, f3 containing histograms hn and Trees Tn - f1 with h1 h2 h3 T1 - f2 with h1 h4 T1 T2 - f3 with h5 - the result of - gadd -f x.root f1.root f2.root f3.root - will be a file x.root with h1 h2 h3 h4 h5 T1 T2 - where h1 will be the sum of the 2 histograms in f1 and f2 - T1 will be the merge of the Trees in f1 and f2 - - The files may contain sub-directories. - - if the source files contains histograms and Trees, one can skip - the Trees with - gadd -T targetfile source1 source2 ... - - Wildcarding and indirect files are also supported - gadd result.root myfil*.root - will merge all files in myfil*.root - gadd result.root file1.root @list.txt file2. root myfil*.root - will merge file1. root, file2. root, all files in myfil*.root - and all files in the indirect text file list.txt ("@" as the first - character of the file indicates an indirect file. An indirect file - is a text file containing a list of other files, including other - indirect files, one line per file). - - If the sources and and target compression levels are identical (default), - the program uses the TChain::Merge function with option "fast", ie - the merge will be done without unzipping or unstreaming the baskets - (i.e. direct copy of the raw byte on disk). The "fast" mode is typically - 5 times faster than the mode unzipping and unstreaming the baskets. - - NOTE1: By default histograms are added. However gadd does not support the case where - histograms have their bit TH1::kIsAverage set. - - NOTE2: gadd returns a status code: 0 if OK, -1 otherwise - - Authors: Rene Brun, Dirk Geppert, Sven A. Schmidt, sven.schmidt@cern.ch - : rewritten from scratch by Rene Brun (30 November 2005) - to support files with nested directories. - Toby Burnett implemented the possibility to use indirect files. - - Moved into this directory with the name gadd to link with grsisort by Ryan Dunlop - */ - -#include "RConfig.h" -#include -#include "TFile.h" -#include "THashList.h" -#include "TKey.h" -#include "TObjString.h" -#include "Riostream.h" -#include "TClass.h" -#include "TSystem.h" -#include - -#include "TFileMerger.h" -#include "TROOT.h" -#include "TInterpreter.h" - -//___________________________________________________________________________ -int main( int argc, char **argv ) -{ - - if ( argc < 3 || "-h" == std::string(argv[1]) || "--help" == std::string(argv[1]) ) { - std::cout << "Usage: " << argv[0] << " [-f[0-9]] [-k] [-T] [-O] [-n maxopenedfiles] [-v verbosity] targetfile source1 [source2 source3 ...]" << std::endl; - std::cout << "This program will add histograms from a list of root files and write them" << std::endl; - std::cout << "to a target root file. The target file is newly created and must not " << std::endl; - std::cout << "exist, or if -f (\"force\") is given, must not be one of the source files." << std::endl; - std::cout << "Supply at least two source files for this to make sense... ;-)" << std::endl; - std::cout << "If the option -k is used, gadd will not exit on corrupt or non-existant input files but skip the offending files instead." << std::endl; - std::cout << "If the option -T is used, Trees are not merged" <= argc) { - std::cerr << "Error: no maximum number of opened was provided after -n.\n"; - } else { - Long_t request = strtol(argv[a+1], 0, 10); - if (request < kMaxLong && request >= 0) { - maxopenedfiles = (Int_t)request; - ++a; - ++ffirst; - } else { - std::cerr << "Error: could not parse the max number of opened file passed after -n: " << argv[a+1] << ". We will use the system maximum.\n"; - } - } - ++ffirst; - } else if ( strcmp(argv[a],"-v") == 0 ) { - if (a+1 >= argc) { - std::cerr << "Error: no verbosity level was provided after -v.\n"; - } else { - Long_t request = strtol(argv[a+1], 0, 10); - if (request < kMaxLong && request >= 0) { - verbosity = (Int_t)request; - ++a; - ++ffirst; - } else { - std::cerr << "Error: could not parse the verbosity level passed after -v: " << argv[a+1] << ". We will use the default value (99).\n"; - } - } - ++ffirst; - } else if ( argv[a][0] == '-' ) { - char ft[4]; - for( int j=0; j<=9; ++j ) { - snprintf(ft,4,"-f%d",j); - if (!strcmp(argv[a],ft)) { - force = kTRUE; - newcomp = j; - ++ffirst; - break; - } - } - if (!force) { - // Bad argument - std::cerr << "Error: option " << argv[a] << " is not a supported option.\n"; - ++ffirst; - } - } else if (!outputPlace) { - outputPlace = a; - } - } - - gSystem->Load("libTreePlayer"); - gSystem->Load("libGROOT"); - TClass::GetClass("ROOT::Cintex::Cintex"); // autoload Cintex if it exist. - if (gInterpreter->IsLoaded("libCintex")) { - gROOT->ProcessLine("ROOT::Cintex::Cintex::Enable();"); - } - const char *targetname = 0; - if (outputPlace) { - targetname = argv[outputPlace]; - } else { - targetname = argv[ffirst-1]; - } - - if (verbosity > 1) { - std::cout << "gadd Target file: " << targetname << std::endl; - } - - TFileMerger merger(kFALSE,kFALSE); - merger.SetMsgPrefix("gadd"); - merger.SetPrintLevel(verbosity - 1); - if (maxopenedfiles > 0) { - merger.SetMaxOpenedFiles(maxopenedfiles); - } - if (!merger.OutputFile(targetname,force,newcomp) ) { - std::cerr << "gadd error opening target file (does " << argv[ffirst-1] << " exist?)." << std::endl; - std::cerr << "Pass \"-f\" argument to force re-creation of output file." << std::endl; - exit(1); - } - - - for ( int i = ffirst; i < argc; i++ ) { - if (argv[i] && argv[i][0]=='@') { - std::ifstream indirect_file(argv[i]+1); - if( ! indirect_file.is_open() ) { - std::cerr<< "gadd could not open indirect file " << (argv[i]+1) << std::endl; - return 1; - } - while( indirect_file ){ - std::string line; - if( std::getline(indirect_file, line) && line.length() && !merger.AddFile(line.c_str()) ) { - return 1; - } - } - } else if( ! merger.AddFile(argv[i]) ) { - if ( skip_errors ) { - std::cerr << "gadd skipping file with error: " << argv[i] << std::endl; - } else { - std::cerr << "gadd exiting due to error in " << argv[i] << std::endl; - return 1; - } - } - } - if (reoptimize) { - merger.SetFastMethod(kFALSE); - } else { - if (merger.HasCompressionChange()) { - // Don't warn if the user any request re-optimization. - std::cout <<"gadd Sources and Target have different compression levels"<GetEntries() << " input files in " << targetname << ".\n"; - } - return 0; - } else { - if (verbosity == 1) { - std::cout << "gadd failure during the merge of " << merger.GetMergeList()->GetEntries() << " input files in " << targetname << ".\n"; - } - return 1; - } -} diff --git a/util/getScalerCounts.cxx b/util/getScalerCounts.cxx new file mode 100644 index 00000000..a4728ffb --- /dev/null +++ b/util/getScalerCounts.cxx @@ -0,0 +1,86 @@ +#include + +#include "TTree.h" +#include "TFile.h" + +#include "TNSCLScalers.h" +#include "TDetector.h" + +void getScalerCounts(char *input_root_file_name){ + TFile *input_root_file = new TFile(input_root_file_name, "read"); + if (!input_root_file){ + std::cout << "Failed to open the input root file!"<Get("EventTree"); + if (!in_tree){ + std::cout << "Failed to open the input tree file!"<SetBranchAddress("TNSCLScalers", &scalers); + std::vector scaler_250(250);//incremental scalers + std::vector scaler_32(32);//periodic scaler + std::vector scaler_32_overflows(32);//periodic scaler overflow check. adds 2^24 to result + + int n_entries = in_tree->GetEntries(); + + for (int entry = 0; entry < n_entries; entry++){ + scalers->Clear(); + in_tree->GetEntry(entry); + + +// s800_raw_triggers += scalers->GetScaler(s800_raw_trigger_index); +// s800_live_triggers += scalers->GetScaler(s800_live_trigger_index); + if (scalers->Size() == 250){ + for (int i = 0; i < 250;i++){ + scaler_250.at(i) += scalers->GetScaler(i); + } + } + if (scalers->Size() == 32){ + for (int i = 0; i < 32;i++){ + if (scalers->GetScaler(i) < scaler_32.at(i)){ + scaler_32_overflows.at(i) += 1; + } + scaler_32.at(i) = scalers->GetScaler(i); + } + } + }//loop over tree + + int live_clock = scaler_32.at(12); + int raw_clock = scaler_32.at(11); + int live_trigger = scaler_32.at(10); + int raw_trigger = scaler_32.at(9); + int second_source = scaler_32.at(1); + + live_clock += scaler_32_overflows.at(12)*pow(2.,24.); + raw_clock += scaler_32_overflows.at(11)*pow(2.,24.); + live_trigger += scaler_32_overflows.at(10)*pow(2.,24.); + raw_trigger += scaler_32_overflows.at(9)*pow(2.,24.); + second_source += scaler_32_overflows.at(1)*pow(2.,24.); + std::cout << "raw.clock\tlive.clock\traw.trigger\tlive.trigger" << std::endl; + std::cout << raw_clock << "\t" << live_clock <<"\t" + << raw_trigger << "\t" << live_trigger + << std::endl; +} +#ifndef __CINT__ + +int main(int argc, char**argv){ + + if (argc < 2){ + std::cout << "USAGE: getScalerCounts INPUT_FILE_NAME" << std::endl; + } + getScalerCounts(argv[1]); + return 0; +} + +#endif diff --git a/util/grutinizer-config b/util/grutinizer-config index 5af8de4b..95eea142 100755 --- a/util/grutinizer-config +++ b/util/grutinizer-config @@ -50,10 +50,11 @@ incdir=$GRUTSYS/include rpath="-Wl,-rpath=$libdir" grutlibs="-lTGRUTUtil -lTRawFormat -lGROOT -lTNSCLFormat -lTGEBFormat -lTGRUTUtil -lTNucleus -lTKinematics -lTReaction -lTSRIM -lTNSCLScalers" -detlibs="-lTSega -lTDetector -lTGretina -lTJanus -lTPhosWall -lTS800 -lTFastScint -lTCaesar -lTS800Sim -lTGretSim" +detlibs="-lTSega -lTDetector -lTGretina -lTJanus -lTPhosWall -lTS800 -lTFastScint -lTCaesar -lTS800Sim -lTGretSim +-lTLenda -lTFSU -lTUML" grutmore="-lTGRUTint -lTLoops -lTHistogramming " -cflags="-std=c++0x -I$incdir" +cflags="-std=c++11 -I$incdir -Wl,--no-as-needed" @@ -129,7 +130,7 @@ while test $# -gt 0; do continue fi rootout="yes" - out="$out `root-config --cflags --glibs` -lPhysics -lSpectrum -lPyROOT -lMinuit" + out="$out `root-config --cflags --glibs` -lPhysics -lSpectrum -lPyROOT -lMinuit -lMathMore" ;; --libdir) if test "x$libdirout" = "xyes" ; then diff --git a/util/r2root.cxx b/util/r2root.cxx new file mode 100644 index 00000000..e9dda4ec --- /dev/null +++ b/util/r2root.cxx @@ -0,0 +1,6 @@ +#include +#include +#include + +int main(){ +} diff --git a/util/read.cxx b/util/read.cxx new file mode 100644 index 00000000..13e412b5 --- /dev/null +++ b/util/read.cxx @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +//#include "global.h" +#include +#include +#include +#include +#include + +using namespace std; + + +typedef unsigned short WORD; +typedef unsigned char BYTE; + +typedef unsigned short UINT16; +typedef signed short INT16; + + + +struct gebData +{ + int type; + int length; // payload in bytes + long long timestamp; +}; + + +struct HFC_item +{ + gebData geb; + BYTE* data; +}; + +void printout(gebData aGeb) { + cout<<"Type : "<5 ) cnt = 5; + for(int i = 0; i < cnt; i++ ){ + printout(gebs[index]); + index = (index +1)%5; + } + printout(aGeb); + } +} + +int main(int argc, char** argv) { + if(argc<2) { + cout< gretina; + vector ddas; + + + while(flag) { + if(fread(&aGeb,sizeof(struct gebData),1,in) !=1 ) break; + read = fread(cbuf,sizeof(char),aGeb.length,in); + if(read != aGeb.length) break; + if(aGeb.type == 0x19) ddas.push_back(aGeb.timestamp); +// else if(aGeb.type == 1 || aGeb.type == 8) gretina.push_back(aGeb.timestamp); + else if(aGeb.type == 1) gretina.push_back(aGeb.timestamp); + + cnt++; + } + + cout<<"size ddas: "<Branch("tdiff",&tdiff,"tdiff/L"); + + for (size_t i = 0; i::iterator index = std::lower_bound(ddas.begin(),ddas.end(),fts-1000); // search window +/-10us + while(index != ddas.end() && abs((*index)-fts)<=1000){ + tdiff = (*index)-fts; + opt->Fill(); + index++; + } + } + opt->Write(); + opf->Close(); +} diff --git a/util/scripts.C b/util/scripts.C index c6680431..057c7aee 100644 --- a/util/scripts.C +++ b/util/scripts.C @@ -1,7 +1,8 @@ +//TTree *tree = NULL; +//TMode3 *mode3 = new TMode3; -TTree *tree = NULL; -TMode3 *mode3 = new TMode3; +TMode3 *mode3 = obj.GetDetector(); static Int_t evno=0; From 8070a5c96d407bdf0a21cee2bd803ac2faff7a35 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Wed, 19 May 2021 18:24:31 -0400 Subject: [PATCH 09/29] Modifications for compatibility with root v6.24/00. --- filters/Filter_e10010.cxx | 3 +- histos/MakeHistos60CoLaBr.cxx | 285 ---- histos/MakeHistos60CoSim.cxx | 489 ------- histos/MakeHistosFDS.cxx | 250 ---- histos/MakeHistosInBeamAngCorr.cxx | 610 --------- histos/MakeHistosNeutrons.cxx | 364 ----- histos/MakeHistosOslo.cxx | 156 --- histos/MakeHistosPencil.cxx | 402 ------ histos/MakeHistosTarEx.cxx | 430 ------ histos/MakeHistosWhiteSim.cxx | 179 --- histos/MakeHistos_e10010.cxx | 705 ---------- histos/MakeHistos_e10010_Sim.cxx | 907 ------------- histos/MakeHistos_e10010_Trigger.cxx | 303 ----- histos/MakeHistos_e10010_Trigger_cl46.cxx | 345 ----- histos/MakeHistos_e10010_Trigger_p41.cxx | 352 ----- histos/MakeHistos_e10010_Trigger_p43.cxx | 352 ----- histos/MakeHistos_e10010_Trigger_s42.cxx | 345 ----- histos/MakeHistos_e10010_Trigger_s44.cxx | 307 ----- histos/MakeHistos_e10010_Trigger_si39.cxx | 345 ----- histos/MakeHistos_e10010_cl46.cxx | 1182 ---------------- histos/MakeHistos_e10010_cl46_empty.cxx | 1182 ---------------- histos/MakeHistos_e10010_p41.cxx | 1197 ---------------- histos/MakeHistos_e10010_p43.cxx | 1182 ---------------- histos/MakeHistos_e10010_p43_empty.cxx | 1182 ---------------- histos/MakeHistos_e10010_s42.cxx | 1197 ---------------- histos/MakeHistos_e10010_s42_empty.cxx | 1197 ---------------- histos/MakeHistos_e10010_s44.cxx | 1206 ----------------- histos/MakeHistos_e10010_si39.cxx | 1197 ---------------- histos/MakeHistos_e10010_si39_empty.cxx | 1197 ---------------- histos/MyMakeHistos.cxx.bak | 761 ----------- include/TCluster.h | 2 + libraries/GROOT/GH2.cxx | 2 + libraries/GROOT/GPeak.cxx | 3 +- libraries/GROOT/GRootBrowser.cxx | 1 + .../TDetSystems/TGretina/TGretinaHit.cxx | 22 +- libraries/TDetSystems/TS800/TS800.cxx | 4 +- makefile | 2 +- util/grutinizer-config | 2 +- 38 files changed, 23 insertions(+), 19824 deletions(-) delete mode 100644 histos/MakeHistos60CoLaBr.cxx delete mode 100644 histos/MakeHistos60CoSim.cxx delete mode 100644 histos/MakeHistosFDS.cxx delete mode 100644 histos/MakeHistosInBeamAngCorr.cxx delete mode 100644 histos/MakeHistosNeutrons.cxx delete mode 100644 histos/MakeHistosOslo.cxx delete mode 100644 histos/MakeHistosPencil.cxx delete mode 100644 histos/MakeHistosTarEx.cxx delete mode 100644 histos/MakeHistosWhiteSim.cxx delete mode 100644 histos/MakeHistos_e10010.cxx delete mode 100644 histos/MakeHistos_e10010_Sim.cxx delete mode 100644 histos/MakeHistos_e10010_Trigger.cxx delete mode 100644 histos/MakeHistos_e10010_Trigger_cl46.cxx delete mode 100644 histos/MakeHistos_e10010_Trigger_p41.cxx delete mode 100644 histos/MakeHistos_e10010_Trigger_p43.cxx delete mode 100644 histos/MakeHistos_e10010_Trigger_s42.cxx delete mode 100644 histos/MakeHistos_e10010_Trigger_s44.cxx delete mode 100644 histos/MakeHistos_e10010_Trigger_si39.cxx delete mode 100644 histos/MakeHistos_e10010_cl46.cxx delete mode 100644 histos/MakeHistos_e10010_cl46_empty.cxx delete mode 100644 histos/MakeHistos_e10010_p41.cxx delete mode 100644 histos/MakeHistos_e10010_p43.cxx delete mode 100644 histos/MakeHistos_e10010_p43_empty.cxx delete mode 100644 histos/MakeHistos_e10010_s42.cxx delete mode 100644 histos/MakeHistos_e10010_s42_empty.cxx delete mode 100644 histos/MakeHistos_e10010_s44.cxx delete mode 100644 histos/MakeHistos_e10010_si39.cxx delete mode 100644 histos/MakeHistos_e10010_si39_empty.cxx delete mode 100644 histos/MyMakeHistos.cxx.bak diff --git a/filters/Filter_e10010.cxx b/filters/Filter_e10010.cxx index e964f7a9..d37f6cb2 100644 --- a/filters/Filter_e10010.cxx +++ b/filters/Filter_e10010.cxx @@ -11,13 +11,12 @@ extern "C" bool FilterCondition(TRuntimeObjects& obj) { + TGretina *gretina = obj.GetDetector(); //TS800 *s800 = obj.GetDetector(); if(!gretina) return false; - } - //if((s800->GetTrigger().GetRegistr()&0x0002)>>1) // return true; diff --git a/histos/MakeHistos60CoLaBr.cxx b/histos/MakeHistos60CoLaBr.cxx deleted file mode 100644 index feb20a07..00000000 --- a/histos/MakeHistos60CoLaBr.cxx +++ /dev/null @@ -1,285 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -Double_t measuredE(Double_t energy){ - Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); - if(std::isnan(resPar1)) - resPar1 = 1.2; - Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); - if(std::isnan(resPar2)) - resPar2 = 0.0005; - - return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - Int_t energyNChannels = 4000; - Double_t energyLlim = 0.; - Double_t energyUlim = 4000.; - Double_t cosTheta = -1; - Double_t mCosTheta = -1; - Double_t x1 = -1; - Double_t y1 = -1; - Double_t z1 = -1; - Double_t x2 = -1; - Double_t y2 = -1; - Double_t z2 = -1; - - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - if(hit.GetEn() > 1331 && hit.GetEn() < 1334){ - x1 = sin(hit.GetTheta())*cos(hit.GetPhi()); - y1 = sin(hit.GetTheta())*sin(hit.GetPhi()); - z1 = cos(hit.GetTheta()); - } - if(hit.GetEn() > 1171 && hit.GetEn() < 1175){ - x2 = sin(hit.GetTheta())*cos(hit.GetPhi()); - y2 = sin(hit.GetTheta())*sin(hit.GetPhi()); - z2 = cos(hit.GetTheta()); - } - } - cosTheta - = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); - obj.FillHistogram("sim","emitted_delta", - 100, -1, 1., - cosTheta); - } - - if(!gretina) - return; - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - int max_layer = -1; - - // LaBr-gate - Bool_t LaBr = false; - Double_t eGateLlim = 1327.5; - Double_t eGateUlim = 1337.5; - for(int x=0; xSize(); x++){ - TGretinaHit hit = gretina->GetGretinaHit(x); - if(hit.GetCrystalId() == 136){ - obj.FillHistogram("energy", "LaBr", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - if(hit.GetCoreEnergy() > eGateLlim && - hit.GetCoreEnergy() < eGateUlim ) - LaBr = true; - } - } - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - if(hit.GetCrystalId() == 136) // Ignore LaBr - continue; - - Double_t mE = measuredE(hit.GetCoreEnergy()); - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - if(LaBr){ - obj.FillHistogram("energy", "LaBr_gate", - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", "overview_LaBr_gate", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - obj.FillHistogram("position", "theta_LaBr", - 1024, 0., TMath::Pi(), - hit.GetTheta()); - if(mE > 1168 && mE < 1178){ - obj.FillHistogram("position", "theta_LaBr_1173", - 1024, 0., TMath::Pi(), - hit.GetTheta()); - } - - } - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, mE); - - obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, hit.NumberOfInteractions()); - - // Symmetrized gamma-gamma matrix and angular correlation - for(int y=x+1; ySize(); y++){ - TGretinaHit hit2 = gretina->GetGretinaHit(y); - if(hit2.GetCrystalId() == 136) // Ignore LaBr - continue; - - Double_t mE2 = measuredE(hit2.GetCoreEnergy()); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE, - energyNChannels/4, energyLlim, energyUlim, mE2); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE2, - energyNChannels/4, energyLlim, energyUlim, mE); - } - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - "segfold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, segment_fold); - - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", "energy_A", - energyNChannels, energyLlim, energyUlim, mE); - else - obj.FillHistogram("energy", "energy_B", - energyNChannels, energyLlim, energyUlim, mE); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - obj.FillHistogram("position", "theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - for(int y=0; y < hit.NumberOfInteractions(); y++){ - - int layer = hit.GetSegmentId(y)/6; - - if(layer > max_layer) max_layer = layer; - - obj.FillHistogram("layers", - Form("theta_vs_phi_%s", LayerMap[layer].c_str()), - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - obj.FillHistogram("layers", "max_layer", 12, -2, 10, - max_layer); - - if(max_layer == 5){ - obj.FillHistogram("energy", "energy_involves_phi", - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", "overview_involves_phi", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - } - - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("energy", - Form("energy_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", - Form("energy_A_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - else - obj.FillHistogram("energy", - Form("energy_B_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - } - - } - - } - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistos60CoSim.cxx b/histos/MakeHistos60CoSim.cxx deleted file mode 100644 index da8bdcf1..00000000 --- a/histos/MakeHistos60CoSim.cxx +++ /dev/null @@ -1,489 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -Double_t measuredE(Double_t energy){ - Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); - if(std::isnan(resPar1)) - resPar1 = 1.2; - Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); - if(std::isnan(resPar2)) - resPar2 = 0.0005; - - return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - Int_t energyNChannels = 4000; - Double_t energyLlim = 0.; - Double_t energyUlim = 4000.; - Double_t cosTheta = -1; - Double_t mCosTheta = -1; - Double_t x1 = -1; - Double_t y1 = -1; - Double_t z1 = -1; - Double_t x2 = -1; - Double_t y2 = -1; - Double_t z2 = -1; - - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - if(hit.GetEn() > 1331 && hit.GetEn() < 1334){ - x1 = sin(hit.GetTheta())*cos(hit.GetPhi()); - y1 = sin(hit.GetTheta())*sin(hit.GetPhi()); - z1 = cos(hit.GetTheta()); - } - if(hit.GetEn() > 1171 && hit.GetEn() < 1175){ - x2 = sin(hit.GetTheta())*cos(hit.GetPhi()); - y2 = sin(hit.GetTheta())*sin(hit.GetPhi()); - z2 = cos(hit.GetTheta()); - } - } - cosTheta - = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); - obj.FillHistogram("sim","emitted_delta", - 100, -1, 1., - cosTheta); - } - - if(!gretina) - return; - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - // Gamma-gated crystal spectrum - Double_t eGateLlim = 1327.5; - Double_t eGateUlim = 1337.5; - int iGate = -1; - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if( hit.GetCoreEnergy() > eGateLlim && - hit.GetCoreEnergy() < eGateUlim ) - iGate = i; - } - if(iGate>=0){ - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if(i != iGate){ - Double_t mE = measuredE(hit.GetCoreEnergy()); - obj.FillHistogram("energy", - Form("energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", - Form("fold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, hit.NumberOfInteractions()); - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - Form("segfold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, segment_fold); - - } - } - } - - // Addback preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += measuredE(hit.GetCoreEnergy()); - hits.push_back(hit); - - } - } - - int max_layer = -1; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - Double_t mE = measuredE(hit.GetCoreEnergy()); - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, mE); - - obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, hit.NumberOfInteractions()); - - // Symmetrized gamma-gamma matrix and angular correlation - for(int y=x+1; ySize(); y++){ - TGretinaHit hit2 = gretina->GetGretinaHit(y); - Double_t mE2 = measuredE(hit2.GetCoreEnergy()); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE, - energyNChannels/4, energyLlim, energyUlim, mE2); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE2, - energyNChannels/4, energyLlim, energyUlim, mE); - - if( (mE > 1168. && mE < 1178. && mE2 > 1328. && mE2 < 1337.) - || (mE2 > 1168. && mE2 < 1178. && mE > 1328. && mE < 1337.) ){ - TVector3 r1 = hit.GetFirstIntPosition_2(); - TVector3 r2 = hit2.GetFirstIntPosition_2(); - mCosTheta = r1.Dot(r2)/r1.Mag()/r2.Mag(); - obj.FillHistogram("position","delta", - 100, -1, 1., - mCosTheta); - obj.FillHistogram("position","cosTheta_mCosTheta", - 100, -1, 1., - cosTheta, - 100, -1, 1., - mCosTheta); - } - - } - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - "segfold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, segment_fold); - - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", "energy_A", - energyNChannels, energyLlim, energyUlim, mE); - else - obj.FillHistogram("energy", "energy_B", - energyNChannels, energyLlim, energyUlim, mE); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - // Position spectra in crystal coordinates - if(hit.NumberOfInteractions()){ - obj.FillHistogram("position", - Form("crys_%d_x", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X()); - - obj.FillHistogram("position", - Form("crys_%d_y", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_z", hit.GetCrystalId()), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_xy", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_xz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_yz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - } - - for(int y=0; y < hit.NumberOfInteractions(); y++){ - - int layer = hit.GetSegmentId(y)/6; - - if(layer > max_layer) max_layer = layer; - - obj.FillHistogram("layers", - Form("theta_vs_phi_%s", LayerMap[layer].c_str()), - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - obj.FillHistogram("layers", "max_layer", 12, -2, 10, - max_layer); - - if(max_layer == 5){ - obj.FillHistogram("energy", "energy_involves_phi", - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", "overview_involves_phi", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - } - - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("energy", - Form("energy_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", - Form("energy_A_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - else - obj.FillHistogram("energy", - Form("energy_B_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, mE); - } - - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("addback", - Form("calorimeter_below_%s", - LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - } - } - - // For energy-gated addback spectra - std::vector ABenergy; - std::vector ABtype; - Int_t Naddback = 0; - iGate = -1; - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1) - addbackType = "addback_n0"; - else if(neighbors == 1 && cluster.size() == 2) - addbackType = "addback_n1"; - else if(neighbors == 3 && cluster.size() == 3) - addbackType = "addback_n2"; - else - addbackType = "addback_ng"; - - // Fill addback histograms. - - obj.FillHistogram("addback", addbackType, - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - - if(addbackType == "addback_n0" - || addbackType == "addback_n1"){ - obj.FillHistogram("addback", "addback_n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - if(addbackType == "addback_n0" - || addbackType == "addback_n1" - || addbackType == "addback_n2"){ - obj.FillHistogram("addback", "addback_n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - - // For energy-gated addback spectra - if(addbackEnergy > eGateLlim && - addbackEnergy < eGateUlim) - iGate = Naddback; - - ABenergy.push_back(addbackEnergy); - ABtype.push_back(addbackType); - Naddback++; - - } - - // Fill energy-gated addback spectra - if(iGate >= 0){ - for(int i = 0; iGetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistosFDS.cxx b/histos/MakeHistosFDS.cxx deleted file mode 100644 index 86e85a43..00000000 --- a/histos/MakeHistosFDS.cxx +++ /dev/null @@ -1,250 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" - -Double_t measuredE(Double_t energy){ - Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); - if(std::isnan(resPar1)) - resPar1 = 1.2; - Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); - if(std::isnan(resPar2)) - resPar2 = 0.0005; - - return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - Int_t energyNChannels = 4000; - Double_t energyLlim = 0.; - Double_t energyUlim = 4000.; - - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - } - } - - if(!gretina) - return; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - Double_t mE = measuredE(hit.GetCoreEnergy()); - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, mE, - 250, 0, 250, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, mE); - - if(gretSim && gretSim->Size()>0) - if(gretSim->GetGretinaSimHit(0).IsFEP()) - obj.FillHistogram("energy", "photopeak", - energyNChannels, energyLlim, energyUlim, mE); - - obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, mE, - 20, 0, 20, hit.NumberOfInteractions()); - - // Symmetrized gamma-gamma matrix - for(int y=x+1; ySize(); y++){ - TGretinaHit hit2 = gretina->GetGretinaHit(y); - Double_t mE2 = measuredE(hit2.GetCoreEnergy()); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE, - energyNChannels/4, energyLlim, energyUlim, mE2); - obj.FillHistogram("energy", "gamma_gamma", - energyNChannels/4, energyLlim, energyUlim, mE2, - energyNChannels/4, energyLlim, energyUlim, mE); - } - - // crmat/crystal Transformations turned off for FDS, so local positions - // are in world coordinates. - TVector3 hitpos = hit.GetLocalPosition(0); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta_vs_phi", - // 360, 0., 360., - 360, -180., 180., - hitpos.Phi()*TMath::RadToDeg(), - 180, 0., 180., - hitpos.Theta()*TMath::RadToDeg()); - // hit.GetPhi()*TMath::RadToDeg(), - // 180, 0., 180., - // hit.GetTheta()*TMath::RadToDeg()); - - if(hit.GetSegmentId(0)==1) - obj.FillHistogram("position", "theta_vs_phi_R", - 360, -180., 180., - hitpos.Phi()*TMath::RadToDeg(), - 180, 0., 180., - hitpos.Theta()*TMath::RadToDeg()); - if(hit.GetSegmentId(0)==2){ - obj.FillHistogram("position", "theta_vs_phi_M", - 360, -180., 180., - hitpos.Phi()*TMath::RadToDeg(), - 180, 0., 180., - hitpos.Theta()*TMath::RadToDeg()); - if(hit.GetCrystalId()%4 == 0 || hit.GetCrystalId()%4 == 3) - obj.FillHistogram("position", "theta_vs_phi_MR", - 360, -180., 180., - hitpos.Phi()*TMath::RadToDeg(), - 180, 0., 180., - hitpos.Theta()*TMath::RadToDeg()); - if(hit.GetCrystalId()%4 == 1 || hit.GetCrystalId()%4 == 2) - obj.FillHistogram("position", "theta_vs_phi_ML", - 360, -180., 180., - hitpos.Phi()*TMath::RadToDeg(), - 180, 0., 180., - hitpos.Theta()*TMath::RadToDeg()); - } - if(hit.GetSegmentId(0)==3){ - obj.FillHistogram("position", "theta_vs_phi_L", - 360, -180., 180., - hitpos.Phi()*TMath::RadToDeg(), - 180, 0., 180., - hitpos.Theta()*TMath::RadToDeg()); - } - - // Position spectra in crystal coordinates - if(hit.NumberOfInteractions()){ - - obj.FillHistogram("position", "r", 500, 0, 500, hitpos.Mag()); - obj.FillHistogram("position", "x", 1000, -500, 500, hitpos.X()); - obj.FillHistogram("position", "y", 1000, -500, 500, hitpos.Y()); - obj.FillHistogram("position", "z", 1000, -500, 500, hitpos.Z()); - - obj.FillHistogram("position", - Form("crys_%d_x", hit.GetCrystalId()), - 1000, -500, 500, hit.GetLocalPosition(0).X()); - - obj.FillHistogram("position", - Form("crys_%d_y", hit.GetCrystalId()), - 1000, -500, 500, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_z", hit.GetCrystalId()), - 1000, -500, 500, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_r", hit.GetCrystalId()), - 500, 0, 500, hit.GetLocalPosition(0).Mag()); - - obj.FillHistogram("position", - Form("crys_%d_xy", hit.GetCrystalId()), - 100, -500, 500, hit.GetLocalPosition(0).X(), - 100, -500, 500, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_xz", hit.GetCrystalId()), - 100, -500, 500, hit.GetLocalPosition(0).X(), - 100, -500, 500, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_yz", hit.GetCrystalId()), - 100, -500, 500, hit.GetLocalPosition(0).Y(), - 100, -500, 500, hit.GetLocalPosition(0).Z()); - } - - } - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - // Addback preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += measuredE(hit.GetCoreEnergy()); - hits.push_back(hit); - - } - } - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - // Same clover - if(cluster[i].GetHoleNumber() == hits[j].GetHoleNumber()){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - for(int i = 0; i < cluster.size(); i++) - addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); - - // Fill addback histograms. - - obj.FillHistogram("energy", "addback", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistosInBeamAngCorr.cxx b/histos/MakeHistosInBeamAngCorr.cxx deleted file mode 100644 index 032e46b9..00000000 --- a/histos/MakeHistosInBeamAngCorr.cxx +++ /dev/null @@ -1,610 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TBank29.h" -#include "TS800.h" -#include "TS800Sim.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -Double_t ProjectileTheta(Double_t theta, Double_t beta){ - // std::cout << theta << ", " << beta - // << ", " - // << (TMath::Cos(theta) - beta)/(1 - beta*TMath::Cos(theta)) - // << ", " - // << TMath::ACos( (TMath::Cos(theta) - beta)/(1 - beta*TMath::Cos(theta)) ) - // << std::endl; - return TMath::ACos( (TMath::Cos(theta) - beta)/(1 - beta*TMath::Cos(theta)) ); -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TS800Sim *s800Sim = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset,yoffset,zoffset); - - Int_t energyNChannels = 8192; - Double_t energyLlim = 0.; - Double_t energyUlim = 8192.; - Double_t cosTheta = -1; - Double_t mCosTheta = -1; - Double_t x1 = -1; - Double_t y1 = -1; - Double_t z1 = -1; - Double_t x2 = -1; - Double_t y2 = -1; - Double_t z2 = -1; - - if(gretSim){ - - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_proj_theta", - 180, 0., 180., - ProjectileTheta(hit.GetTheta(), - beta)*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - obj.FillHistogram("sim","beta", - 500, 0, 0.5, - hit.GetBeta()); - obj.FillHistogram("sim","beta_z", - 1000,-5,5., - hit.GetZ(), - 300, 0.2, 0.5, - hit.GetBeta()); - if(x==0){ - Double_t th = ProjectileTheta(hit.GetTheta(), beta); - x1 = TMath::Sin(th)*TMath::Cos(hit.GetPhi()); - y1 = TMath::Sin(th)*TMath::Sin(hit.GetPhi()); - z1 = TMath::Cos(th); - } - if(x==1){ - Double_t th = ProjectileTheta(hit.GetTheta(), beta); - x2 = TMath::Sin(th)*TMath::Cos(hit.GetPhi()); - y2 = TMath::Sin(th)*TMath::Sin(hit.GetPhi()); - z2 = TMath::Cos(th); - } - } - cosTheta - = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); - obj.FillHistogram("sim","emitted_delta", - 100, -1, 1., - cosTheta); - } - - if(!s800Sim) - return; - - if(s800Sim->Size() > 0){ - // std::cout << "In MakeHistos:" << std::endl; - - // std::cout << " time stamp = " - // << s800Sim->Timestamp() << std::endl; - - // std::cout << " size = " - // << s800Sim->Size() - // << std::endl; - - // std::cout << std::flush; - - Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); - - // std::cout << " ATA = " - // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; - - // std::cout << " BTA = " - // << s800Sim->GetS800SimHit(0).GetBTA() << std::endl; - - // std::cout << " DTA = " - // << dta << std::endl; - - - obj.FillHistogram("s800","dta", - 200, -0.10, 0.10, - dta); - - // Rough dta acceptance cut - if(dta < -0.06 || dta > 0.06) - return; - - obj.FillHistogram("s800","dta_cut", - 200, -0.10, 0.10, - dta); - - obj.FillHistogram("s800","ata", - 200, -100, 100, - s800Sim->GetS800SimHit(0).GetATA()); - - obj.FillHistogram("s800","bta", - 200, -100, 100, - s800Sim->GetS800SimHit(0).GetBTA()); - - Double_t xsin, ysin, scatter; - - xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); - ysin = -sin(s800Sim->GetS800SimHit(0).GetBTA()/1000.); - scatter = asin(sqrt(xsin*xsin + ysin*ysin))*1000.; - - obj.FillHistogram("s800","scatter", - 4096, 0, 300, - scatter); - } - - if(!gretina) - return; - - // (optionally define extra beta values in gvalues file) - const Int_t nBetas = 1; - Double_t betas[nBetas] = {beta}; - - Double_t calorimeterEnergy = 0.; - Double_t calorimeterEnergy_gaus = 0.; - std::vector hits; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Addback preprocessing - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += hit.GetCoreEnergy(); - calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - hits.push_back(hit); - - } - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - obj.FillHistogram("energy", "overview_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - - for(int i=0; iGaus(1,1./1000.); - for(int y=x+1; ySize(); y++){ - - TGretinaHit hit2 = gretina->GetGretinaHit(y); - Double_t e2 = hit2.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.); - - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/16, energyLlim, energyUlim/2, e1, - energyNChannels/16, energyLlim, energyUlim/2, e2); - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/8, energyLlim, energyUlim, e2, - energyNChannels/8, energyLlim, energyUlim, e1); - - if( (e1 > 1110. && e1 < 1145. && e2 > 1305. && e2 < 1350.) - || (e2 > 1110. && e2 < 1145. && e1 > 1305. && e1 < 1350.) ){ - //TVector3 r1 = hit.GetFirstIntPosition_2(); - //TVector3 r2 = hit2.GetFirstIntPosition_2(); - // mCosTheta = r1.Dot(r2)/r1.Mag()/r2.Mag(); - Double_t th = ProjectileTheta(hit.GetTheta(), beta); - x1 = sin(th)*cos(hit.GetPhi()); - y1 = sin(th)*sin(hit.GetPhi()); - z1 = cos(th); - th = ProjectileTheta(hit2.GetTheta(), beta); - x2 = sin(th)*cos(hit2.GetPhi()); - y2 = sin(th)*sin(hit2.GetPhi()); - z2 = cos(th); - mCosTheta - = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); - obj.FillHistogram("position","delta", - 100, -1, 1., mCosTheta); - obj.FillHistogram("position","cosTheta_mCosTheta", - 100, -1, 1., - cosTheta, - 100, -1, 1., - mCosTheta); - } - } - - obj.FillHistogram("energy", - Form("dop_%.0f", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])); - - obj.FillHistogram("energy", - Form("dop_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("energy", - Form("dop_fw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } else { - obj.FillHistogram("energy", - Form("dop_bw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } - } - - obj.FillHistogram("position", "theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - obj.FillHistogram("position", "theta_proj", - 180, 0., 180., - ProjectileTheta(hit.GetTheta(), beta)*TMath::RadToDeg()); - - obj.FillHistogram("position", "phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - obj.FillHistogram("position", "theta_vs_phi_proj", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - ProjectileTheta(hit.GetTheta(), beta)*TMath::RadToDeg()); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("position", "theta_vs_phi_fw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } else { - obj.FillHistogram("position", "theta_vs_phi_bw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - obj.FillHistogram("addback", "calorimeter_gaus", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy_gaus); - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - Double_t addbackEnergy_gaus = 0.; - TVector3 firstHitPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - addbackEnergy_gaus += - cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - // Find the largest IP in the cluster and save its position - // for Doppler correction. - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) - > firstHitEnergy){ - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; - firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy[nBetas] = {0.}; - Double_t dopplerABEnergy_gaus[nBetas] = {0.}; - for(int b=0; bGetSize()) - list->Sort(); - -} diff --git a/histos/MakeHistosNeutrons.cxx b/histos/MakeHistosNeutrons.cxx deleted file mode 100644 index 26023166..00000000 --- a/histos/MakeHistosNeutrons.cxx +++ /dev/null @@ -1,364 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - // TBank29 *bank29 = obj.GetDetector(); - // TS800 *s800 = obj.GetDetector() - TGretSim *gretSim = obj.GetDetector(); - - Int_t energyNChannels = 10000; - Double_t energyLlim = 0.; - Double_t energyUlim = 10000.; - - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_x", - 2000,-100., 100., - hit.GetX()); - obj.FillHistogram("sim","emitted_y", - 2000,-100., 100., - hit.GetY()); - obj.FillHistogram("sim","emitted_z", - 2000,-100., 100., - hit.GetZ()); - } - } - - if(!gretina) - return; - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - for(int x=0; xSize(); x++){ - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Addback preprocessing - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += hit.GetCoreEnergy(); - - hits.push_back(hit); - - } - - // directory, histogram - // obj.FillHistogram("energy", "overview", - // energyNChannels, energyLlim, energyUlim, - // hit.GetCoreEnergy(), - // 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - obj.FillHistogram("energy", "energy_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - - if(gretSim && gretSim->Size()>0){ - TGretSimHit simhit = gretSim->GetGretinaSimHit(0); - obj.FillHistogram("energy", "GT_energy_gaus_vs_neutron_energy", - energyNChannels/5, energyLlim, energyUlim, - simhit.GetEn(), - energyNChannels/5, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - obj.FillHistogram("energy", "neutron_energy_minus_GT_energy_gaus", - 2*energyNChannels, -energyUlim, energyUlim, - simhit.GetEn() - - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - if( simhit.GetEn() < hit.GetCoreEnergy() ) - obj.FillHistogram("energy", "GT_energy_gaus_EGT_gt_En", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - } - - obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, hit.NumberOfInteractions()); - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - "segfold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, segment_fold); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - TGretSimHit simhit = gretSim->GetGretinaSimHit(0); - if(gretSim){ - if(gretSim->Size()){ - Double_t p = simhit.GetPhi(); - p += TMath::Pi()/2.; - if(p>TMath::TwoPi()) - p -= TMath::TwoPi(); - Double_t azimuthal = hit.GetPhi()-p+TMath::Pi(); - if(azimuthal>TMath::TwoPi()) - azimuthal -= TMath::TwoPi(); - obj.FillHistogram("position", "phi_GT_phi_n", - 360, 0., TMath::TwoPi(), - hit.GetPhi(), - 360, 0., TMath::TwoPi(), - p); - obj.FillHistogram("position", "azimuthal", - 540, 0., 3.*TMath::Pi(), - azimuthal); - - if(azimuthal > 2.5 && azimuthal < 4.){ - obj.FillHistogram("position", "phi_GT_phi_n_azimuthal", - 360, 0., TMath::TwoPi(), - hit.GetPhi(), - 360, 0., TMath::TwoPi(), - p); - obj.FillHistogram("energy", "energy_gaus_azimuthal", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - } - - } - } - - int max_layer = -1; - for(int y=0; y < hit.NumberOfInteractions(); y++){ - - int layer = hit.GetSegmentId(y)/6; - - if(layer > max_layer) max_layer = layer; - - obj.FillHistogram("layers", - Form("theta_vs_phi_%s", LayerMap[layer].c_str()), - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - obj.FillHistogram("layers", "max_layer", 12, -2, 10, - max_layer); - - if(max_layer == 5){ - obj.FillHistogram("energy", "energy_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - obj.FillHistogram("energy", "overview_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - } - - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("energy", - Form("energy_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", - Form("energy_A_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - else - obj.FillHistogram("energy", - Form("energy_B_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - } - - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - - // For energy-gated addback spectra - Double_t ABenergy[100]; - TString ABtype[100]; - Int_t Naddback = 0; - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1) - addbackType = "addback_n0"; - else if(neighbors == 1 && cluster.size() == 2) - addbackType = "addback_n1"; - else if(neighbors == 3 && cluster.size() == 3) - addbackType = "addback_n2"; - else - addbackType = "addback_ng"; - - // Fill addback histograms. - - obj.FillHistogram("addback", addbackType, - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - - if(addbackType == "addback_n0" - || addbackType == "addback_n1"){ - obj.FillHistogram("addback", "addback_n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - if(addbackType == "addback_n0" - || addbackType == "addback_n1" - || addbackType == "addback_n2"){ - obj.FillHistogram("addback", "addback_n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - - ABenergy[Naddback] = addbackEnergy; - ABtype[Naddback] = addbackType; - Naddback++; - - } - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistosOslo.cxx b/histos/MakeHistosOslo.cxx deleted file mode 100644 index 13f07c43..00000000 --- a/histos/MakeHistosOslo.cxx +++ /dev/null @@ -1,156 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" - -#define Q1 15 -#define Q2 7 -#define Q3 8 -#define Q4 16 -#define Q5 9 -#define Q6 14 -#define Q7 17 -#define Q8 6 -#define Q9 19 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -Double_t measuredE(Double_t energy){ - Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); - if(std::isnan(resPar1)) - resPar1 = 2.650474517; - Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); - if(std::isnan(resPar2)) - resPar2 = 0.000838828; - - if( !(resPar1 + resPar2 > 0) ) - return energy; - - return gRandom->Gaus(energy, (resPar1+energy*resPar2)/2.355); - -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - Int_t energyNChannels = 10000; - Double_t energyLlim = 0.; - Double_t energyUlim = 10000.; - - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - } - } - - if(!gretina) - return; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - Double_t mE = measuredE(hit.GetCoreEnergy()); - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, mE); - - if(gretSim && gretSim->Size()>0){ - TGretSimHit simHit = gretSim->GetGretinaSimHit(0); - obj.FillHistogram("energy","emitted_energy_vs_energy", - energyNChannels/10, energyLlim, energyUlim, - mE, - energyNChannels/10, energyLlim, energyUlim, - simHit.GetEn()); - } - if(gretSim && gretSim->Size()>0 && - gretSim->GetGretinaSimHit(0).IsFEP()){ - obj.FillHistogram("energy", "photopeak", - energyNChannels, energyLlim, energyUlim, mE); - obj.FillHistogram("energy", "overview_photopeak", - energyNChannels, energyLlim, energyUlim, mE, - 100, 0, 100, hit.GetCrystalId()); - } - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistosPencil.cxx b/histos/MakeHistosPencil.cxx deleted file mode 100644 index dee3c737..00000000 --- a/histos/MakeHistosPencil.cxx +++ /dev/null @@ -1,402 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -std::map LayerMap; - -void InitMap() { - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - // TBank29 *bank29 = obj.GetDetector(); - // TS800 *s800 = obj.GetDetector(); - - if(!gretina) - return; - - Int_t energyNChannels = 4000; - Double_t energyLlim = 0.; - Double_t energyUlim = 4000.; - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - // Gamma-gated crystal spectrum - Double_t eGateLlim = 1327.5; - Double_t eGateUlim = 1337.5; - int iGate = -1; - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if( hit.GetCoreEnergy() > eGateLlim && - hit.GetCoreEnergy() < eGateUlim ) - iGate = i; - } - if(iGate>=0){ - for(int i=0; iSize(); i++){ - TGretinaHit hit = gretina->GetGretinaHit(i); - if(i != iGate){ - obj.FillHistogram("energy", - Form("energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - obj.FillHistogram("energy", - Form("fold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, hit.NumberOfInteractions()); - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - Form("segfold_vs_energy_%.0f", - (eGateLlim+eGateUlim)/2.0), - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, segment_fold); - - } - } - } - - for(int x=0; xSize(); x++){ - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Addback preprocessing - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += hit.GetCoreEnergy(); - - hits.push_back(hit); - - } - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - obj.FillHistogram("energy", "fold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, hit.NumberOfInteractions()); - - // Count segment fold - int segment_fold = hit.NumberOfInteractions(); - for(int y=0; y < hit.NumberOfInteractions(); y++) - for(int z = y+1; z < hit.NumberOfInteractions(); z++) - if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ - segment_fold--; - break; - } - - obj.FillHistogram("energy", - "segfold_vs_energy", - energyNChannels/8, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 20, 0, 20, segment_fold); - - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", "energy_A", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - else - obj.FillHistogram("energy", "energy_B", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - // Position spectra in crystal coordinates - if(hit.NumberOfInteractions()){ - obj.FillHistogram("position", "world_x", - 1400, 20, 160, hit.GetInteractionPosition(0).X()); - obj.FillHistogram("position", "world_y", - 1400, -280, -140, hit.GetInteractionPosition(0).Y()); - obj.FillHistogram("position", "world_z", - 1400, 20, 160, hit.GetInteractionPosition(0).Z()); - obj.FillHistogram("position", - Form("world_xy", hit.GetCrystalId()), - 1400, 20, 160, hit.GetInteractionPosition(0).X(), - 1400, -280, -140, hit.GetInteractionPosition(0).Y()); - obj.FillHistogram("position", - Form("world_xz", hit.GetCrystalId()), - 1400, 20, 160, hit.GetInteractionPosition(0).X(), - 1400, 20, 160, hit.GetInteractionPosition(0).Z()); - obj.FillHistogram("position", - Form("world_zy", hit.GetCrystalId()), - 1400, 20, 160, hit.GetInteractionPosition(0).Z(), - 1400, -280, -140, hit.GetInteractionPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_x", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X()); - - obj.FillHistogram("position", - Form("crys_%d_y", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_z", hit.GetCrystalId()), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_xy", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -60, 60, hit.GetLocalPosition(0).Y()); - - obj.FillHistogram("position", - Form("crys_%d_xz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).X(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - - obj.FillHistogram("position", - Form("crys_%d_yz", hit.GetCrystalId()), - 1200, -60, 60, hit.GetLocalPosition(0).Y(), - 1200, -10, 100, hit.GetLocalPosition(0).Z()); - } - - int max_layer = -1; - for(int y=0; y < hit.NumberOfInteractions(); y++){ - - int layer = hit.GetSegmentId(y)/6; - - if(layer > max_layer) max_layer = layer; - - obj.FillHistogram("layers", - Form("theta_vs_phi_%s", LayerMap[layer].c_str()), - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - obj.FillHistogram("layers", "max_layer", 12, -2, 10, - max_layer); - - if(max_layer == 5){ - obj.FillHistogram("energy", "energy_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - obj.FillHistogram("energy", "overview_involves_phi", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - } - - for(int k = 5; k > 0; k--){ - if(max_layer < k){ - obj.FillHistogram("energy", - Form("energy_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - if( hit.GetCrystalId()%2 ) - obj.FillHistogram("energy", - Form("energy_A_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - else - obj.FillHistogram("energy", - Form("energy_B_below_%s", LayerMap[k].c_str()), - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - } - - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - - // For energy-gated addback spectra - Double_t ABenergy[100]; - TString ABtype[100]; - Int_t Naddback = 0; - iGate = -1; - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1) - addbackType = "addback_n0"; - else if(neighbors == 1 && cluster.size() == 2) - addbackType = "addback_n1"; - else if(neighbors == 3 && cluster.size() == 3) - addbackType = "addback_n2"; - else - addbackType = "addback_ng"; - - // Fill addback histograms. - - obj.FillHistogram("addback", addbackType, - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - - if(addbackType == "addback_n0" - || addbackType == "addback_n1"){ - obj.FillHistogram("addback", "addback_n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - if(addbackType == "addback_n0" - || addbackType == "addback_n1" - || addbackType == "addback_n2"){ - obj.FillHistogram("addback", "addback_n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - } - - obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - - // For energy-gated addback spectra - if(addbackEnergy > eGateLlim && - addbackEnergy < eGateUlim) - iGate = Naddback; - - ABenergy[Naddback] = addbackEnergy; - ABtype[Naddback] = addbackType; - Naddback++; - - } - - // Fill energy-gated addback spectra - if(iGate >= 0){ - for(int i = 0; iGetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistosTarEx.cxx b/histos/MakeHistosTarEx.cxx deleted file mode 100644 index ccdcc86b..00000000 --- a/histos/MakeHistosTarEx.cxx +++ /dev/null @@ -1,430 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TBank29.h" -#include "TS800.h" -#include "TS800Sim.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" -#include "GValue.h" - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - - TGretina *gretina = obj.GetDetector(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TS800Sim *s800Sim = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - Int_t energyNChannels = 8192; - Double_t energyLlim = 0.; - Double_t energyUlim = 8192.; - - if(gretSim){ - if(gretSim->Size() > 0){ - obj.FillHistogram("sim","beta", - 1000, 0, 1.0, - gretSim->GetGretinaSimHit(0).GetBeta()); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - gretSim->GetGretinaSimHit(0).GetEn()); - obj.FillHistogram("sim","z", - 1000,-5,5., - gretSim->GetGretinaSimHit(0).GetZ()); - obj.FillHistogram("sim","beta_z", - 1000,-5,5., - gretSim->GetGretinaSimHit(0).GetZ(), - 300, 0.3, 0.6, - gretSim->GetGretinaSimHit(0).GetBeta()); - } - } - - if(!gretina) - return; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset,yoffset,zoffset); - - // (optionally define extra beta values in gvalues file) - const Int_t nBetas = 1; - Double_t betas[nBetas] = {beta}; - - Double_t calorimeterEnergy = 0.; - Double_t calorimeterEnergy_gaus = 0.; - std::vector hits; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Addback preprocessing - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += hit.GetCoreEnergy(); - calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - hits.push_back(hit); - - } - - // directory, histogram - obj.FillHistogram("energy", "overview", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - obj.FillHistogram("energy", "overview_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), - 100, 0, 100, hit.GetCrystalId()); - - obj.FillHistogram("energy", "energy_gaus", - energyNChannels, energyLlim, energyUlim, - hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); - - for(int i=0; iGaus(1,1./1000.); - for(int y=x+1; ySize(); y++){ - - TGretinaHit hit2 = gretina->GetGretinaHit(y); - Double_t e2 = hit2.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.); - - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/16, energyLlim, energyUlim/2, e1, - energyNChannels/16, energyLlim, energyUlim/2, e2); - obj.FillHistogram("energy", - Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), - energyNChannels/8, energyLlim, energyUlim, e2, - energyNChannels/8, energyLlim, energyUlim, e1); - } - - obj.FillHistogram("energy", - Form("dop_%.0f", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])); - - obj.FillHistogram("energy", - Form("dop_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("energy", - Form("dop_fw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } else { - obj.FillHistogram("energy", - Form("dop_bw_%.0f_gaus", betas[i]*10000), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(betas[i])*gRandom->Gaus(1,1./1000.)); - } - } - - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - if(hit.GetHoleNumber() < 10){ - obj.FillHistogram("position", "theta_vs_phi_fw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } else { - obj.FillHistogram("position", "theta_vs_phi_bw", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - } - - } - - // Addback - obj.FillHistogram("addback", "calorimeter", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy); - obj.FillHistogram("addback", "calorimeter_gaus", - energyNChannels, energyLlim, energyUlim, - calorimeterEnergy_gaus); - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - obj.FillHistogram("position", "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - Double_t addbackEnergy_gaus = 0.; - TVector3 firstHitPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - addbackEnergy_gaus += - cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); - - // Find the largest IP in the cluster and save its position - // for Doppler correction. - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) - > firstHitEnergy){ - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; - firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy[nBetas] = {0.}; - Double_t dopplerABEnergy_gaus[nBetas] = {0.}; - for(int b=0; bGetSize()) - list->Sort(); - -} diff --git a/histos/MakeHistosWhiteSim.cxx b/histos/MakeHistosWhiteSim.cxx deleted file mode 100644 index 2a26b90e..00000000 --- a/histos/MakeHistosWhiteSim.cxx +++ /dev/null @@ -1,179 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "TGretSim.h" -#include "GValue.h" - - -#include "TChannel.h" - -// Not actual mapping -#define Q1 6 -#define Q2 7 -#define Q3 8 -#define Q4 9 -#define Q5 14 -#define Q6 15 -#define Q7 21 -#define Q8 22 -#define Q9 24 -#define Q10 25 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - HoleQMap[Q10] = 10; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -Double_t measuredE(Double_t energy){ - - Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); - if(std::isnan(resPar1)) - resPar1 = 0.; - Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); - if(std::isnan(resPar2)) - resPar2 = 0.; - - if(!(resPar1 + resPar2) > 0) - return energy; - - return energy*gRandom->Gaus(1.0, exp(resPar1*log(energy)+resPar2)); -} - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - // TBank29 *bank29 = obj.GetDetector(); - // TS800 *s800 = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - - Int_t energyNChannels = 8000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - if(!gretSim) - return; - - Double_t eE = 0.; - Bool_t fE = false; - if(gretSim){ - for(int x=0; xSize(); x++){ - TGretSimHit hit = gretSim->GetGretinaSimHit(x); - eE = hit.GetEn(); - fE = hit.IsFEP(); - obj.FillHistogram("sim","emitted_energy", - energyNChannels, energyLlim, energyUlim, - hit.GetEn()); - obj.FillHistogram("sim","emitted_theta", - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg()); - obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., - hit.GetZ()); - obj.FillHistogram("sim","full_energy", - 3, -1, 2, - hit.IsFEP()); - obj.FillHistogram("sim","beta", - 1000, 0., 1.0, - hit.GetBeta()); - } - } - - if(!gretina) - return; - - // Double_t res = 1./1000.; // Relative energy resolution - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - // Addback preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if(hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim){ - - calorimeterEnergy += measuredE(hit.GetCoreEnergy()); - hits.push_back(hit); - - } - } - - int max_layer = -1; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - Double_t mE = measuredE(hit.GetCoreEnergy()); - - // directory, histogram - obj.FillHistogram("energy", "energy", - energyNChannels, energyLlim, energyUlim, mE); - - if(fE) - obj.FillHistogram("energy", "full_energy", - energyNChannels, energyLlim, energyUlim, mE); - - obj.FillHistogram("energy", "emitted_vs_detected", - energyNChannels/10, energyLlim, energyUlim, mE, - energyNChannels/10, energyLlim, energyUlim, eE); - - // Peter wrote these to give Dirk his Phi range (0-360). - obj.FillHistogram("position", "theta_vs_phi", - 360, 0., 360., - hit.GetPhi()*TMath::RadToDeg(), - 180, 0., 180., - hit.GetTheta()*TMath::RadToDeg()); - - } - - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/histos/MakeHistos_e10010.cxx b/histos/MakeHistos_e10010.cxx deleted file mode 100644 index aeb9da18..00000000 --- a/histos/MakeHistos_e10010.cxx +++ /dev/null @@ -1,705 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p43=0; -GCutG *incoming_s44=0; -GCutG *incoming_cl46=0; - -GCutG *outgoing_s44=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge()) ) - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 2000, 3000, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -2500, -1500, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 30000, 70000, - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - Int_t energyNChannels = 1000; - Double_t energyLlim = 0.; - Double_t energyUlim = 4000.; - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - Double_t calorimeterEnergy = 0.; - std::vector hits; - - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - // Preprocessing - if( hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ){ - - calorimeterEnergy += hit.GetCoreEnergy(); - - if( hit.HasInteractions() ) - hits.push_back(hit); - - } - } - - // Addback - obj.FillHistogram(dirname, - "calorimeter", - 1000, 0, 4000, - calorimeterEnergy); - - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < 80.){ // Neighbors - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - // Find the largest IP in the cluster and save its position - // for Doppler correction. - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) - > firstHitEnergy){ - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - targetOffset; - firstHitEnergy = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < 80.) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1) - addbackType = "n0"; - else if(neighbors == 1 && cluster.size() == 2) - addbackType = "n1"; - else if(neighbors == 3 && cluster.size() == 3) - addbackType = "n2"; - else - addbackType = "ng"; - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - if(firstHitHoleNum < 10){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - if(firstHitHoleNum < 10){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - if(firstHitHoleNum < 10){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().Charge()) ) - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 1000, 0, 4000, - hit.GetDoppler(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 1000, 0, 4000, - hit.GetDoppler(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 1000, 0, 4000, - hit.GetDoppler(beta, 0)); - - // Time cut - if( gt_time && !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 1000, 0, 4000, - hit.GetDoppler(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 1000, 0, 4000, - hit.GetDoppler(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 1000, 0, 4000, - hit.GetDoppler(beta, 0)); - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p43) { - incoming_p43 = (GCutG*)gates->FindObject("incoming_p43"); - } - if(!incoming_s44) { - incoming_s44 = (GCutG*)gates->FindObject("in44S"); - } - if(!incoming_cl46) { - incoming_cl46 = (GCutG*)gates->FindObject("incoming_cl46"); - } - - if(!outgoing_s44) { - outgoing_s44 = (GCutG*)gates->FindObject("out44S"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p43); - IncomingS800(obj, s800, incoming_s44); - IncomingS800(obj, s800, incoming_cl46); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s44); - - DTA(obj, incoming_s44, outgoing_s44); - - if(gretina) { - - HandleGretina(obj, incoming_s44, outgoing_s44, gt_time); - - HandleAddback(obj, incoming_s44, outgoing_s44, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 4000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 4000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 500, 0, 4000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 500, 0, 4000, - hit.GetCoreEnergy()); - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Sim.cxx b/histos/MakeHistos_e10010_Sim.cxx deleted file mode 100644 index a268a7da..00000000 --- a/histos/MakeHistos_e10010_Sim.cxx +++ /dev/null @@ -1,907 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800Sim.h" -#include "TGretSim.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -bool DTA(TRuntimeObjects &obj){ - - TS800Sim *s800Sim = obj.GetDetector(); - - if(!s800Sim || s800Sim->Size() < 1) - return false; - - Double_t dta_min = GValue::Value("DTA_MIN"); - if(std::isnan(dta_min)) - dta_min = -0.06; - Double_t dta_max = GValue::Value("DTA_MAX"); - if(std::isnan(dta_max)) - dta_max = 0.06; - - TS800SimHit hit = s800Sim->GetS800SimHit(0); - - std::string dirname = "S800"; - std::string histname = "dta"; - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - hit.GetDTA()); - histname = "ata"; - obj.FillHistogram(dirname, histname, - 200, -50., 50., - hit.GetATA()); - histname = "bta"; - obj.FillHistogram(dirname, histname, - 200, -50., 50., - hit.GetBTA()); - histname = "ata_bta"; - obj.FillHistogram(dirname, histname, - 200, -50., 50., - hit.GetBTA(), - 200, -50., 50., - hit.GetATA()); - histname = "yta"; - obj.FillHistogram(dirname, histname, - 200, -20, 20, - hit.GetYTA()); - - // Rough DTA cut - if(hit.GetDTA() < dta_max && - hit.GetDTA() > dta_min){ - histname = "dta_acc"; - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - hit.GetDTA()); - histname = "ata_acc"; - obj.FillHistogram(dirname, histname, - 200, -50., 50., - hit.GetATA()); - histname = "bta_acc"; - obj.FillHistogram(dirname, histname, - 200, -50., 50., - hit.GetBTA()); - histname = "ata_bta_acc"; - obj.FillHistogram(dirname, histname, - 200, -50., 50., - hit.GetBTA(), - 200, -50., 50., - hit.GetATA()); - histname = "yta_acc"; - obj.FillHistogram(dirname, histname, - 200, -20, 20, - hit.GetYTA()); - } - - return true; - -} - -Double_t measuredE(Double_t energy, Int_t xtalID){ - - Double_t threshPar1 = GValue::Value(Form("THRESH_PAR_%i_1",xtalID)); - if(std::isnan(threshPar1)) - threshPar1 = 0.; - Double_t threshPar2 = GValue::Value(Form("THRESH_PAR_%i_2",xtalID)); - if(std::isnan(threshPar2)) - threshPar2 = 0.001; - - // std::cout << Form("THRESH_PAR_%i_1",xtalID) << " = " - // << threshPar1 << std::endl; - // std::cout << Form("THRESH_PAR_%i_2",xtalID) << " = " - // << threshPar2 << std::endl; - - Double_t threshold = (1.0 + tanh((energy-threshPar1)/threshPar2))/2.0; - - if(gRandom->Rndm() > threshold) - return -1.; - - Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); - Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); - if(std::isnan(resPar1) || std::isnan(resPar2)) - return energy; - else - return energy*gRandom->Gaus(1.0, exp(resPar1*log(energy)+resPar2)); -} - -bool HandleAddback(TRuntimeObjects &obj) { - - TGretina *gretina = obj.GetDetector(); - TS800Sim *s800Sim = obj.GetDetector(); - - if(!gretina || !s800Sim) - return false; - - //Rough dta acceptance cut - Double_t dta_min = GValue::Value("DTA_MIN"); - if(std::isnan(dta_min)) - dta_min = -0.06; - Double_t dta_max = GValue::Value("DTA_MAX"); - if(std::isnan(dta_max)) - dta_max = 0.06; - if(s800Sim->GetS800SimHit(0).GetDTA() < dta_min || - s800Sim->GetS800SimHit(0).GetDTA() > dta_max) - return false; - - std::string dirname = "addback"; - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - // Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += measuredE(cluster[i].GetCoreEnergy(), - cluster[i].GetCrystalId()); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - // firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = measuredE(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()), - cluster[i].GetCrystalId()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - Double_t gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/8, energyLlim, energyUlim/2, e1, - energyNChannels/8, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/8, energyLlim, energyUlim/2, e2, - energyNChannels/8, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/8, energyLlim, energyUlim/2, e1, - energyNChannels/8, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/8, energyLlim, energyUlim/2, e2, - energyNChannels/8, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/8, energyLlim, energyUlim/2, e1, - energyNChannels/8, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/8, energyLlim, energyUlim/2, e2, - energyNChannels/8, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj) { - - TGretina *gretina = obj.GetDetector(); - TS800Sim *s800Sim = obj.GetDetector(); - - if(!gretina || !s800Sim || s800Sim->Size() < 1) - return false; - - //Rough dta acceptance cut - Double_t dta_min = GValue::Value("DTA_MIN"); - if(std::isnan(dta_min)) - dta_min = -0.06; - Double_t dta_max = GValue::Value("DTA_MAX"); - if(std::isnan(dta_max)) - dta_max = 0.06; - if(s800Sim->GetS800SimHit(0).GetDTA() < dta_min || - s800Sim->GetS800SimHit(0).GetDTA() > dta_max) - return false; - - std::string dirname = "segAddback"; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim ) - hits.push_back(hit); - } - - // Addback - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of hits including the current - // hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - // Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += measuredE(cluster[i].GetCoreEnergy(), - cluster[i].GetCrystalId()); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - // firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = measuredE(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()), - cluster[i].GetCrystalId()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1) - addbackType = "n0"; - else if(neighbors == 1 && cluster.size() == 2) - addbackType = "n1"; - else if(neighbors == 3 && cluster.size() == 3) - addbackType = "n2"; - else - addbackType = "ng"; - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj) { - - TGretina *gretina = obj.GetDetector(); - TS800Sim *s800Sim = obj.GetDetector(); - - if(!gretina || !s800Sim) - return false; - - //Rough dta acceptance cut - Double_t dta_min = GValue::Value("DTA_MIN"); - if(std::isnan(dta_min)) - dta_min = -0.06; - Double_t dta_max = GValue::Value("DTA_MAX"); - if(std::isnan(dta_max)) - dta_max = 0.06; - if(s800Sim->GetS800SimHit(0).GetDTA() < dta_min || - s800Sim->GetS800SimHit(0).GetDTA() > dta_max) - return false; - - std::string dirname = "gretina"; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( !hit.HasInteractions() || - hit.GetCoreEnergy() < energyLlim || - hit.GetCoreEnergy() > energyUlim ) - continue; - - std::string histname = "energy"; - Double_t e = measuredE(hit.GetCoreEnergy(), - hit.GetCrystalId()); - obj.FillHistogram(dirname, histname, - energyNChannels*4, energyLlim, energyUlim, - e); - histname = "overview"; - obj.FillHistogram(dirname, histname, - energyNChannels*4, energyLlim, energyUlim, - e, - 120, 0, 120, - hit.GetCrystalId()); - - histname = "doppler"; - // obj.FillHistogram(dirname, histname, - // energyNChannels, energyLlim, energyUlim, - // hit.GetDoppler_2(beta, 0)); - - // Do this "by hand" to use "measured" energy. - TVector3 firstHitPos = hit.GetInteractionPosition(hit.GetFirstIntPoint()) - - targetOffset; - Double_t gamma = 1/(sqrt(1-pow(beta,2))); - Double_t edop = e*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - obj.FillHistogram(dirname, histname, - energyNChannels, energyLlim, energyUlim, - edop); - - // histname = "doppler_s800"; - // TVector3 track = s800->Track(); - // obj.FillHistogram(dirname, histname, - // energyNChannels, energyLlim, energyUlim, - // hit.GetDoppler(beta, &track)); - - histname = "doppler_theta"; - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // energyNChannels, energyLlim, energyUlim, - // hit.GetDoppler_2(beta, 0)); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - energyNChannels, energyLlim, energyUlim, - edop); - - histname = "theta_phi"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - - histname = "theta"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - - histname = "phi"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = "theta_phi_fw"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = "theta_fw"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - - histname = "phi_fw"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = "theta_phi_bw"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = "theta_bw"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - - histname = "phi_bw"; - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - } - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TS800Sim *s800Sim = obj.GetDetector(); - TGretSim *gretSim = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - std::string histname = ""; - std::string dirname = ""; - - if(gretSim && gretSim->Size() > 0 && - s800Sim && s800Sim->Size() > 0){ - - dirname = "sim"; - - histname = "beta"; - obj.FillHistogram(dirname, histname, - 500, 0, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - histname = "z"; - obj.FillHistogram(dirname, histname, - 1000,-50,50., - gretSim->GetGretinaSimHit(0).GetZ()); - histname = "beta_z"; - obj.FillHistogram(dirname, histname, - 1000,-50,50., - gretSim->GetGretinaSimHit(0).GetZ(), - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - - //Rough dta acceptance cut - Double_t dta_min = GValue::Value("DTA_MIN"); - if(std::isnan(dta_min)) - dta_min = -0.06; - Double_t dta_max = GValue::Value("DTA_MAX"); - if(std::isnan(dta_max)) - dta_max = 0.06; - if(s800Sim->GetS800SimHit(0).GetDTA() > dta_min && - s800Sim->GetS800SimHit(0).GetDTA() < dta_max) { - histname = "beta_acc"; - obj.FillHistogram(dirname, histname, - 500, 0, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - histname = "z_acc"; - obj.FillHistogram(dirname, histname, - 1000,-50,50., - gretSim->GetGretinaSimHit(0).GetZ()); - histname = "beta_z_acc"; - obj.FillHistogram(dirname, histname, - 1000,-50,50., - gretSim->GetGretinaSimHit(0).GetZ(), - 300, 0.2, 0.5, - gretSim->GetGretinaSimHit(0).GetBeta()); - } - } - - if(s800Sim) { - dirname = "S800"; - - DTA(obj); - - if(gretina) { - - HandleGretina(obj); - - HandleAddback(obj); - - HandleSegmentAddback(obj); - - } - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Trigger.cxx b/histos/MakeHistos_e10010_Trigger.cxx deleted file mode 100644 index cfedde6b..00000000 --- a/histos/MakeHistos_e10010_Trigger.cxx +++ /dev/null @@ -1,303 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_s44=0; - -GCutG *outgoing_s44=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 2000, 3000, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -2500, -1500, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 30000, 70000, - s800->GetIonChamber().Charge()); - // s800->GetIonChamber().GetSum()); - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_s44) { - incoming_s44 = (GCutG*)gates->FindObject("in44S"); - } - - if(!outgoing_s44) { - outgoing_s44 = (GCutG*)gates->FindObject("out44S"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - - TriggerRegister(obj, incoming_s44, outgoing_s44); - - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s44); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s44); - - DTA(obj, incoming_s44, outgoing_s44); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Trigger_cl46.cxx b/histos/MakeHistos_e10010_Trigger_cl46.cxx deleted file mode 100644 index 65e43fbe..00000000 --- a/histos/MakeHistos_e10010_Trigger_cl46.cxx +++ /dev/null @@ -1,345 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p43=0; -GCutG *incoming_s44=0; -GCutG *incoming_cl46=0; - -GCutG *outgoing_p43=0; -GCutG *outgoing_s44=0; -GCutG *outgoing_cl46=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 2000, 3000, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -2500, -1500, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 30000, 70000, - s800->GetIonChamber().Charge()); - // s800->GetIonChamber().GetSum()); - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("trigger_bit_%s_%s", - incoming->GetName(), - outgoing->GetName()); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = Form("trigger_raw_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p43) { - incoming_p43 = (GCutG*)gates->FindObject("in43P"); - } - if(!incoming_s44) { - incoming_s44 = (GCutG*)gates->FindObject("in44S"); - } - if(!incoming_cl46) { - incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); - } - - if(!outgoing_p43) { - outgoing_p43 = (GCutG*)gates->FindObject("out43P"); - } - if(!outgoing_s44) { - outgoing_s44 = (GCutG*)gates->FindObject("out44S"); - } - if(!outgoing_cl46) { - outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - - TriggerRegister(obj, incoming_p43, outgoing_p43); - - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p43); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p43); - - DTA(obj, incoming_p43, outgoing_p43); - - - TriggerRegister(obj, incoming_s44, outgoing_s44); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s44); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s44); - - DTA(obj, incoming_s44, outgoing_s44); - - - TriggerRegister(obj, incoming_cl46, outgoing_cl46); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_cl46); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_cl46); - - DTA(obj, incoming_cl46, outgoing_cl46); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Trigger_p41.cxx b/histos/MakeHistos_e10010_Trigger_p41.cxx deleted file mode 100644 index 04f4e7f6..00000000 --- a/histos/MakeHistos_e10010_Trigger_p41.cxx +++ /dev/null @@ -1,352 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p41=0; -GCutG *incoming_s42=0; -GCutG *incoming_si39=0; - -GCutG *outgoing_p41=0; -GCutG *outgoing_s42=0; -GCutG *outgoing_si39=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 1500, 2700, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -2100, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 32000, 60000, - s800->GetIonChamber().Charge()); - // s800->GetIonChamber().GetSum()); - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname = "dta_ata"; - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta(), - 200, -0.1, 0.1, - s800->GetAta()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("trigger_bit_%s_%s", - incoming->GetName(), - outgoing->GetName()); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = Form("trigger_raw_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p41) { - incoming_p41 = (GCutG*)gates->FindObject("in41P"); - } - if(!incoming_s42) { - incoming_s42 = (GCutG*)gates->FindObject("in42S"); - } - if(!incoming_si39) { - incoming_si39 = (GCutG*)gates->FindObject("in39Si"); - } - - if(!outgoing_p41) { - outgoing_p41 = (GCutG*)gates->FindObject("out41P"); - } - if(!outgoing_s42) { - outgoing_s42 = (GCutG*)gates->FindObject("out42S"); - } - if(!outgoing_si39) { - outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - - TriggerRegister(obj, incoming_p41, outgoing_p41); - - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p41); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p41); - - DTA(obj, incoming_p41, outgoing_p41); - - - TriggerRegister(obj, incoming_s42, outgoing_s42); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s42); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s42); - - DTA(obj, incoming_s42, outgoing_s42); - - - TriggerRegister(obj, incoming_si39, outgoing_si39); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_si39); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_si39); - - DTA(obj, incoming_si39, outgoing_si39); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Trigger_p43.cxx b/histos/MakeHistos_e10010_Trigger_p43.cxx deleted file mode 100644 index 0bc3b9a0..00000000 --- a/histos/MakeHistos_e10010_Trigger_p43.cxx +++ /dev/null @@ -1,352 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p43=0; -GCutG *incoming_s44=0; -GCutG *incoming_cl46=0; - -GCutG *outgoing_p43=0; -GCutG *outgoing_s44=0; -GCutG *outgoing_cl46=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 2000, 3000, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -2500, -1500, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 30000, 70000, - s800->GetIonChamber().Charge()); - // s800->GetIonChamber().GetSum()); - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname = "dta_ata"; - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta(), - 200, -0.1, 0.1, - s800->GetAta()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("trigger_bit_%s_%s", - incoming->GetName(), - outgoing->GetName()); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = Form("trigger_raw_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p43) { - incoming_p43 = (GCutG*)gates->FindObject("in43P"); - } - if(!incoming_s44) { - incoming_s44 = (GCutG*)gates->FindObject("in44S"); - } - if(!incoming_cl46) { - incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); - } - - if(!outgoing_p43) { - outgoing_p43 = (GCutG*)gates->FindObject("out43P"); - } - if(!outgoing_s44) { - outgoing_s44 = (GCutG*)gates->FindObject("out44S"); - } - if(!outgoing_cl46) { - outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - - TriggerRegister(obj, incoming_p43, outgoing_p43); - - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p43); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p43); - - DTA(obj, incoming_p43, outgoing_p43); - - - TriggerRegister(obj, incoming_s44, outgoing_s44); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s44); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s44); - - DTA(obj, incoming_s44, outgoing_s44); - - - TriggerRegister(obj, incoming_cl46, outgoing_cl46); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_cl46); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_cl46); - - DTA(obj, incoming_cl46, outgoing_cl46); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Trigger_s42.cxx b/histos/MakeHistos_e10010_Trigger_s42.cxx deleted file mode 100644 index 0bf1c1c6..00000000 --- a/histos/MakeHistos_e10010_Trigger_s42.cxx +++ /dev/null @@ -1,345 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p41=0; -GCutG *incoming_s42=0; -GCutG *incoming_si39=0; - -GCutG *outgoing_p41=0; -GCutG *outgoing_s42=0; -GCutG *outgoing_si39=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 1500, 2700, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -2100, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 32000, 60000, - s800->GetIonChamber().Charge()); - // s800->GetIonChamber().GetSum()); - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("trigger_bit_%s_%s", - incoming->GetName(), - outgoing->GetName()); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = Form("trigger_raw_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p41) { - incoming_p41 = (GCutG*)gates->FindObject("in41P"); - } - if(!incoming_s42) { - incoming_s42 = (GCutG*)gates->FindObject("in42S"); - } - if(!incoming_si39) { - incoming_si39 = (GCutG*)gates->FindObject("in39Si"); - } - - if(!outgoing_p41) { - outgoing_p41 = (GCutG*)gates->FindObject("out41P"); - } - if(!outgoing_s42) { - outgoing_s42 = (GCutG*)gates->FindObject("out42S"); - } - if(!outgoing_si39) { - outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - - TriggerRegister(obj, incoming_p41, outgoing_p41); - - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p41); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p41); - - DTA(obj, incoming_p41, outgoing_p41); - - - TriggerRegister(obj, incoming_s42, outgoing_s42); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s42); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s42); - - DTA(obj, incoming_s42, outgoing_s42); - - - TriggerRegister(obj, incoming_si39, outgoing_si39); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_si39); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_si39); - - DTA(obj, incoming_si39, outgoing_si39); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Trigger_s44.cxx b/histos/MakeHistos_e10010_Trigger_s44.cxx deleted file mode 100644 index 6aafa734..00000000 --- a/histos/MakeHistos_e10010_Trigger_s44.cxx +++ /dev/null @@ -1,307 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_s44=0; - -GCutG *outgoing_s44=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 1500, 2700, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -2100, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 32000, 60000, - s800->GetIonChamber().Charge()); - // s800->GetIonChamber().GetSum()); - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("trigger_bit_%s_%s", - incoming->GetName(), - outgoing->GetName()); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = Form("trigger_raw_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_s44) { - incoming_s44 = (GCutG*)gates->FindObject("in44S"); - } - - if(!outgoing_s44) { - outgoing_s44 = (GCutG*)gates->FindObject("out44S"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - - dirname = "S800"; - - TriggerRegister(obj, incoming_s44, outgoing_s44); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s44); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s44); - - DTA(obj, incoming_s44, outgoing_s44); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_Trigger_si39.cxx b/histos/MakeHistos_e10010_Trigger_si39.cxx deleted file mode 100644 index 0bf1c1c6..00000000 --- a/histos/MakeHistos_e10010_Trigger_si39.cxx +++ /dev/null @@ -1,345 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p41=0; -GCutG *incoming_s42=0; -GCutG *incoming_si39=0; - -GCutG *outgoing_p41=0; -GCutG *outgoing_s42=0; -GCutG *outgoing_si39=0; - -GCutG *gt_time=0; - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -1600, - s800->GetOBJ_E1Raw_MESY(), - 1000, 1500, 2700, - s800->GetXF_E1Raw_MESY()); - - return true; -} - - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - } else { - histname = "outgoing"; - } - obj.FillHistogram(dirname, histname, - 1000, -3000, -2100, - s800->GetCorrTOF_OBJ_MESY(), - 1000, 32000, 60000, - s800->GetIonChamber().Charge()); - // s800->GetIonChamber().GetSum()); - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - // s800->GetIonChamber().GetSum()) ) - if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().Charge()) ) - return false; - - histname = Form("trigger_bit_%s_%s", - incoming->GetName(), - outgoing->GetName()); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = Form("trigger_raw_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p41) { - incoming_p41 = (GCutG*)gates->FindObject("in41P"); - } - if(!incoming_s42) { - incoming_s42 = (GCutG*)gates->FindObject("in42S"); - } - if(!incoming_si39) { - incoming_si39 = (GCutG*)gates->FindObject("in39Si"); - } - - if(!outgoing_p41) { - outgoing_p41 = (GCutG*)gates->FindObject("out41P"); - } - if(!outgoing_s42) { - outgoing_s42 = (GCutG*)gates->FindObject("out42S"); - } - if(!outgoing_si39) { - outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - - TriggerRegister(obj, incoming_p41, outgoing_p41); - - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p41); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p41); - - DTA(obj, incoming_p41, outgoing_p41); - - - TriggerRegister(obj, incoming_s42, outgoing_s42); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s42); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s42); - - DTA(obj, incoming_s42, outgoing_s42); - - - TriggerRegister(obj, incoming_si39, outgoing_si39); - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_si39); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_si39); - - DTA(obj, incoming_si39, outgoing_si39); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_cl46.cxx b/histos/MakeHistos_e10010_cl46.cxx deleted file mode 100644 index 51ca511d..00000000 --- a/histos/MakeHistos_e10010_cl46.cxx +++ /dev/null @@ -1,1182 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_cl46=0; - -GCutG *outgoing_cl46=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600., -1600., - s800->GetOBJ_E1Raw_MESY(), - 1000, 2000., 3000., - s800->GetXF_E1Raw_MESY()); - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600., -1600., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 20000., 60000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - obj.FillHistogram(dirname, ehistname, - 1000, 20000., 45000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_cl46) { - incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); - } - - if(!outgoing_cl46) { - outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_cl46); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_cl46); - - DTA(obj, incoming_cl46, outgoing_cl46); - - if(gretina) { - - HandleGretina(obj, incoming_cl46, outgoing_cl46, gt_time); - - HandleAddback(obj, incoming_cl46, outgoing_cl46, gt_time); - - HandleSegmentAddback(obj, incoming_cl46, outgoing_cl46, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_cl46 && !outgoing_cl46 && - incoming_cl46->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_cl46->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_cl46->GetName(), - outgoing_cl46->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_cl46->GetName(), - outgoing_cl46->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_cl46_empty.cxx b/histos/MakeHistos_e10010_cl46_empty.cxx deleted file mode 100644 index b5a3155b..00000000 --- a/histos/MakeHistos_e10010_cl46_empty.cxx +++ /dev/null @@ -1,1182 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_cl46=0; - -GCutG *outgoing_cl46=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -4000., 0., - s800->GetOBJ_E1Raw_MESY(), - 1000, 0., 4000., - s800->GetXF_E1Raw_MESY()); - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - obj.FillHistogram(dirname, histname, - 1000, -4000., 0., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 0., 100000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - obj.FillHistogram(dirname, ehistname, - 1000, 20000., 45000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_cl46) { - incoming_cl46 = (GCutG*)gates->FindObject("in46Cl"); - } - - if(!outgoing_cl46) { - outgoing_cl46 = (GCutG*)gates->FindObject("out46Cl"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_cl46); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_cl46); - - DTA(obj, incoming_cl46, outgoing_cl46); - - if(gretina) { - - HandleGretina(obj, incoming_cl46, outgoing_cl46, gt_time); - - HandleAddback(obj, incoming_cl46, outgoing_cl46, gt_time); - - HandleSegmentAddback(obj, incoming_cl46, outgoing_cl46, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_cl46 && !outgoing_cl46 && - incoming_cl46->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_cl46->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_cl46->GetName(), - outgoing_cl46->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_cl46->GetName(), - outgoing_cl46->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_p41.cxx b/histos/MakeHistos_e10010_p41.cxx deleted file mode 100644 index 20f9faff..00000000 --- a/histos/MakeHistos_e10010_p41.cxx +++ /dev/null @@ -1,1197 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p41=0; - -GCutG *outgoing_p41=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - // LH runs - obj.FillHistogram(dirname, histname, - 1000, -3000., -1600., - s800->GetOBJ_E1Raw_MESY(), - 1000, 1500., 2700., - s800->GetXF_E1Raw_MESY()); - - // Empty run - // obj.FillHistogram(dirname, histname, - // 1000, -2600., -1200., - // s800->GetOBJ_E1Raw_MESY(), - // 1000, 1600., 3600., - // s800->GetXF_E1Raw_MESY()); - - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - // LH runs - obj.FillHistogram(dirname, histname, - 1000, -3000., -2100., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 32000., 60000., - s800->GetIonChamber().GetSum()); - - // Empty run - // obj.FillHistogram(dirname, histname, - // 1000, -2200., -1500., - // s800->GetCorrTOF_OBJ_MESY(), - // 1000, 10000., 50000., - // s800->GetIonChamber().GetSum()); - - obj.FillHistogram(dirname, ehistname, - 1000, 32000., 60000., - s800->GetIonChamber().GetSum()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p41) { - incoming_p41 = (GCutG*)gates->FindObject("in41P"); - } - - if(!outgoing_p41) { - outgoing_p41 = (GCutG*)gates->FindObject("out41P"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p41); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p41); - - DTA(obj, incoming_p41, outgoing_p41); - - if(gretina) { - - HandleGretina(obj, incoming_p41, outgoing_p41, gt_time); - - HandleAddback(obj, incoming_p41, outgoing_p41, gt_time); - - HandleSegmentAddback(obj, incoming_p41, outgoing_p41, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_p41 && !outgoing_p41 && - incoming_p41->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_p41->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_p41->GetName(), - outgoing_p41->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_p41->GetName(), - outgoing_p41->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_p43.cxx b/histos/MakeHistos_e10010_p43.cxx deleted file mode 100644 index 6d53b016..00000000 --- a/histos/MakeHistos_e10010_p43.cxx +++ /dev/null @@ -1,1182 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p43=0; - -GCutG *outgoing_p43=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600., -1600., - s800->GetOBJ_E1Raw_MESY(), - 1000, 2000., 3000., - s800->GetXF_E1Raw_MESY()); - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600., -1600., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 20000., 60000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - obj.FillHistogram(dirname, ehistname, - 1000, 20000., 45000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p43) { - incoming_p43 = (GCutG*)gates->FindObject("in43P"); - } - - if(!outgoing_p43) { - outgoing_p43 = (GCutG*)gates->FindObject("out43P"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p43); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p43); - - DTA(obj, incoming_p43, outgoing_p43); - - if(gretina) { - - HandleGretina(obj, incoming_p43, outgoing_p43, gt_time); - - HandleAddback(obj, incoming_p43, outgoing_p43, gt_time); - - HandleSegmentAddback(obj, incoming_p43, outgoing_p43, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_p43 && !outgoing_p43 && - incoming_p43->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_p43->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_p43->GetName(), - outgoing_p43->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_p43->GetName(), - outgoing_p43->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_p43_empty.cxx b/histos/MakeHistos_e10010_p43_empty.cxx deleted file mode 100644 index 2c270a7e..00000000 --- a/histos/MakeHistos_e10010_p43_empty.cxx +++ /dev/null @@ -1,1182 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_p43=0; - -GCutG *outgoing_p43=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -4000., 0., - s800->GetOBJ_E1Raw_MESY(), - 1000, 0., 4000., - s800->GetXF_E1Raw_MESY()); - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - obj.FillHistogram(dirname, histname, - 1000, -4000., 0., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 0., 100000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - obj.FillHistogram(dirname, ehistname, - 1000, 20000., 45000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_p43) { - incoming_p43 = (GCutG*)gates->FindObject("in43P"); - } - - if(!outgoing_p43) { - outgoing_p43 = (GCutG*)gates->FindObject("out43P"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_p43); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_p43); - - DTA(obj, incoming_p43, outgoing_p43); - - if(gretina) { - - HandleGretina(obj, incoming_p43, outgoing_p43, gt_time); - - HandleAddback(obj, incoming_p43, outgoing_p43, gt_time); - - HandleSegmentAddback(obj, incoming_p43, outgoing_p43, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_p43 && !outgoing_p43 && - incoming_p43->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_p43->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_p43->GetName(), - outgoing_p43->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_p43->GetName(), - outgoing_p43->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_s42.cxx b/histos/MakeHistos_e10010_s42.cxx deleted file mode 100644 index 129e32c0..00000000 --- a/histos/MakeHistos_e10010_s42.cxx +++ /dev/null @@ -1,1197 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_s42=0; - -GCutG *outgoing_s42=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - // LH runs - obj.FillHistogram(dirname, histname, - 1000, -3000., -1600., - s800->GetOBJ_E1Raw_MESY(), - 1000, 1500., 2700., - s800->GetXF_E1Raw_MESY()); - - // Empty run - // obj.FillHistogram(dirname, histname, - // 1000, -2600., -1200., - // s800->GetOBJ_E1Raw_MESY(), - // 1000, 1600., 3600., - // s800->GetXF_E1Raw_MESY()); - - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - // LH runs - obj.FillHistogram(dirname, histname, - 1000, -3000., -2100., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 32000., 60000., - s800->GetIonChamber().GetSum()); - - // Empty run - // obj.FillHistogram(dirname, histname, - // 1000, -2200., -1500., - // s800->GetCorrTOF_OBJ_MESY(), - // 1000, 10000., 50000., - // s800->GetIonChamber().GetSum()); - - obj.FillHistogram(dirname, ehistname, - 1000, 32000., 60000., - s800->GetIonChamber().GetSum()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_s42) { - incoming_s42 = (GCutG*)gates->FindObject("in42S"); - } - - if(!outgoing_s42) { - outgoing_s42 = (GCutG*)gates->FindObject("out42S"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s42); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s42); - - DTA(obj, incoming_s42, outgoing_s42); - - if(gretina) { - - HandleGretina(obj, incoming_s42, outgoing_s42, gt_time); - - HandleAddback(obj, incoming_s42, outgoing_s42, gt_time); - - HandleSegmentAddback(obj, incoming_s42, outgoing_s42, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_s42 && !outgoing_s42 && - incoming_s42->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_s42->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_s42->GetName(), - outgoing_s42->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_s42->GetName(), - outgoing_s42->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_s42_empty.cxx b/histos/MakeHistos_e10010_s42_empty.cxx deleted file mode 100644 index 1bbbc50d..00000000 --- a/histos/MakeHistos_e10010_s42_empty.cxx +++ /dev/null @@ -1,1197 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_s42=0; - -GCutG *outgoing_s42=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - // LH runs - // obj.FillHistogram(dirname, histname, - // 1000, -3000., -1600., - // s800->GetOBJ_E1Raw_MESY(), - // 1000, 1500., 2700., - // s800->GetXF_E1Raw_MESY()); - - // Empty run - obj.FillHistogram(dirname, histname, - 1000, -2600., -1200., - s800->GetOBJ_E1Raw_MESY(), - 1000, 1600., 3600., - s800->GetXF_E1Raw_MESY()); - - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - // LH runs - // obj.FillHistogram(dirname, histname, - // 1000, -3000., -2100., - // s800->GetCorrTOF_OBJ_MESY(), - // 1000, 32000., 60000., - // s800->GetIonChamber().GetSum()); - - // Empty run - obj.FillHistogram(dirname, histname, - 1000, -2200., -1500., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 10000., 50000., - s800->GetIonChamber().GetSum()); - - obj.FillHistogram(dirname, ehistname, - 1000, 10000., 50000., - s800->GetIonChamber().GetSum()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_s42) { - incoming_s42 = (GCutG*)gates->FindObject("in42S"); - } - - if(!outgoing_s42) { - outgoing_s42 = (GCutG*)gates->FindObject("out42S"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s42); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s42); - - DTA(obj, incoming_s42, outgoing_s42); - - if(gretina) { - - HandleGretina(obj, incoming_s42, outgoing_s42, gt_time); - - HandleAddback(obj, incoming_s42, outgoing_s42, gt_time); - - HandleSegmentAddback(obj, incoming_s42, outgoing_s42, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_s42 && !outgoing_s42 && - incoming_s42->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_s42->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_s42->GetName(), - outgoing_s42->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_s42->GetName(), - outgoing_s42->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_s44.cxx b/histos/MakeHistos_e10010_s44.cxx deleted file mode 100644 index ad6b901a..00000000 --- a/histos/MakeHistos_e10010_s44.cxx +++ /dev/null @@ -1,1206 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_s44=0; - -GCutG *outgoing_s44=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600., -1000., - s800->GetOBJ_E1Raw_MESY(), - 1000, 2000., 3600., - s800->GetXF_E1Raw_MESY()); - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - obj.FillHistogram(dirname, histname, - 1000, -2600., -1000., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 0., 55000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - obj.FillHistogram(dirname, ehistname, - 1000, 32000., 55000., - s800->GetIonChamber().GetSum()); - // s800->GetIonChamber().Charge()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - std::string histname = "energy"; - obj.FillHistogram(dirname, histname, - energyNChannels*4, energyLlim, energyUlim, - hit.GetCoreEnergy()); - - histname = "overview"; - obj.FillHistogram(dirname, histname, - energyNChannels*4, energyLlim, energyUlim, - hit.GetCoreEnergy(), - 120, 0, 120, - hit.GetCrystalId()); - - histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ){ - histname = Form("background_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - energyNChannels*4, energyLlim, energyUlim, - hit.GetCoreEnergy()); - histname = Form("background_dop_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - energyNChannels*4, energyLlim, energyUlim, - hit.GetDoppler_2(beta, 0)); - return false; - } - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - energyNChannels, energyLlim, energyUlim, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_s44) { - incoming_s44 = (GCutG*)gates->FindObject("in44S"); - } - - if(!outgoing_s44) { - outgoing_s44 = (GCutG*)gates->FindObject("out44S"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_s44); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_s44); - - DTA(obj, incoming_s44, outgoing_s44); - - if(gretina) { - - HandleGretina(obj, incoming_s44, outgoing_s44, gt_time); - - HandleAddback(obj, incoming_s44, outgoing_s44, gt_time); - - HandleSegmentAddback(obj, incoming_s44, outgoing_s44, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_s44 && !outgoing_s44 && - incoming_s44->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_s44->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_s44->GetName(), - outgoing_s44->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_s44->GetName(), - outgoing_s44->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_si39.cxx b/histos/MakeHistos_e10010_si39.cxx deleted file mode 100644 index b69a235b..00000000 --- a/histos/MakeHistos_e10010_si39.cxx +++ /dev/null @@ -1,1197 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_si39=0; - -GCutG *outgoing_si39=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - // LH runs - obj.FillHistogram(dirname, histname, - 1000, -3000., -1600., - s800->GetOBJ_E1Raw_MESY(), - 1000, 1500., 2700., - s800->GetXF_E1Raw_MESY()); - - // Empty run - // obj.FillHistogram(dirname, histname, - // 1000, -2600., -1200., - // s800->GetOBJ_E1Raw_MESY(), - // 1000, 1600., 3600., - // s800->GetXF_E1Raw_MESY()); - - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - // LH runs - obj.FillHistogram(dirname, histname, - 1000, -3000., -2100., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 32000., 60000., - s800->GetIonChamber().GetSum()); - - // Empty run - // obj.FillHistogram(dirname, histname, - // 1000, -2200., -1500., - // s800->GetCorrTOF_OBJ_MESY(), - // 1000, 10000., 50000., - // s800->GetIonChamber().GetSum()); - - obj.FillHistogram(dirname, ehistname, - 1000, 32000., 60000., - s800->GetIonChamber().GetSum()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_si39) { - incoming_si39 = (GCutG*)gates->FindObject("in39Si"); - } - - if(!outgoing_si39) { - outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_si39); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_si39); - - DTA(obj, incoming_si39, outgoing_si39); - - if(gretina) { - - HandleGretina(obj, incoming_si39, outgoing_si39, gt_time); - - HandleAddback(obj, incoming_si39, outgoing_si39, gt_time); - - HandleSegmentAddback(obj, incoming_si39, outgoing_si39, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_si39 && !outgoing_si39 && - incoming_si39->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_si39->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_si39->GetName(), - outgoing_si39->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_si39->GetName(), - outgoing_si39->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MakeHistos_e10010_si39_empty.cxx b/histos/MakeHistos_e10010_si39_empty.cxx deleted file mode 100644 index e5f2087d..00000000 --- a/histos/MakeHistos_e10010_si39_empty.cxx +++ /dev/null @@ -1,1197 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank29.h" -#include "TS800.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 1 -#define Q5 22 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 21 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -GCutG *incoming_si39=0; - -GCutG *outgoing_si39=0; - -GCutG *gt_time=0; - -//GCutG *strange=0; // high energy events (4-8 MeV), slightly early in time - -bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname; - if(outgoing) { - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - histname = Form("incoming_%s", outgoing->GetName()); - } else { - histname = "incoming"; - } - // LH runs - // obj.FillHistogram(dirname, histname, - // 1000, -3000., -1600., - // s800->GetOBJ_E1Raw_MESY(), - // 1000, 1500., 2700., - // s800->GetXF_E1Raw_MESY()); - - // Empty run - obj.FillHistogram(dirname, histname, - 1000, -2600., -1200., - s800->GetOBJ_E1Raw_MESY(), - 1000, 1600., 3600., - s800->GetXF_E1Raw_MESY()); - - - return true; - -} - -bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { - - if(!s800) - return false; - - std::string dirname = "S800"; - std::string histname, ehistname; - if(incoming) { - if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - histname = Form("outgoing_%s", incoming->GetName()); - ehistname = Form("ICcharge_%s", incoming->GetName()); - } else { - histname = "outgoing"; - ehistname = "ICcharge"; - } - // LH runs - // obj.FillHistogram(dirname, histname, - // 1000, -3000., -2100., - // s800->GetCorrTOF_OBJ_MESY(), - // 1000, 32000., 60000., - // s800->GetIonChamber().GetSum()); - - // Empty run - obj.FillHistogram(dirname, histname, - 1000, -2200., -1500., - s800->GetCorrTOF_OBJ_MESY(), - 1000, 10000., 50000., - s800->GetIonChamber().GetSum()); - - obj.FillHistogram(dirname, ehistname, - 1000, 10000., 50000., - s800->GetIonChamber().GetSum()); - - // std::cout << "s800->GetCorrTOF_OBJ_MESY() = " - // << s800->GetCorrTOF_OBJ_MESY() - // << "s800->GetIonChamber().Charge() = " - // << s800->GetIonChamber().Charge() - // << std::endl; - - // TMTof &mtof = s800->GetMTof(); - //histname = "RefSize"; - //obj.FillHistogram(dirname,histname,20,0,0,mtof.RefSize(), - // 20,0,0,mtof.E1UpSize()); - - //for(int i=0;iGetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetCrdc(0).GetDispersiveX()); -// -// histname = "time_afp"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetAFP()); -// -// histname = "time_charge"; -// obj.FillHistogram(dirname,histname,2000,0,0,s800->GetCorrTOF_OBJ_MESY(), -// 2000,0,0,s800->GetIonChamber().Charge()); - - return true; - -} - -bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - - std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetDta()); - - histname = Form("ata_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta()); - histname = Form("ata_bta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, - s800->GetBta(), - 200, -0.1, 0.1, - s800->GetAta()); - histname = Form("yta_%s_%s", - incoming->GetName(), - outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 200, -20, 20, - s800->GetYta()); - - return true; -} - -bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname = "S800"; - std::string histname; - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - - if(!incoming || !outgoing) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - - histname = "trigger_bit_PID"; - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname, histname, 20, 0, 20, j); - } - histname = "trigger_raw_PID"; - obj.FillHistogram(dirname, histname, - 20, 0, 20, - s800->GetTrigger().GetRegistr()); - return true; - -} - -bool HandleAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = 100.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("addback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - hits[j].GetCrystalPosition(); - - // std::cout << " * distance.Mag() = " << distance.Mag() - // << std::endl; - - obj.FillHistogram(dirname, - "crystal_separation", - 1000, 0., 1000., - distance.Mag()); - - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitCrystalPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - //if(cluster[i].GetCoreEnergy() > firstHitEnergy){ - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitCrystalPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - // firstHitEnergy = cluster[i].GetCoreEnergy(); - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetCrystalPosition() - - cluster[j].GetCrystalPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleSegmentAddback(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - Double_t neighborLimit = GValue::Value("SEGMENT_NEIGHBOR_LIMIT"); - if(std::isnan(neighborLimit)) - neighborLimit = 0.; - - Int_t energyNChannels = 2000; - Double_t energyLlim = 0.; - Double_t energyUlim = 8000.; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!incoming || !outgoing || !gt_time) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = Form("segAddback_%s_%s", - incoming->GetName(), - outgoing->GetName()); - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - std::vector hits; - - // Preprocessing - for(int x=0; xSize(); x++){ - - TGretinaHit hit = gretina->GetGretinaHit(x); - - if( hit.HasInteractions() && - hit.GetCoreEnergy() > energyLlim && - hit.GetCoreEnergy() < energyUlim && - gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - hits.push_back(hit); - } - - // Addback - std::vector dop_n0n1_energies; // for gamma-gamma - std::vector dop_n0n1n2_energies; // for gamma-gamma - std::vector dop_n0n1n2ng_energies; // for gamma-gamma - while(hits.size() > 0){ - TGretinaHit currentHit = hits.back(); - hits.pop_back(); - - - // Find and add all hits in a cluster of adjacent crystals including - // the current hit. - // - // CAUTION: This clustering includes neighbors of neighbors! - std::vector cluster; - cluster.push_back(currentHit); - int lastClusterSize = 0; - while(lastClusterSize < cluster.size()){ - for(int i = 0; i < cluster.size(); i++){ - for(int j = 0; j < hits.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - hits[j].GetSegmentPosition(); - - obj.FillHistogram(dirname, - "segment_separation", - 1000, 0., 1000., - distance.Mag()); - if(distance.Mag() < neighborLimit){ - cluster.push_back(hits.back()); - hits.pop_back(); - } - } - } - lastClusterSize = cluster.size(); - } - - // Calculate the total energy deposited in the cluster, - // and count the pairs of neighbors. - Int_t neighbors = 0; - Double_t addbackEnergy = 0.; - TVector3 firstHitPos; - TVector3 firstHitSegmentPos; - Int_t firstHitHoleNum; - Double_t firstHitEnergy = 0; - for(int i = 0; i < cluster.size(); i++){ - addbackEnergy += cluster[i].GetCoreEnergy(); - - // Find the hit with the largest energy deposit and save its position - // for Doppler correction. - - if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) > - firstHitEnergy){ - firstHitSegmentPos = cluster[i].GetCrystalPosition(); - firstHitHoleNum = cluster[i].GetHoleNumber(); - firstHitPos - = cluster[i].GetInteractionPosition(cluster[i].GetFirstIntPoint()) - - targetOffset; - firstHitEnergy - = cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()); - } - - for(int j = i+1; j < cluster.size(); j++){ - TVector3 distance = cluster[i].GetSegmentPosition() - - cluster[j].GetSegmentPosition(); - if(distance.Mag() < neighborLimit) neighbors++; - } - } - - // Doppler correct the addback energy. - // *** NEED TO ADD S800 TRAJECTORY *** - - Double_t dopplerABEnergy = 0.; - double gamma = 1/(sqrt(1-pow(beta,2))); - dopplerABEnergy = - addbackEnergy*gamma*(1-beta*TMath::Cos(firstHitPos.Theta())); - - TString addbackType; - if(neighbors == 0 && cluster.size() == 1){ - addbackType = "n0"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 1 && cluster.size() == 2){ - addbackType = "n1"; - dop_n0n1_energies.push_back(dopplerABEnergy); - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else if(neighbors == 3 && cluster.size() == 3){ - addbackType = "n2"; - dop_n0n1n2_energies.push_back(dopplerABEnergy); - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } else { - addbackType = "ng"; - dop_n0n1n2ng_energies.push_back(dopplerABEnergy); - } - - // Fill addback histograms. - obj.FillHistogram(dirname, addbackType.Data(), - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_%s_%.0f", - addbackType.Data(), - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - - if(addbackType == "n0" - || addbackType == "n1"){ - obj.FillHistogram(dirname, "n0n1", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - if(addbackType == "n0" - || addbackType == "n1" - || addbackType == "n2"){ - obj.FillHistogram(dirname, "n0n1n2", - energyNChannels, energyLlim, energyUlim, - addbackEnergy); - obj.FillHistogram(dirname, - Form("dop_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - // if(firstHitHoleNum < 10){ - // if( firstHitCrystalPos.Theta() < TMath::Pi()/2. ){ - if( firstHitSegmentPos.Theta() < TMath::Pi()/2. ){ - obj.FillHistogram(dirname, - Form("dop_fw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } else { - obj.FillHistogram(dirname, - Form("dop_bw_n0n1n2_%.0f", - beta*10000), - energyNChannels, energyLlim, energyUlim, - dopplerABEnergy); - } - } - - obj.FillHistogram(dirname, "clusterSize_vs_neighborPairs", - 20, 0, 20, neighbors, - 10, 0, 10, cluster.size()); - } - - // Symmetrized gamma-gamma - std::string histname = Form("gam_gam_dop_n0n1_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1_energies.size(); i++){ - Double_t e1 = dop_n0n1_energies[i]; - for(int j = i+1; j < dop_n0n1_energies.size(); j++){ - Double_t e2 = dop_n0n1_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2_energies.size(); i++){ - Double_t e1 = dop_n0n1n2_energies[i]; - for(int j = i+1; j < dop_n0n1n2_energies.size(); j++){ - Double_t e2 = dop_n0n1n2_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - histname = Form("gam_gam_dop_n0n1n2ng_%.0f", beta*10000); - for(int i = 0; i < dop_n0n1n2ng_energies.size(); i++){ - Double_t e1 = dop_n0n1n2ng_energies[i]; - for(int j = i+1; j < dop_n0n1n2ng_energies.size(); j++){ - Double_t e2 = dop_n0n1n2ng_energies[j]; - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e1, - energyNChannels/10, energyLlim, energyUlim/2, e2); - obj.FillHistogram(dirname, histname, - energyNChannels/10, energyLlim, energyUlim/2, e2, - energyNChannels/10, energyLlim, energyUlim/2, e1); - } - } - - return true; - -} - -bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, - GCutG *outgoing, GCutG *gt_time) { - - if(!incoming || !outgoing) - return false; - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) - return false; - - if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) ) - return false; - - if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) - return false; - // s800->GetIonChamber().Charge()) ) - - std::string dirname = "gretina"; - - double beta = GValue::Value("BETA"); - if(std::isnan(beta)) - beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); - - for(int x=0;xSize();x++) { - TGretinaHit hit = gretina->GetGretinaHit(x); - - std::string histname = Form("doppler_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s",outgoing->GetName()); - TVector3 track = s800->Track(); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - // if( strange->IsInside(s800->GetTimestamp()-hit.GetTimestamp(), - // hit.GetCoreEnergy()) ){ - // histname = Form("doppler_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 2000, 0, 8000, - // hit.GetDoppler_2(beta, 0)); - // histname = Form("doppler_theta_%s_strange",outgoing->GetName()); - // obj.FillHistogram(dirname, histname, - // 100, 0, TMath::Pi(), - // hit.GetTheta(), - // 2000, 0, 8000, - // hit.GetDoppler(beta, 0)); - // } - - histname = Form("theta_phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - - if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi(), - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), - hit.GetPhi()); - } - - // Time cut - if(!gt_time) - return false; - - if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), - hit.GetCoreEnergy()) ) - return false; - - histname = Form("doppler_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - histname = Form("doppler_s800_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 2000, 0, 8000, - hit.GetDoppler_2(beta, &track)); - - histname = Form("doppler_theta_%s_t",outgoing->GetName()); - obj.FillHistogram(dirname, histname, - 100, 0, TMath::Pi(), - hit.GetTheta(), - 2000, 0, 8000, - hit.GetDoppler_2(beta, 0)); - - } - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - //std::cout << "---------------------------------" <(); - TBank29 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - //std::cout << " Dets Gotten" << std::endl; - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - if(!incoming_si39) { - incoming_si39 = (GCutG*)gates->FindObject("in39Si"); - } - - if(!outgoing_si39) { - outgoing_si39 = (GCutG*)gates->FindObject("out39Si"); - } - - if(!gt_time) { - gt_time = (GCutG*)gates->FindObject("gt_time"); - } - - // if(!strange) { - // strange = (GCutG*)gates->FindObject("strange"); - // } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank29"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank29_time"; - dirname = "Bank29"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - } - } - - if(s800) { - dirname = "S800"; - - IncomingS800(obj, s800, 0); - IncomingS800(obj, s800, incoming_si39); - - OutgoingS800(obj, s800, 0); - OutgoingS800(obj, s800, outgoing_si39); - - DTA(obj, incoming_si39, outgoing_si39); - - if(gretina) { - - HandleGretina(obj, incoming_si39, outgoing_si39, gt_time); - - HandleAddback(obj, incoming_si39, outgoing_si39, gt_time); - - HandleSegmentAddback(obj, incoming_si39, outgoing_si39, gt_time); - - dirname = "gretina"; - for(unsigned int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "dtime_all"; - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - histname = "dtimet0_all"; - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 2000, 0, 8000, - hit.GetCoreEnergy()); - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<5;j++) { - if((bits>>j)&0x0001) { - histname = Form("dtime_all_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i",j); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - if(incoming_si39 && !outgoing_si39 && - incoming_si39->IsInside(s800->GetOBJ_E1Raw_MESY(), - s800->GetXF_E1Raw_MESY()) && - outgoing_si39->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - - histname = Form("dtime_all_reg%i_%s_%s",j, - incoming_si39->GetName(), - outgoing_si39->GetName()); - obj.FillHistogram(dirname,histname, - 500, -250, 250, - s800->GetTimestamp()-hit.GetTimestamp(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - histname = Form("dtimet0_reg%i_%s_%s",j, - incoming_si39->GetName(), - outgoing_si39->GetName()); - obj.FillHistogram(dirname,histname, - 500, 0, 500, - s800->GetTimestamp()-hit.GetTime(), - 1000, 0, 8000, - hit.GetCoreEnergy()); - } - } - } - } - } - - // histname = "TDC_vs_DispX"; - // obj.FillHistogram(dirname,histname, - // 4000,-4000,4000,s800->GetCorrTOF_OBJ(), - // 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - // histname ="PID_TDC"; - // obj.FillHistogram(dirname,histname, - // 2000,0,0,s800->GetCorrTOF_OBJ(), - // 2000,0,0,s800->GetIonChamber().Charge()); - - //double delta_t = s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ(); - //if(delta_t>E1_TDC_low && delta_tGetCorrTOF_OBJ(), - // 2000,10000,60000,s800->GetIonChamber().Charge()); - //} - - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //std::cout << " In gret loop + s800 before haspids" << std::endl; - //histname = "E1_m_TDC"; - //obj.FillHistogram(histname,8000,-8000,8000,s800->GetScint().GetTimeUp()-s800->GetTof().GetOBJ()); - - //histname = "E1Raw"; - //obj.FillHistogram(histname,2000,0,8000,s800->GetScint().GetTimeUp()); - - //histname = "M_E1Raw"; - //for(int z=0;zGetMTof().E1UpSize();z++) - // obj.FillHistogram(histname,2000,0,8000,s800->GetMTof().fE1Up[z]); - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - - } - - if(numobj!=list->GetSize()) - list->Sort(); - -} - diff --git a/histos/MyMakeHistos.cxx.bak b/histos/MyMakeHistos.cxx.bak deleted file mode 100644 index 84aaa4ce..00000000 --- a/histos/MyMakeHistos.cxx.bak +++ /dev/null @@ -1,761 +0,0 @@ - -#include "TRuntimeObjects.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "TGretina.h" -#include "TS800.h" -#include "TBank88.h" -#include "TS800.h" -#include "TFastScint.h" -#include "GCutG.h" - -#include "TChannel.h" -#include "GValue.h" - -//#define Q1 15 -//#define Q2 7 -//#define Q3 8 -//#define Q4 16 -//#define Q5 9 -//#define Q6 14 -//#define Q7 17 -//#define Q8 6 -//#define Q9 19 - -//#define Q1 15 -//#define Q2 7 -//#define Q3 11 -//#define Q4 1 -//#define Q5 22 -//#define Q6 14 -//#define Q7 12 -//#define Q8 6 -//#define Q9 21 - -#define Q1 15 -#define Q2 7 -#define Q3 11 -#define Q4 16 -#define Q5 8 -#define Q6 14 -#define Q7 12 -#define Q8 6 -#define Q9 17 -#define Q10 9 - -//#define BETA .37 - -std::map HoleQMap; -std::map LayerMap; - -//hole_list="15 7 11 16 8 14 12 6 17 9"; - -void InitMap() { - HoleQMap[Q1] = 1; - HoleQMap[Q2] = 2; - HoleQMap[Q3] = 3; - HoleQMap[Q4] = 4; - HoleQMap[Q5] = 5; - HoleQMap[Q6] = 6; - HoleQMap[Q7] = 7; - HoleQMap[Q8] = 8; - HoleQMap[Q9] = 9; - HoleQMap[Q10] = 10; - - LayerMap[0] = "alpha"; - LayerMap[1] = "beta"; - LayerMap[2] = "gamma"; - LayerMap[3] = "delta"; - LayerMap[4] = "epsilon"; - LayerMap[5] = "phi"; - -} - -#define INTEGRATION 128.0 - -// extern "C" is needed to prevent name mangling. -// The function signature must be exactly as shown here, -// or else bad things will happen. - -std::vector incoming_cuts = {0}; -std::vector outgoing_cuts = {0}; - -//std::vector gretina_cuts = {0}; -GCutG *gg_timing_gate=0; - -int gates_loaded=0; - -long first_time = -1; - -GCutG *test = 0; - -//for(unsigned int j=0;j(); - if(!s800) - return false; - - std::string dirname; - if(incoming) - dirname = Form("outgoing_%s",incoming->GetName()); - else - dirname = "outgoing"; - - - if(incoming) { - if(!s800->GetMTof().ObjSize() || !s800->GetMTof().XfpSize()) - return false; - bool found = false; - for(int x=0;xGetMTof().ObjSize();x++) { - for(int y=0;xGetMTof().XfpSize();x++) { - if(incoming->IsInside(s800->GetMTof().fObj[x],s800->GetMTof().fXfp[y])) { - found = true; - //std::cout << incoming->GetName() << "\tpassed." << std::endl; - } - } - } - //if(!incoming->IsInside(s800->GetMTof().fObj[0],s800->GetMTof().fXfp[0])) - if(!found) - return false; - } - - std::string histname; - - TIonChamber ion = s800->GetIonChamber(); - histname = "ion_summary"; - for(int i=0;iGetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - histname = "CRDC1_XY"; - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX(), - 800,-400,400,s800->GetCrdc(0).GetNonDispersiveY()); - - histname = "CRDC2_XY"; - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX(), - 800,-400,400,s800->GetCrdc(1).GetNonDispersiveY()); - - - for(int i=0;iGetMTof().fObj.size();i++) { - double value = s800->GetMTOF_ObjE1(i,0); - histname = Form("mesy_obj_e1_all_%i",s800->GetTrigger().GetRegistr());; - obj.FillHistogram(dirname,histname,8000,-16000,16000,value); - histname = Form("mesy_obj_e1_num_hit_%i",s800->GetTrigger().GetRegistr());; - obj.FillHistogram(dirname,histname,8000,-16000,16000,value, - 10,0,10,i); - } - - - - - TMTof &mtof = s800->GetMTof(); - - for(int i=0;iGetMTOF_RfE1(i))); //mtof.fE1Up.at(i)-mtof.fRf.at(i))); - } - if(iGetMTOF_ObjE1(i,false)));//mtof.fE1Up.at(i)-mtof.fObj.at(i)); - } - } - - histname = "time_x"; - obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), - 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - - - histname = "time_afp"; - obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), - 1000,-.1,.1,s800->GetAFP()); - - histname = "registr"; - obj.FillHistogram(dirname, histname, - 20, -5, 15, s800->GetTrigger().GetRegistr()); - - - - if(s800->GetTrigger().GetRegistr()&0x0002) { - histname = "time_charge_coinc"; - obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), - 5000,10000,40000,s800->GetIonChamber().Charge()); - } - histname = "time_charge"; - obj.FillHistogram(dirname,histname,2000,-4000,0,s800->GetMTOF_ObjE1(), - 10000,2000,42000,s800->GetIonChamber().Charge()); - - - - return true; -} - - -bool IncomingBeam(TRuntimeObjects& obj,GCutG *outgoing) { - TS800 *s800 = obj.GetDetector(); - - if(!s800) - return false; - if(outgoing) { - if(!outgoing->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge())) - return false; - } - - std::string dirname; - if(outgoing) - dirname = Form("incoming_%s",outgoing->GetName()); - else - dirname = "incoming"; - - std::string histname; - TMTof &mtof = s800->GetMTof(); - - - histname = "Obj"; - if(s800->GetMTof().ObjSize()) - obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTof().fObj[0]); //OF_ObjE1()); - histname = "Obj_Rf"; - obj.FillHistogram(dirname,histname,8000,-3200,32000,s800->GetMTOF_ObjRf()); - histname = "Xfp"; - if(s800->GetMTof().XfpSize()) { - obj.FillHistogram(dirname,histname,8000,-32000,32000,s800->GetMTof().fXfp[0]); //OF_XfpE1()); - histname = "Xfp_time"; - obj.FillHistogram(dirname,histname,360,0,3600,s800->Timestamp()/1e8, - 2000,-32000,32000,s800->GetMTof().fXfp[0]); //OF_XfpE1()); - } - histname = "Rf_E1"; - obj.FillHistogram(dirname,histname,8000,-32000,64000,s800->GetMTOF_RfE1()); - - histname = "obj_rf_2d"; - obj.FillHistogram(dirname,histname,1600,-8000,0,s800->GetMTOF_ObjE1(), - 1600,-24000,-16000,s800->GetMTOF_RfE1()); - - for(int x=0;xGetMTof().ObjSize();x++) { - for(int y=0;xGetMTof().XfpSize();x++) { - if(s800->GetMTof().ObjSize() && s800->GetMTof().XfpSize()) { - histname = "obj_xfp_2d"; - obj.FillHistogram(dirname,histname,6000,8000,14000,s800->GetMTof().fObj[x], - 8000,12000,20000,s800->GetMTof().fXfp[y]); - - if (s800->GetTrigger().GetRegistr()&0x0002) { - histname = "obj_xfp_2d_coinc"; - obj.FillHistogram(dirname,histname,6000,8000,14000,s800->GetMTof().fObj[x], - 8000,12000,20000,s800->GetMTof().fXfp[y]); - } - } - } - } - - - - //histname = "obj_xfp_2d"; - //obj.FillHistogram(dirname,histname,800,0,64000,s800->GetMTOF_ObjE1(), - // 800,0,64000,s800->GetMTOF_XfpE1()); - - histname = "trigger_bit"; - unsigned short bits = s800->GetTrigger().GetRegistr(); - for(int j=0;j<16;j++) { - if(((bits>>j)&0x0001)) - obj.FillHistogram(dirname,histname,20,0,20,j); - } - histname = "trigger_raw"; - obj.FillHistogram(dirname,histname,20,0,20,s800->GetTrigger().GetRegistr()); - - return true; -} - - - -bool HandleGretina(TRuntimeObjects &obj,GCutG *outgoing=0) { - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - if(!gretina) - return false; - - //gretina->CleanHits(); /// remove pad !=0 and duplicate segments. - - std::string dirname = "gretina"; - std::string histname; - - for(unsigned int x=0;xSize();x++) { - TGretinaHit hit1 = gretina->GetGretinaHit(x); - histname="summary"; - obj.FillHistogram(dirname,histname,4000,0,4000,hit1.GetCoreEnergy(), - 120,0,120,hit1.GetCrystalId()); - histname="error_code"; - obj.FillHistogram(dirname,histname,4000,0,4000,hit1.GetCoreEnergy(), - 10,0,10,hit1.GetPad()); - histname="singles"; - obj.FillHistogram(dirname,histname,12000,0,6000,hit1.GetCoreEnergy()); - - if(s800 && (s800->GetReg()&0x0002)) { - histname="singles_coin"; - obj.FillHistogram(dirname,histname,12000,0,6000,hit1.GetCoreEnergy()); - } - - histname="position"; - obj.FillHistogram(dirname,histname,180,0,180,hit1.GetThetaDeg(), - 360,0,360,hit1.GetPhiDeg()); - if(first_time<0 && hit1.GetTime()>0) { - first_time = hit1.GetTime(); - } - if(first_time>0) { - histname="counts_vs_time"; - obj.FillHistogram(dirname,histname,2000,0,20000,(hit1.GetTime()-first_time)*1e-8, - 200,0,200,hit1.GetCrystalId()); - } - for(unsigned int y=x+1;ySize();y++) { - TGretinaHit hit2 = gretina->GetGretinaHit(y); - double energy,time; - //bool prompt = false; - if(hit1.GetCoreEnergy()>hit2.GetCoreEnergy()) { - energy = hit2.GetCoreEnergy(); - time = hit1.GetTime()-hit2.GetTime(); - } else { - energy = hit1.GetCoreEnergy(); - time = hit2.GetTime()-hit1.GetTime(); - } - //if(gg_timing_gate && gg_timing_gate->IsInside(time,energy)) - // prompt=true; - histname="gg_time"; - obj.FillHistogram(dirname,histname,2000,-1000,1000,time, - 2000,0,10000,energy); - //histname="gg_matrix"; - //obj.FillHistogram(dirname,histname,4000,0,8000,hit1.GetCoreEnergy(), - // 4000,0,8000,hit2.GetCoreEnergy()); - //histname="gg_matrix"; - //obj.FillHistogram(dirname,histname,4000,0,8000,hit2.GetCoreEnergy(), - // 4000,0,8000,hit1.GetCoreEnergy()); - //if(prompt) { - // histname="gg_matrix_clean"; - // obj.FillHistogram(dirname,histname,4000,0,8000,hit1.GetCoreEnergy(), - // 4000,0,8000,hit2.GetCoreEnergy()); - // histname="gg_matrix_clean"; - // obj.FillHistogram(dirname,histname,4000,0,8000,hit2.GetCoreEnergy(), - // 4000,0,8000,hit1.GetCoreEnergy()); - //} - } - - //for(int y=0;y36) - // continue; - // histname = Form("GretinaSummaryX%02i",hit.GetCrystalId()); - // obj.FillHistogram(dirname,histname,40,0,40,hit.GetSegmentId(y), - // 1000,0,4000,hit.GetSegmentEng(y)); - - // int layer = hit.GetSegmentId(y)/6; - // histname = Form("position_%s",LayerMap[layer].c_str()); - // double phi = hit.GetIntPosition(y).Phi(); - // if(phi<0) phi +=TMath::Pi()*2; - // if(hit.GetPad()==0) { - // obj.FillHistogram(dirname,histname, - // 628,0.0,6.28,phi, - // 314,0,3.14,hit.GetIntPosition(y).Theta()); - // } - //} - } - return true; -} - - -bool HandleLaBr(TRuntimeObjects &obj,GCutG *outgoing=0) { - - TFastScint *labr = obj.GetDetector(); - if(!labr) - return false; - - std::string dirname = "labr"; - std::string histname; - - for(unsigned int x=0;xSize();x++) { - if(labr->GetLaBrHit(x).GetChannel()==15) { - histname="chan_15"; - obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge()); - - histname="chan_15_time"; - obj.FillHistogram(dirname,histname,130,0,3600,labr->Timestamp()/(double)1e8, - 4000,0,4000,labr->GetLaBrHit(x).Charge()); - - histname="chan_15_time_energy"; - obj.FillHistogram(dirname,histname,16000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), - 4000,0,4000,labr->GetLaBrHit(x).Charge()); - } - TGretina *gretina = obj.GetDetector(); - if(gretina) { - std::string gdirname = "gretina"; - histname = "labr_gretina"; - for(int y=0;ySize();y++) { - obj.FillHistogram(gdirname,histname,4000,0,8000,gretina->GetGretinaHit(y).GetCoreEnergy(), - 4000,0,4000,labr->GetLaBrHit(x).GetEnergy()); - - - } - } - if(labr->GetLaBrHit(x).GetChannel()==0) { - histname="chan_0"; - obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge()); - - histname="chan_0_time"; - obj.FillHistogram(dirname,histname,130,0,3600,labr->Timestamp()/(double)1e8, - 4000,0,4000,labr->GetLaBrHit(x).Charge()); - - - } - - - histname="summary"; - obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - histname="summary_cal"; - obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).GetEnergy(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - - histname="summary_time"; - obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetLaBrHit(x).GetTime(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - - - //if(labr->GetRefTime() >100 && labr->GetLaBrHit(x).GetTime() >100 ) { - if(labr->GetRefTime() >100 && labr->GetLaBrHit(x).GetTime() >100 && labr->GetLaBrHit(x).Charge() >100 ) { - //if(labr->GetLaBrHit(x).Charge() >100 ) { - histname="summary_time_ref"; - obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - histname="energy_time_ref"; - obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), - 4000,0,4000,labr->GetLaBrHit(x).GetEnergy()); - - - } - } - - - return true; -} - - -bool HandleS800(TRuntimeObjects &obj,GCutG *outgoing=0) { - - TS800 *s800 = obj.GetDetector(); - if(!s800) - return false; - - std::string dirname = "s800"; - std::string histname; - - histname="e1_charge"; - obj.FillHistogram(dirname,histname,2000,0,2000,s800->GetScint().GetEUp()); - - histname="reg"; - obj.FillHistogram(dirname,histname,300,0,300,s800->GetTrigger().GetRegistr()); - - - TGretina *gretina = obj.GetDetector(); - if(gretina) { - std::string gdirname = "gretina"; - histname = "e1_gretina"; - for(int y=0;ySize();y++) { - obj.FillHistogram(gdirname,histname,4000,0,8000,gretina->GetGretinaHit(y).GetCoreEnergy(), - 2000,0,2000,s800->GetScint().GetEUp()); - - - } - } - - - return true; -} - - -bool HandleS800Gated(TRuntimeObjects &obj,GCutG *incoming=0, GCutG *outgoing=0) { - TS800 *s800 = obj.GetDetector(); - - if( !s800) - return false; - - std::string dirname = "s800_gated"; - std::string histname; - - histname = Form("CRDC1_X_%s_%s",incoming->GetName(),outgoing->GetName()); - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(0).GetDispersiveX()); - - histname = Form("CRDC2_X_%s_%s",incoming->GetName(),outgoing->GetName()); - obj.FillHistogram(dirname,histname,800,-400,400,s800->GetCrdc(1).GetDispersiveX()); - - histname = Form("time_x_%s_%s",incoming->GetName(),outgoing->GetName()); - obj.FillHistogram(dirname,histname,2000,-6000,-3000,s800->GetMTOF_ObjE1(), - 600,-300,300,s800->GetCrdc(0).GetDispersiveX()); - - - if(test && test->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge()) ) { - - } - return true; -} - -bool HandleGretinaGated(TRuntimeObjects &obj,GCutG *incoming=0, GCutG *outgoing=0) { - - TGretina *gretina = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - - if(!gretina || !s800) - return false; - - std::string dirname; //= "gretina"; - if(incoming) - dirname = Form("gretina_%s",incoming->GetName()); - else - dirname = "gretina"; - std::string histname; - - - //if(!outgoing || !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge())) - if(!outgoing || !outgoing->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge())) { - if(!outgoing) - std::cout << "no gate!" << std::endl; - return false; - } - //if(!incoming || !incoming->IsInside(s800->GetMTOF_ObjE1(),s800->GetMTOF_XfpE1())) - // return false; - - //histname = Form("gretina_%s_%s",incoming->GetName(),outgoing->GetName()); - histname = Form("gretina_%s_%s",incoming->GetName(),outgoing->GetName()); - - for(unsigned int x=0;xSize();x++) { - obj.FillHistogram(dirname,histname,2500,0,10000, - gretina->GetGretinaHit(x).GetDoppler(GValue::Value("BETA"))); - //for(unsigned int y=x+1;ySize();y++) { - //histname = Form("matrix_%s_%s",incoming->GetName(),outgoing->GetName()); - // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetGretinaHit(x).GetDoppler(GValue::Value("BETA")), - // 625,0,10000,gretina->GetGretinaHit(y).GetDoppler(GValue::Value("BETA"))); - // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetGretinaHit(y).GetDoppler(GValue::Value("BETA")), - // 625,0,10000,gretina->GetGretinaHit(x).GetDoppler(GValue::Value("BETA"))); - //} - } - - histname = Form("addback_%s_%s",incoming->GetName(),outgoing->GetName()); - for(unsigned int x=0;xAddbackSize();x++) { - obj.FillHistogram(dirname,histname,2500,0,10000, - gretina->GetAddbackHit(x).GetDoppler(GValue::Value("BETA"))); - //for(unsigned int y=x+1;yAddbackSize();y++) { - // histname = Form("addback_matrix_%s_%s",incoming->GetName(),outgoing->GetName()); - // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetAddbackHit(x).GetDoppler(GValue::Value("BETA")), - // 625,0,10000,gretina->GetAddbackHit(y).GetDoppler(GValue::Value("BETA"))); - // obj.FillHistogram(dirname,histname,625,0,10000,gretina->GetAddbackHit(y).GetDoppler(GValue::Value("BETA")), - // 625,0,10000,gretina->GetAddbackHit(x).GetDoppler(GValue::Value("BETA"))); - //} - } - - - double sum = 0; - for(unsigned int i=0; iSize(); i++) { - sum += gretina->GetGretinaHit(i).GetDoppler(GValue::Value("BETA")); - } - obj.FillHistogram(dirname, Form("calorimeter_%s_%s", incoming->GetName(), outgoing->GetName()), - 2500, 0, 10000, sum); - - double sum2 = 0; - for(unsigned int i=0; iAddbackSize(); i++) { - sum2 += gretina->GetAddbackHit(i).GetDoppler(GValue::Value("BETA")); - } - obj.FillHistogram(dirname, Form("abcalorimeter_%s_%s", incoming->GetName(), outgoing->GetName()), - 2500, 0, 10000, sum2); - - return true; -} - -bool HandleLaBrGated(TRuntimeObjects &obj,GCutG *incoming=0,GCutG *outgoing=0) { - - TFastScint *labr = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - if(!labr || !s800) - return false; - - std::string dirname = "labr"; - std::string histname; - - //if(!outgoing || !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(),s800->GetIonChamber().Charge())) - if(!outgoing || !outgoing->IsInside(s800->GetMTOF_ObjE1(),s800->GetIonChamber().Charge())) - return false; - //if(!incoming || !incoming->IsInside(s800->GetMTOF_ObjE1(),s800->GetMTOF_XfpE1())) - // return false; - - for(unsigned int x=0;xSize();x++) { - histname = Form("summary_%s_%s",incoming->GetName(),outgoing->GetName()); - obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).Charge(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - histname = Form("summary_cal_%s_%s",incoming->GetName(),outgoing->GetName()); - obj.FillHistogram(dirname,histname,4000,0,4000,labr->GetLaBrHit(x).GetEnergy(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - - histname = Form("summary_time_%s_%s",incoming->GetName(),outgoing->GetName()); - obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetLaBrHit(x).GetTime(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - if(labr->GetRefTime() >100 && labr->GetLaBrHit(x).GetTime() >100 && labr->GetLaBrHit(x).Charge() >100 ) { - histname=Form("summary_time_ref_%s_%s",incoming->GetName(),outgoing->GetName()); - obj.FillHistogram(dirname,histname,8000,0,64000,labr->GetRefTime() - labr->GetLaBrHit(x).GetTime(), - 32,0,32,labr->GetLaBrHit(x).GetChannel()); - } - } - - - - return true; -} - - -extern "C" -void MakeHistograms(TRuntimeObjects& obj) { - InitMap(); - TGretina *gretina = obj.GetDetector(); - TBank88 *bank29 = obj.GetDetector(); - TS800 *s800 = obj.GetDetector(); - TFastScint *labr = obj.GetDetector(); - TList *list = &(obj.GetObjects()); - int numobj = list->GetSize(); - - TList *gates = &(obj.GetGates()); - - if(gates_loaded!=gates->GetSize()) { - TIter iter(gates); - while(TObject *obj = iter.Next()) { - GCutG *gate = (GCutG*)obj; - std::string tag = gate->GetTag(); - if(!tag.compare("incoming")) { - incoming_cuts.push_back(gate); - std::cout << "incoming: << " << gate->GetName() << std::endl; - } else if(!tag.compare("outgoing")) { - outgoing_cuts.push_back(gate); - std::cout << "outgoing: << " << gate->GetName() << std::endl; - } else if(!tag.compare("test")) { - //outgoing_cuts.push_back(gate); - test = gate; - std::cout << "outgoing: << " << gate->GetName() << std::endl; - } else if(!tag.compare("gretina")) { - std::string cutname = gate->GetName(); - if(!cutname.compare("timing")) { - gg_timing_gate=new GCutG(*gate); - //gg_timing_gate->Print(); - } - } else { - std::cout << "unknown: << " << gate->GetName() << std::endl; - } - gates_loaded++; - } - std::cout << "outgoing size: " << outgoing_cuts.size() << std::endl; - } - - std::string histname = ""; - std::string dirname = ""; - - if(bank29) { - dirname = "Bank88"; - for(unsigned int x=0;xSize();x++) { - TMode3Hit &hit = (TMode3Hit&)bank29->GetHit(x); - dirname = "Bank88"; - histname = Form("bank29_%i",hit.GetChannel()); - obj.FillHistogram(dirname,histname, - 16000,0,64000,hit.Charge()); - } - if(s800) { - histname = "S800_Bank88_time"; - obj.FillHistogram(dirname,histname, - 200,-200,200,bank29->Timestamp()-s800->Timestamp()); - - histname = "S800_Bank88_runtime"; - obj.FillHistogram(dirname,histname, - 3600,0,3600,bank29->Timestamp()*1e-8, - 1000,-1000,1000,bank29->Timestamp()-s800->Timestamp()); - histname = Form("S800_Bank88_runtime_Reg%i",s800->GetTrigger().GetRegistr()); - obj.FillHistogram(dirname,histname, - 3600,0,3600,bank29->Timestamp()*1e-8, - 1000,-1000,1000,bank29->Timestamp()-s800->Timestamp()); - } - if(gretina) { - for(int i=0;iSize();i++) { - TGretinaHit hit = gretina->GetGretinaHit(i); - histname = "Gretina_Bank88_time"; - obj.FillHistogram(dirname,histname, - 600,-600,600,bank29->Timestamp()-hit.Timestamp(), - 2000,0,4000,hit.GetCoreEnergy()); - histname = "Gretina_t0_Bank88_time"; - obj.FillHistogram(dirname,histname, - 600,-600,600,bank29->Timestamp()-hit.GetTime(), - 2000,0,4000,hit.GetCoreEnergy()); - } - } - if(labr) { - histname = "labr_Bank88_time"; - obj.FillHistogram(dirname,histname, - 600,-600,600,bank29->Timestamp()-labr->Timestamp()); - - } - } - - std::vector incoming_passed; - std::vector outgoing_passed; - - for(unsigned int x=0;x0)) { - passed = IncomingBeam(obj,outgoing_cuts.at(x)); - } - if(x!=0 && passed) { - outgoing_passed.push_back(x); - //break; - } - } - - - HandleGretina(obj); - HandleLaBr(obj); - HandleS800(obj); - - for(unsigned int i=0; iGetName() << std::endl; - //HandleGretinaGated(obj,0,outgoing_cuts.at(outgoing_passed.at(j))); - HandleLaBrGated(obj,incoming_cuts.at(incoming_passed.at(i)),outgoing_cuts.at(outgoing_passed.at(j))); - //HandleS800Gated(obj,0,outgoing_cuts.at(outgoing_passed.at(j))); - } - } - - if(numobj!=list->GetSize()) - list->Sort(); -} diff --git a/include/TCluster.h b/include/TCluster.h index dcc03dbd..6f060c96 100644 --- a/include/TCluster.h +++ b/include/TCluster.h @@ -1,6 +1,8 @@ #ifndef TCLUSTER_H #define TCLUSTER_H +#include + #include "TGretinaHit.h" #include "GRootFunctions.h" diff --git a/libraries/GROOT/GH2.cxx b/libraries/GROOT/GH2.cxx index e92c8103..8afbdb96 100644 --- a/libraries/GROOT/GH2.cxx +++ b/libraries/GROOT/GH2.cxx @@ -34,6 +34,8 @@ #include "TF2.h" #include "TProfile.h" +#include "TObjString.h" + #include "TRandom.h" #include "THLimitsFinder.h" #include "TMath.h" diff --git a/libraries/GROOT/GPeak.cxx b/libraries/GROOT/GPeak.cxx index 918d5d7d..49312479 100644 --- a/libraries/GROOT/GPeak.cxx +++ b/libraries/GROOT/GPeak.cxx @@ -279,7 +279,8 @@ Bool_t GPeak::Fit(TH1 *fithist,Option_t *opt) { TFitResultPtr fitres = fithist->Fit(this,Form("%sLRSME",options.Data())); //fitres.Get()->Print(); - // printf("chi^2/NDF = %.02f\n",this->GetChisquare()/(double)this->GetNDF()); + printf("chi^2/NDF = %.02f\n",this->GetChisquare()/(double)this->GetNDF()); + if(!fitres.Get()->IsValid()) { diff --git a/libraries/GROOT/GRootBrowser.cxx b/libraries/GROOT/GRootBrowser.cxx index aa73053b..1164373b 100644 --- a/libraries/GROOT/GRootBrowser.cxx +++ b/libraries/GROOT/GRootBrowser.cxx @@ -67,6 +67,7 @@ #include "TGFileDialog.h" #include "TObjString.h" #include "TVirtualPad.h" +#include "TVirtualX.h" #include "TEnv.h" #include diff --git a/libraries/TDetSystems/TGretina/TGretinaHit.cxx b/libraries/TDetSystems/TGretina/TGretinaHit.cxx index a34f47d0..2f6aeaf1 100644 --- a/libraries/TDetSystems/TGretina/TGretinaHit.cxx +++ b/libraries/TDetSystems/TGretina/TGretinaHit.cxx @@ -229,17 +229,17 @@ void TInteractionPoint::Add(TInteractionPoint &other) { TVector3 TGretinaHit::GetPosition() const { if(fNumberOfInteractions>0){ - //double xoffset = GValue::Value("GRETINA_X_OFFSET"); - //if(std::isnan(xoffset)) - // xoffset=0.00; - //double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - //if(std::isnan(yoffset)) - // yoffset=0.00; - //double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - //if(std::isnan(zoffset)) - // zoffset=0.00; - //TVector3 offset(xoffset,yoffset,zoffset); - return GetInteractionPoint(0).GetPosition(GetCrystalId());// + offset; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 offset(xoffset,yoffset,zoffset); + return GetInteractionPoint(0).GetPosition(GetCrystalId()) - offset; } else { return TDetectorHit::BeamUnitVec; } diff --git a/libraries/TDetSystems/TS800/TS800.cxx b/libraries/TDetSystems/TS800/TS800.cxx index a63157f4..429eb7e7 100644 --- a/libraries/TDetSystems/TS800/TS800.cxx +++ b/libraries/TDetSystems/TS800/TS800.cxx @@ -24,8 +24,8 @@ bool TS800::fGlobalReset =false; -//static double f_mafp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); -//static double f_mxfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); +static double f_mafp_cor = GValue::Value("OBJ_MTOF_CORR_AFP"); +static double f_mxfp_cor = GValue::Value("OBJ_MTOF_CORR_XFP"); diff --git a/makefile b/makefile index 52fe1fa7..3b7651c7 100644 --- a/makefile +++ b/makefile @@ -57,7 +57,7 @@ CFLAGS += $(shell root-config --cflags) CFLAGS += -MMD -MP $(INCLUDES) CFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 LINKFLAGS += -Llib $(addprefix -l,$(LIBRARY_NAMES)) -Wl,-rpath,\$$ORIGIN/../lib -LINKFLAGS += $(shell root-config --glibs) -lSpectrum -lPyROOT -lMinuit -lMathMore +LINKFLAGS += $(shell root-config --glibs) -lSpectrum -lROOTTPython -lMinuit -lMathMore LINKFLAGS := $(LINKFLAGS_PREFIX) $(LINKFLAGS) $(LINKFLAGS_SUFFIX) ROOT_LIBFLAGS := $(shell root-config --cflags) diff --git a/util/grutinizer-config b/util/grutinizer-config index 95eea142..5c077aa2 100755 --- a/util/grutinizer-config +++ b/util/grutinizer-config @@ -130,7 +130,7 @@ while test $# -gt 0; do continue fi rootout="yes" - out="$out `root-config --cflags --glibs` -lPhysics -lSpectrum -lPyROOT -lMinuit -lMathMore" + out="$out `root-config --cflags --glibs` -lPhysics -lSpectrum -lROOTTPython -lMinuit -lMathMore" ;; --libdir) if test "x$libdirout" = "xyes" ; then From 94c1d455c0114d28aa3a3486b40b9f5e7cbfb5eb Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Sat, 11 Jun 2022 23:15:54 -0400 Subject: [PATCH 10/29] Works with root 6.26. Changed make_unique provided by MakeUnique to std::make_uniqe in TFilterLoop.cxx. --- histos/MakeHistos60CoSim.cxx | 489 ++++++++++++++++++++++++++++ histos/MakeHistosInBeam.cxx | 527 +++++++++++++++++++++++++++++++ histos/MakeHistosSourcesSim.cxx | 361 +++++++++++++++++++++ libraries/TLoops/TFilterLoop.cxx | 4 +- 4 files changed, 1379 insertions(+), 2 deletions(-) create mode 100644 histos/MakeHistos60CoSim.cxx create mode 100644 histos/MakeHistosInBeam.cxx create mode 100644 histos/MakeHistosSourcesSim.cxx diff --git a/histos/MakeHistos60CoSim.cxx b/histos/MakeHistos60CoSim.cxx new file mode 100644 index 00000000..be315ac8 --- /dev/null +++ b/histos/MakeHistos60CoSim.cxx @@ -0,0 +1,489 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +Double_t measuredE(Double_t energy){ + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 1.2; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.0005; + + return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + // TS800 *s800 = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 4000; + Double_t energyLlim = 0.; + Double_t energyUlim = 4000.; + Double_t cosTheta = -1; + Double_t mCosTheta = -1; + Double_t x1 = -1; + Double_t y1 = -1; + Double_t z1 = -1; + Double_t x2 = -1; + Double_t y2 = -1; + Double_t z2 = -1; + + if(gretSim){ + for(unsigned int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + if(hit.GetEn() > 1331 && hit.GetEn() < 1334){ + x1 = sin(hit.GetTheta())*cos(hit.GetPhi()); + y1 = sin(hit.GetTheta())*sin(hit.GetPhi()); + z1 = cos(hit.GetTheta()); + } + if(hit.GetEn() > 1171 && hit.GetEn() < 1175){ + x2 = sin(hit.GetTheta())*cos(hit.GetPhi()); + y2 = sin(hit.GetTheta())*sin(hit.GetPhi()); + z2 = cos(hit.GetTheta()); + } + } + cosTheta + = (x1*x2+y1*y2+z1*z2)/(x1*x1+y1*y1+z1*z1)/(x2*x2+y2*y2+z2*z2); + obj.FillHistogram("sim","emitted_delta", + 100, -1, 1., + cosTheta); + } + + if(!gretina) + return; + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + // Gamma-gated crystal spectrum + Double_t eGateLlim = 1327.5; + Double_t eGateUlim = 1337.5; + int iGate = -1; + for(unsigned int i=0; iSize(); i++){ + TGretinaHit hit = gretina->GetGretinaHit(i); + if( hit.GetCoreEnergy() > eGateLlim && + hit.GetCoreEnergy() < eGateUlim ) + iGate = i; + } + if(iGate>=0){ + for(unsigned int i=0; iSize(); i++){ + TGretinaHit hit = gretina->GetGretinaHit(i); + if(i != iGate){ + Double_t mE = measuredE(hit.GetCoreEnergy()); + obj.FillHistogram("energy", + Form("energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", + Form("fold_vs_energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, hit.NumberOfInteractions()); + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + Form("segfold_vs_energy_%.0f", + (eGateLlim+eGateUlim)/2.0), + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, segment_fold); + + } + } + } + + // Addback preprocessing + for(unsigned int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += measuredE(hit.GetCoreEnergy()); + hits.push_back(hit); + + } + } + + int max_layer = -1; + + for(unsigned int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + Double_t mE = measuredE(hit.GetCoreEnergy()); + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); + + obj.FillHistogram("energy", "fold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, hit.NumberOfInteractions()); + + // Symmetrized gamma-gamma matrix and angular correlation + for(unsigned int y=x+1; ySize(); y++){ + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t mE2 = measuredE(hit2.GetCoreEnergy()); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE, + energyNChannels/4, energyLlim, energyUlim, mE2); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE2, + energyNChannels/4, energyLlim, energyUlim, mE); + + if( (mE > 1168. && mE < 1178. && mE2 > 1328. && mE2 < 1337.) + || (mE2 > 1168. && mE2 < 1178. && mE > 1328. && mE < 1337.) ){ + // TVector3 r1 = hit.GetFirstIntPosition_2(); + // TVector3 r2 = hit2.GetFirstIntPosition_2(); + TVector3 r1 = hit.GetPosition(); + TVector3 r2 = hit2.GetPosition(); + mCosTheta = r1.Dot(r2)/r1.Mag()/r2.Mag(); + obj.FillHistogram("position","delta", + 100, -1, 1., + mCosTheta); + obj.FillHistogram("position","cosTheta_mCosTheta", + 100, -1, 1., + cosTheta, + 100, -1, 1., + mCosTheta); + } + + } + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + "segfold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, segment_fold); + + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", "energy_A", + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", "energy_B", + energyNChannels, energyLlim, energyUlim, mE); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + // Position spectra in crystal coordinates + if(hit.NumberOfInteractions()){ + obj.FillHistogram("position", + Form("crys_%d_x", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).X()); + + obj.FillHistogram("position", + Form("crys_%d_y", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_z", hit.GetCrystalId()), + 1200, -10, 100, hit.GetLocalIntPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_xy", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).X(), + 1200, -60, 60, hit.GetLocalIntPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_xz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).X(), + 1200, -10, 100, hit.GetLocalIntPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_yz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).Y(), + 1200, -10, 100, hit.GetLocalIntPosition(0).Z()); + } + + for(int y=0; y < hit.NumberOfInteractions(); y++){ + + int layer = hit.GetSegmentId(y)/6; + + if(layer > max_layer) max_layer = layer; + + obj.FillHistogram("layers", + Form("theta_vs_phi_%s", LayerMap[layer].c_str()), + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + obj.FillHistogram("layers", "max_layer", 12, -2, 10, + max_layer); + + if(max_layer == 5){ + obj.FillHistogram("energy", "energy_involves_phi", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_involves_phi", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + } + + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("energy", + Form("energy_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", + Form("energy_A_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", + Form("energy_B_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + } + + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("addback", + Form("calorimeter_below_%s", + LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + } + } + + // For energy-gated addback spectra + std::vector ABenergy; + std::vector ABtype; + Int_t Naddback = 0; + iGate = -1; + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + unsigned int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(unsigned int i = 0; i < cluster.size(); i++){ + for(unsigned int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + for(unsigned int i = 0; i < cluster.size(); i++){ + addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); + for(unsigned int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1) + addbackType = "addback_n0"; + else if(neighbors == 1 && cluster.size() == 2) + addbackType = "addback_n1"; + else if(neighbors == 3 && cluster.size() == 3) + addbackType = "addback_n2"; + else + addbackType = "addback_ng"; + + // Fill addback histograms. + + obj.FillHistogram("addback", addbackType, + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + + if(addbackType == "addback_n0" + || addbackType == "addback_n1"){ + obj.FillHistogram("addback", "addback_n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + if(addbackType == "addback_n0" + || addbackType == "addback_n1" + || addbackType == "addback_n2"){ + obj.FillHistogram("addback", "addback_n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + + // For energy-gated addback spectra + if(addbackEnergy > eGateLlim && + addbackEnergy < eGateUlim) + iGate = Naddback; + + ABenergy.push_back(addbackEnergy); + ABtype.push_back(addbackType); + Naddback++; + + } + + // Fill energy-gated addback spectra + if(iGate >= 0){ + for(int i = 0; iGetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/histos/MakeHistosInBeam.cxx b/histos/MakeHistosInBeam.cxx new file mode 100644 index 00000000..c63e9484 --- /dev/null +++ b/histos/MakeHistosInBeam.cxx @@ -0,0 +1,527 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TS800Sim.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + // TS800 *s800 = obj.GetDetector(); + TS800Sim *s800Sim = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + Int_t energyNChannels = 8192; + Double_t energyLlim = 0.; + Double_t energyUlim = 8192.; + + if(gretSim){ + for(unsigned int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + obj.FillHistogram("sim","beta", + 500, 0, 0.5, + hit.GetBeta()); + obj.FillHistogram("sim","beta_z", + 1000,-5,5., + hit.GetZ(), + 300, 0.2, 0.5, + hit.GetBeta()); + } + } + + if(!s800Sim) + return; + + if(s800Sim->Size() > 0){ + // std::cout << "In MakeHistos:" << std::endl; + + // std::cout << " time stamp = " + // << s800Sim->Timestamp() << std::endl; + + // std::cout << " size = " + // << s800Sim->Size() + // << std::endl; + + // std::cout << std::flush; + + Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); + + // std::cout << " ATA = " + // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; + + // std::cout << " BTA = " + // << s800Sim->GetS800SimHit(0).GetBTA() << std::endl; + + // std::cout << " DTA = " + // << dta << std::endl; + + + obj.FillHistogram("s800","dta", + 200, -0.10, 0.10, + dta); + + // Rough dta acceptance cut + if(dta < -0.06 || dta > 0.06) + return; + + obj.FillHistogram("s800","dta_cut", + 200, -0.10, 0.10, + dta); + + obj.FillHistogram("s800","ata", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetATA()); + + obj.FillHistogram("s800","bta", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetBTA()); + + Double_t xsin, ysin, scatter; + + xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); + ysin = -sin(s800Sim->GetS800SimHit(0).GetBTA()/1000.); + scatter = asin(sqrt(xsin*xsin + ysin*ysin))*1000.; + + obj.FillHistogram("s800","scatter", + 4096, 0, 300, + scatter); + } + + if(!gretina) + return; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset,yoffset,zoffset); + + // (optionally define extra beta values in gvalues file) + const Int_t nBetas = 1; + Double_t betas[nBetas] = {beta}; + + Double_t calorimeterEnergy = 0.; + Double_t calorimeterEnergy_gaus = 0.; + std::vector hits; + + for(unsigned int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + // Addback preprocessing + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += hit.GetCoreEnergy(); + calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + hits.push_back(hit); + + } + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + obj.FillHistogram("energy", "overview_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + + for(int i=0; iGaus(1,1./1000.); + for(unsigned int y=x+1; ySize(); y++){ + + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t e2 = hit2.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.); + + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/16, energyLlim, energyUlim/2, e1, + energyNChannels/16, energyLlim, energyUlim/2, e2); + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/8, energyLlim, energyUlim, e2, + energyNChannels/8, energyLlim, energyUlim, e1); + } + + obj.FillHistogram("energy", + Form("dop_%.0f", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])); + + obj.FillHistogram("energy", + Form("dop_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.)); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("energy", + Form("dop_fw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.)); + } else { + obj.FillHistogram("energy", + Form("dop_bw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.)); + } + } + + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("position", "theta_vs_phi_fw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } else { + obj.FillHistogram("position", "theta_vs_phi_bw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + obj.FillHistogram("addback", "calorimeter_gaus", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy_gaus); + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + unsigned int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(unsigned int i = 0; i < cluster.size(); i++){ + for(unsigned int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + Double_t addbackEnergy_gaus = 0.; + TVector3 firstHitPos; + Int_t firstHitHoleNum = -1; + Double_t firstHitEnergy = 0; + for(unsigned int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + addbackEnergy_gaus += + cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + // Find the largest IP in the cluster and save its position + // for Doppler correction. + // if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) + // > firstHitEnergy){ + if(cluster[i].GetIntAssignEng(0) > firstHitEnergy){ + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos = cluster[i].GetIntPosition(0) - targetOffset; + firstHitEnergy = cluster[i].GetIntAssignEng(0); + } + + for(unsigned int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy[nBetas] = {0.}; + Double_t dopplerABEnergy_gaus[nBetas] = {0.}; + for(int b=0; bGetSize()) + list->Sort(); + +} diff --git a/histos/MakeHistosSourcesSim.cxx b/histos/MakeHistosSourcesSim.cxx new file mode 100644 index 00000000..606c91d1 --- /dev/null +++ b/histos/MakeHistosSourcesSim.cxx @@ -0,0 +1,361 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TS800.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +Double_t measuredE(Double_t energy){ + Double_t resPar1 = GValue::Value("RESOLUTION_PAR_1"); + if(std::isnan(resPar1)) + resPar1 = 1.2; + Double_t resPar2 = GValue::Value("RESOLUTION_PAR_2"); + if(std::isnan(resPar2)) + resPar2 = 0.0005; + + return energy + gRandom->Gaus(0.0, resPar1*sqrt(1 + resPar2*energy)); +} + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + // TS800 *s800 = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + Int_t energyNChannels = 4000; + Double_t energyLlim = 0.; + Double_t energyUlim = 4000.; + + if(gretSim){ + for(unsigned int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + } + } + + if(!gretina) + return; + + Double_t calorimeterEnergy = 0.; + std::vector hits; + + // Addback preprocessing + for(unsigned int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += measuredE(hit.GetCoreEnergy()); + hits.push_back(hit); + + } + } + + int max_layer = -1; + + for(unsigned int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + Double_t mE = measuredE(hit.GetCoreEnergy()); + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, mE); + + if(gretSim && gretSim->Size()>0) + if(gretSim->GetGretinaSimHit(0).IsFEP()) + obj.FillHistogram("energy", "photopeak", + energyNChannels, energyLlim, energyUlim, mE); + + obj.FillHistogram("energy", "fold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, hit.NumberOfInteractions()); + + // Symmetrized gamma-gamma matrix + for(unsigned int y=x+1; ySize(); y++){ + TGretinaHit hit2 = gretina->GetGretinaHit(y); + Double_t mE2 = measuredE(hit2.GetCoreEnergy()); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE, + energyNChannels/4, energyLlim, energyUlim, mE2); + obj.FillHistogram("energy", "gamma_gamma", + energyNChannels/4, energyLlim, energyUlim, mE2, + energyNChannels/4, energyLlim, energyUlim, mE); + } + + // Count segment fold + int segment_fold = hit.NumberOfInteractions(); + for(int y=0; y < hit.NumberOfInteractions(); y++) + for(int z = y+1; z < hit.NumberOfInteractions(); z++) + if(hit.GetSegmentId(y) == hit.GetSegmentId(z)){ + segment_fold--; + break; + } + + obj.FillHistogram("energy", + "segfold_vs_energy", + energyNChannels/8, energyLlim, energyUlim, mE, + 20, 0, 20, segment_fold); + + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", "energy_A", + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", "energy_B", + energyNChannels, energyLlim, energyUlim, mE); + + // Peter wrote these to give Dirk his Phi range (0-360). + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + // Position spectra in crystal coordinates + if(hit.NumberOfInteractions()){ + obj.FillHistogram("position", + Form("crys_%d_x", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).X()); + + obj.FillHistogram("position", + Form("crys_%d_y", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_z", hit.GetCrystalId()), + 1200, -10, 100, hit.GetLocalIntPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_xy", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).X(), + 1200, -60, 60, hit.GetLocalIntPosition(0).Y()); + + obj.FillHistogram("position", + Form("crys_%d_xz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).X(), + 1200, -10, 100, hit.GetLocalIntPosition(0).Z()); + + obj.FillHistogram("position", + Form("crys_%d_yz", hit.GetCrystalId()), + 1200, -60, 60, hit.GetLocalIntPosition(0).Y(), + 1200, -10, 100, hit.GetLocalIntPosition(0).Z()); + } + + for(int y=0; y < hit.NumberOfInteractions(); y++){ + + int layer = hit.GetSegmentId(y)/6; + + if(layer > max_layer) max_layer = layer; + + obj.FillHistogram("layers", + Form("theta_vs_phi_%s", LayerMap[layer].c_str()), + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + obj.FillHistogram("layers", "max_layer", 12, -2, 10, + max_layer); + + if(max_layer == 5){ + obj.FillHistogram("energy", "energy_involves_phi", + energyNChannels, energyLlim, energyUlim, mE); + obj.FillHistogram("energy", "overview_involves_phi", + energyNChannels, energyLlim, energyUlim, mE, + 100, 0, 100, hit.GetCrystalId()); + } + + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("energy", + Form("energy_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + if( hit.GetCrystalId()%2 ) + obj.FillHistogram("energy", + Form("energy_A_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + else + obj.FillHistogram("energy", + Form("energy_B_below_%s", LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, mE); + } + + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + for(int k = 5; k > 0; k--){ + if(max_layer < k){ + obj.FillHistogram("addback", + Form("calorimeter_below_%s", + LayerMap[k].c_str()), + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + } + } + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + unsigned int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(unsigned int i = 0; i < cluster.size(); i++){ + for(unsigned int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + for(unsigned int i = 0; i < cluster.size(); i++){ + addbackEnergy += measuredE(cluster[i].GetCoreEnergy()); + for(unsigned int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + TString addbackType; + if(neighbors == 0 && cluster.size() == 1) + addbackType = "addback_n0"; + else if(neighbors == 1 && cluster.size() == 2) + addbackType = "addback_n1"; + else if(neighbors == 3 && cluster.size() == 3) + addbackType = "addback_n2"; + else + addbackType = "addback_ng"; + + // Fill addback histograms. + + obj.FillHistogram("addback", addbackType, + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + + if(addbackType == "addback_n0" + || addbackType == "addback_n1"){ + obj.FillHistogram("addback", "addback_n0n1", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + if(addbackType == "addback_n0" + || addbackType == "addback_n1" + || addbackType == "addback_n2"){ + obj.FillHistogram("addback", "addback_n0n1n2", + energyNChannels, energyLlim, energyUlim, + addbackEnergy); + } + + obj.FillHistogram("addback", "clusterSize_vs_neighborPairs", + 20, 0, 20, neighbors, + 10, 0, 10, cluster.size()); + + } + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + if(numobj!=list->GetSize()) + list->Sort(); +} diff --git a/libraries/TLoops/TFilterLoop.cxx b/libraries/TLoops/TFilterLoop.cxx index 8b71d517..0a48fe8d 100644 --- a/libraries/TLoops/TFilterLoop.cxx +++ b/libraries/TLoops/TFilterLoop.cxx @@ -1,6 +1,6 @@ #include "TFilterLoop.h" -#include "MakeUnique.h" +// #include "MakeUnique.h" #include "TGRUTOptions.h" #include "TRawFileOut.h" @@ -73,7 +73,7 @@ void TFilterLoop::HandleEvent(TUnpackedEvent* event) { } void TFilterLoop::OpenRawOutputFile(const std::string& output_filename) { - filtered_output = make_unique(output_filename); + filtered_output = std::make_unique(output_filename); } void TFilterLoop::AddCutFile(TFile* cut_file) { From b4daec4376c06ffadde1ca5c7dd2a790b6a36667 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Sun, 12 Jun 2022 08:54:21 -0400 Subject: [PATCH 11/29] Colors are now specified %RRGGBB instead of #RRGGBB. --- .grutrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.grutrc b/.grutrc index 85c8fcae..1f84a4f4 100644 --- a/.grutrc +++ b/.grutrc @@ -21,7 +21,7 @@ Rint.Logon: $(GRUTSYS)/.grut_logon Rint.History $(GRUTSYS)/.grut_history Rint.HistSize: 1000000 -Rint.PromptColor: #CCCC00 +Rint.PromptColor: %CCCC00 Rint.BracketColor: bold green Rint.BadBracketColor: bold red underlined Rint.TabComColor: magenta From 75dca30dff0dd58550c5878698ad884eaf4e9d20 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 30 May 2023 20:06:39 -0400 Subject: [PATCH 12/29] MakeHistos for beam characterization for e19028 --- histos/MakeHistos_e19028_Trigger.cxx | 244 +++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 histos/MakeHistos_e19028_Trigger.cxx diff --git a/histos/MakeHistos_e19028_Trigger.cxx b/histos/MakeHistos_e19028_Trigger.cxx new file mode 100644 index 00000000..058b1ced --- /dev/null +++ b/histos/MakeHistos_e19028_Trigger.cxx @@ -0,0 +1,244 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank88.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + +//#define BETA .37 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_cut=0; + +GCutG *outgoing_cut=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + + //LR (e19028 Run0022, 74Kr setting, emtpy cell) + obj.FillHistogram(dirname, histname, + 600, -1800, -1200, + s800->GetOBJ_E1Raw_MESY(), + 800, 3000, 3800, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + + obj.FillHistogram(dirname, histname, + 1000, -2000, -1000, + s800->GetCorrTOF_OBJ_MESY(), + 2000, 30000, 50000, + s800->GetIonChamber().Charge()); + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + + InitMap(); + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + + TIter next(gates); + GCutG* gate = 0; + while ((gate = (GCutG*)next())) { + TString cutname = gate->GetName(); + if(cutname.Contains("in") && !incoming_cut) + incoming_cut = gate; + + if(cutname.Contains("out") && !outgoing_cut) + outgoing_cut = gate; + } + + std::string histname = ""; + std::string dirname = ""; + + if(s800) { + + TriggerRegister(obj, incoming_cut, outgoing_cut); + + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_cut); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_cut); + + DTA(obj, incoming_cut, outgoing_cut); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + From ba1c303d0a2d2059005b7435f9767d6f85ecfee2 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Wed, 31 May 2023 10:17:03 -0400 Subject: [PATCH 13/29] 19028 update --- histos/MakeHistos_e19028_Trigger.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/histos/MakeHistos_e19028_Trigger.cxx b/histos/MakeHistos_e19028_Trigger.cxx index 058b1ced..cfb113df 100644 --- a/histos/MakeHistos_e19028_Trigger.cxx +++ b/histos/MakeHistos_e19028_Trigger.cxx @@ -211,10 +211,10 @@ void MakeHistograms(TRuntimeObjects& obj) { GCutG* gate = 0; while ((gate = (GCutG*)next())) { TString cutname = gate->GetName(); - if(cutname.Contains("in") && !incoming_cut) + if(!incoming_cut && cutname.Contains("in")) incoming_cut = gate; - if(cutname.Contains("out") && !outgoing_cut) + if(!outgoing_cut && cutname.Contains("out")) outgoing_cut = gate; } From c3da8c4fe03fc073b08b09f80116f8341ffef9f3 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Mon, 5 Jun 2023 09:38:32 -0400 Subject: [PATCH 14/29] Filter file for e19028 --- filters/Filter_e19028.cxx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 filters/Filter_e19028.cxx diff --git a/filters/Filter_e19028.cxx b/filters/Filter_e19028.cxx new file mode 100644 index 00000000..d37f6cb2 --- /dev/null +++ b/filters/Filter_e19028.cxx @@ -0,0 +1,39 @@ +// To make a new filter, copy this file under a new name in the "filter" directory. +// The "FilterCondition" function should return a boolean value. +// The boolean indicates whether the event should be kept or not. + +#include "TRuntimeObjects.h" + +#include +#include + + +extern "C" +bool FilterCondition(TRuntimeObjects& obj) { + + + TGretina *gretina = obj.GetDetector(); + //TS800 *s800 = obj.GetDetector(); + + if(!gretina) + return false; + + //if((s800->GetTrigger().GetRegistr()&0x0002)>>1) + // return true; + //if(s800->GetTrigger().GetRegistr()==3) { + //printf("i am returning true\n"); fflush(stdout); + // return true; + //} + + //return false; + gretina->CleanHits(); + if(!gretina->Size()) + return false; + + return true; + + +} + + + From c128b58036e672ac2e54a3227c5852305d27c839 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 6 Jun 2023 09:21:02 -0400 Subject: [PATCH 15/29] Update for e19028 analysis, including restoring gadd.cxx (automated CMake doesn't generate the gaddCommandLineOptionsHelp.h header.) --- histos/MakeHistos_e19028.cxx | 520 +++++++++++++++++++++++++++ include/gaddCommandLineOptionsHelp.h | 33 ++ util/gadd.cxx | 250 +++++++++++++ util/gadd_fast.py | 3 +- 4 files changed, 805 insertions(+), 1 deletion(-) create mode 100644 histos/MakeHistos_e19028.cxx create mode 100644 include/gaddCommandLineOptionsHelp.h create mode 100644 util/gadd.cxx diff --git a/histos/MakeHistos_e19028.cxx b/histos/MakeHistos_e19028.cxx new file mode 100644 index 00000000..9c879ee4 --- /dev/null +++ b/histos/MakeHistos_e19028.cxx @@ -0,0 +1,520 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank88.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_cut=0; + +GCutG *outgoing_cut=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + + //LR (e19028 Run0022, 74Kr setting, emtpy cell) + obj.FillHistogram(dirname, histname, + 600, -1800, -1200, + s800->GetOBJ_E1Raw_MESY(), + 800, 3000, 3800, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + + obj.FillHistogram(dirname, histname, + 1000, -2000, -1000, + s800->GetCorrTOF_OBJ_MESY(), + 2000, 30000, 50000, + s800->GetIonChamber().Charge()); + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + std::string histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + Double_t ata = s800->GetAta(); + Double_t bta = s800->GetBta(); + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + ata); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + bta); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + bta, + 200, -0.1, 0.1, + ata); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + histname = Form("scatter_%s_%s", + incoming->GetName(), + outgoing->GetName()); + Double_t scatter = sqrt(ata*ata + bta*bta); + obj.FillHistogram(dirname, histname, + 200, 0, 0.1, + scatter); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + std::string histname = "energy"; + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + histname = "overview"; + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 120, 0, 120, + hit.GetCrystalId()); + + histname = Form("doppler_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + histname = Form("doppler_s800_%s",outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + + histname = Form("doppler_theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + histname = Form("theta_phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ){ + histname = Form("background_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy()); + histname = Form("background_dop_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + return false; + } + + histname = Form("doppler_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + histname = Form("doppler_s800_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + + histname = Form("doppler_theta_%s_t",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + + TIter next(gates); + GCutG* gate = 0; + while ((gate = (GCutG*)next())) { + TString cutname = gate->GetName(); + if(!incoming_cut && cutname.Contains("in")) + incoming_cut = gate; + + if(!outgoing_cut && cutname.Contains("out")) + outgoing_cut = gate; + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_cut); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_cut); + + DTA(obj, incoming_cut, outgoing_cut); + + if(gretina) { + + HandleGretina(obj, incoming_cut, outgoing_cut, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + // obj.FillHistogram(dirname,histname, + // 500, -250, 250, + // s800->GetTimestamp()-hit.GetTimestamp(), + // 2000, 0, 8000, + // hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + // histname = Form("dtime_all_reg%i",j); + // obj.FillHistogram(dirname,histname, + // 500, -250, 250, + // s800->GetTimestamp()-hit.GetTimestamp(), + // 1000, 0, 8000, + // hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_cut && !outgoing_cut && + incoming_cut->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_cut->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + // histname = Form("dtime_all_reg%i_%s_%s",j, + // incoming_cut->GetName(), + // outgoing_cut->GetName()); + // obj.FillHistogram(dirname,histname, + // 500, -250, 250, + // s800->GetTimestamp()-hit.GetTimestamp(), + // 1000, 0, 8000, + // hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_cut->GetName(), + outgoing_cut->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + + histname = "CRDC1_X"; + dirname = "CRDC"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = "CRDC2_X"; + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + diff --git a/include/gaddCommandLineOptionsHelp.h b/include/gaddCommandLineOptionsHelp.h new file mode 100644 index 00000000..cc50a2f2 --- /dev/null +++ b/include/gaddCommandLineOptionsHelp.h @@ -0,0 +1,33 @@ +#ifndef ROOT_haddCommandLineOptionsHelp +#define ROOT_haddCommandLineOptionsHelp +constexpr static const char kCommandLineOptionsHelp[] = R"RAW( +usage: hadd [-a A] [-k K] [-T T] [-O O] [-v V] [-j J] [-dbg DBG] [-d D] [-n N] + [-cachesize CACHESIZE] + [-experimental-io-features EXPERIMENTAL_IO_FEATURES] [-f F] + [-fk FK] [-ff FF] [-f0 F0] [-f6 F6] + TARGET SOURCES + +OPTIONS: + -a Append to the output + -k Skip corrupt or non-existent files, do not exit + -T Do not merge Trees + -O Re-optimize basket size when merging TTree + -v Explicitly set the verbosity level: 0 request no output, 99 is the default + -j Parallelize the execution in multiple processes + -dbg Parallelize the execution in multiple processes in debug mode (Does not delete partial files stored inside working directory) + -d Carry out the partial multiprocess execution in the specified directory + -n Open at most 'maxopenedfiles' at once (use 0 to request to use the system maximum) + -cachesize Resize the prefetching cache use to speed up I/O operations(use 0 to disable) + -experimental-io-features Used with an argument provided, enables the corresponding experimental feature for output trees + -f Gives the ability to specify the compression level of the target file(by default 4) + -fk Sets the target file to contain the baskets with the same compression + as the input files (unless -O is specified). Compresses the meta data + using the compression level specified in the first input or the + compression setting after fk (for example 206 when using -fk206) + -ff The compression level use is the one specified in the first input + -f0 Do not compress the target file + -f6 Use compression level 6. (See TFile::SetCompressionSettings for the support range of value.) + TARGET Target file + SOURCES Source files +)RAW"; +#endif diff --git a/util/gadd.cxx b/util/gadd.cxx new file mode 100644 index 00000000..4ebd5008 --- /dev/null +++ b/util/gadd.cxx @@ -0,0 +1,250 @@ +/* + + This program will add histograms (see note) and Trees from a list of root files and write them + to a target root file. The target file is newly created and must not be + identical to one of the source files. + + Syntax: + + gadd targetfile source1 source2 ... + or + gadd -f targetfile source1 source2 ... + (targetfile is overwritten if it exists) + + When the -f option is specified, one can also specify the compression + level of the target file. By default the compression level is 1, but + if "-f0" is specified, the target file will not be compressed. + if "-f6" is specified, the compression level 6 will be used. + + For example assume 3 files f1, f2, f3 containing histograms hn and Trees Tn + f1 with h1 h2 h3 T1 + f2 with h1 h4 T1 T2 + f3 with h5 + the result of + gadd -f x.root f1.root f2.root f3.root + will be a file x.root with h1 h2 h3 h4 h5 T1 T2 + where h1 will be the sum of the 2 histograms in f1 and f2 + T1 will be the merge of the Trees in f1 and f2 + + The files may contain sub-directories. + + if the source files contains histograms and Trees, one can skip + the Trees with + gadd -T targetfile source1 source2 ... + + Wildcarding and indirect files are also supported + gadd result.root myfil*.root + will merge all files in myfil*.root + gadd result.root file1.root @list.txt file2. root myfil*.root + will merge file1. root, file2. root, all files in myfil*.root + and all files in the indirect text file list.txt ("@" as the first + character of the file indicates an indirect file. An indirect file + is a text file containing a list of other files, including other + indirect files, one line per file). + + If the sources and and target compression levels are identical (default), + the program uses the TChain::Merge function with option "fast", ie + the merge will be done without unzipping or unstreaming the baskets + (i.e. direct copy of the raw byte on disk). The "fast" mode is typically + 5 times faster than the mode unzipping and unstreaming the baskets. + + NOTE1: By default histograms are added. However gadd does not support the case where + histograms have their bit TH1::kIsAverage set. + + NOTE2: gadd returns a status code: 0 if OK, -1 otherwise + + Authors: Rene Brun, Dirk Geppert, Sven A. Schmidt, sven.schmidt@cern.ch + : rewritten from scratch by Rene Brun (30 November 2005) + to support files with nested directories. + Toby Burnett implemented the possibility to use indirect files. + + Moved into this directory with the name gadd to link with grsisort by Ryan Dunlop + */ + +#include "RConfig.h" +#include +#include "TFile.h" +#include "THashList.h" +#include "TKey.h" +#include "TObjString.h" +#include "Riostream.h" +#include "TClass.h" +#include "TSystem.h" +#include + +#include "TFileMerger.h" +#include "TROOT.h" +#include "TInterpreter.h" + +//___________________________________________________________________________ +int main( int argc, char **argv ) +{ + + if ( argc < 3 || "-h" == std::string(argv[1]) || "--help" == std::string(argv[1]) ) { + std::cout << "Usage: " << argv[0] << " [-f[0-9]] [-k] [-T] [-O] [-n maxopenedfiles] [-v verbosity] targetfile source1 [source2 source3 ...]" << std::endl; + std::cout << "This program will add histograms from a list of root files and write them" << std::endl; + std::cout << "to a target root file. The target file is newly created and must not " << std::endl; + std::cout << "exist, or if -f (\"force\") is given, must not be one of the source files." << std::endl; + std::cout << "Supply at least two source files for this to make sense... ;-)" << std::endl; + std::cout << "If the option -k is used, gadd will not exit on corrupt or non-existant input files but skip the offending files instead." << std::endl; + std::cout << "If the option -T is used, Trees are not merged" <= argc) { + std::cerr << "Error: no maximum number of opened was provided after -n.\n"; + } else { + Long_t request = strtol(argv[a+1], 0, 10); + if (request < kMaxLong && request >= 0) { + maxopenedfiles = (Int_t)request; + ++a; + ++ffirst; + } else { + std::cerr << "Error: could not parse the max number of opened file passed after -n: " << argv[a+1] << ". We will use the system maximum.\n"; + } + } + ++ffirst; + } else if ( strcmp(argv[a],"-v") == 0 ) { + if (a+1 >= argc) { + std::cerr << "Error: no verbosity level was provided after -v.\n"; + } else { + Long_t request = strtol(argv[a+1], 0, 10); + if (request < kMaxLong && request >= 0) { + verbosity = (Int_t)request; + ++a; + ++ffirst; + } else { + std::cerr << "Error: could not parse the verbosity level passed after -v: " << argv[a+1] << ". We will use the default value (99).\n"; + } + } + ++ffirst; + } else if ( argv[a][0] == '-' ) { + char ft[4]; + for( int j=0; j<=9; ++j ) { + snprintf(ft,4,"-f%d",j); + if (!strcmp(argv[a],ft)) { + force = kTRUE; + newcomp = j; + ++ffirst; + break; + } + } + if (!force) { + // Bad argument + std::cerr << "Error: option " << argv[a] << " is not a supported option.\n"; + ++ffirst; + } + } else if (!outputPlace) { + outputPlace = a; + } + } + + gSystem->Load("libTreePlayer"); + gSystem->Load("libGROOT"); + TClass::GetClass("ROOT::Cintex::Cintex"); // autoload Cintex if it exist. + if (gInterpreter->IsLoaded("libCintex")) { + gROOT->ProcessLine("ROOT::Cintex::Cintex::Enable();"); + } + const char *targetname = 0; + if (outputPlace) { + targetname = argv[outputPlace]; + } else { + targetname = argv[ffirst-1]; + } + + if (verbosity > 1) { + std::cout << "gadd Target file: " << targetname << std::endl; + } + + TFileMerger merger(kFALSE,kFALSE); + merger.SetMsgPrefix("gadd"); + merger.SetPrintLevel(verbosity - 1); + if (maxopenedfiles > 0) { + merger.SetMaxOpenedFiles(maxopenedfiles); + } + if (!merger.OutputFile(targetname,force,newcomp) ) { + std::cerr << "gadd error opening target file (does " << argv[ffirst-1] << " exist?)." << std::endl; + std::cerr << "Pass \"-f\" argument to force re-creation of output file." << std::endl; + exit(1); + } + + + for ( int i = ffirst; i < argc; i++ ) { + if (argv[i] && argv[i][0]=='@') { + std::ifstream indirect_file(argv[i]+1); + if( ! indirect_file.is_open() ) { + std::cerr<< "gadd could not open indirect file " << (argv[i]+1) << std::endl; + return 1; + } + while( indirect_file ){ + std::string line; + if( std::getline(indirect_file, line) && line.length() && !merger.AddFile(line.c_str()) ) { + return 1; + } + } + } else if( ! merger.AddFile(argv[i]) ) { + if ( skip_errors ) { + std::cerr << "gadd skipping file with error: " << argv[i] << std::endl; + } else { + std::cerr << "gadd exiting due to error in " << argv[i] << std::endl; + return 1; + } + } + } + if (reoptimize) { + merger.SetFastMethod(kFALSE); + } else { + if (merger.HasCompressionChange()) { + // Don't warn if the user any request re-optimization. + std::cout <<"gadd Sources and Target have different compression levels"<GetEntries() << " input files in " << targetname << ".\n"; + } + return 0; + } else { + if (verbosity == 1) { + std::cout << "gadd failure during the merge of " << merger.GetMergeList()->GetEntries() << " input files in " << targetname << ".\n"; + } + return 1; + } +} diff --git a/util/gadd_fast.py b/util/gadd_fast.py index 0956b605..54ea0fe2 100755 --- a/util/gadd_fast.py +++ b/util/gadd_fast.py @@ -106,7 +106,8 @@ def main(): # return 0 - with Merger(max_workers=10, files_per_merge=5, gadd_args=unknown) as merger: +# with Merger(max_workers=10, files_per_merge=5, gadd_args=unknown) as merger: + with Merger(max_workers=10, files_per_merge=2, gadd_args=unknown) as merger: merger.merge(args.input_files, args.output_file) return 0 From 67df68e8ee025c2ca027e70241cf99dedde3574b Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 6 Jun 2023 09:54:05 -0400 Subject: [PATCH 16/29] Naming fix for histos/MakeHistos_e19028.cxx. --- histos/MakeHistos_e19028.cxx | 46 +++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/histos/MakeHistos_e19028.cxx b/histos/MakeHistos_e19028.cxx index 9c879ee4..36479b79 100644 --- a/histos/MakeHistos_e19028.cxx +++ b/histos/MakeHistos_e19028.cxx @@ -290,31 +290,34 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, 120, 0, 120, hit.GetCrystalId()); - histname = Form("doppler_%s",outgoing->GetName()); + histname = Form("doppler_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); - histname = Form("doppler_s800_%s",outgoing->GetName()); + histname = Form("doppler_s800_%s_%s",incoming->GetName(), + outgoing->GetName()); TVector3 track = s800->Track(); obj.FillHistogram(dirname, histname, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, &track)); - histname = Form("doppler_theta_%s",outgoing->GetName()); + histname = Form("doppler_theta_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 100, 0, TMath::Pi(), hit.GetTheta(), energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); - histname = Form("theta_phi_%s",outgoing->GetName()); + histname = Form("theta_phi_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetPhi(), 500, 0, TMath::Pi(), hit.GetTheta()); - histname = Form("theta_%s",outgoing->GetName()); + histname = Form("theta_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetTheta()); @@ -324,32 +327,38 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, hit.GetPhi()); if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ - histname = Form("theta_phi_fw_%s",outgoing->GetName()); + histname = Form("theta_phi_fw_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetPhi(), 500, 0, TMath::Pi(), hit.GetTheta()); - histname = Form("theta_fw_%s",outgoing->GetName()); + histname = Form("theta_fw_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetTheta()); - histname = Form("phi_fw_%s",outgoing->GetName()); + histname = Form("phi_fw_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetPhi()); } else { - histname = Form("theta_phi_bw_%s",outgoing->GetName()); + histname = Form("theta_phi_bw_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetPhi(), 500, 0, TMath::Pi(), hit.GetTheta()); - histname = Form("theta_bw_%s",outgoing->GetName()); + histname = Form("theta_bw_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetTheta()); - histname = Form("phi_bw_%s",outgoing->GetName()); + histname = Form("phi_bw_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 500, 0, TMath::Pi(), hit.GetPhi()); @@ -361,28 +370,33 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), hit.GetCoreEnergy()) ){ - histname = Form("background_%s",outgoing->GetName()); + histname = Form("background_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, energyNChannels*4, energyLlim, energyUlim, hit.GetCoreEnergy()); - histname = Form("background_dop_%s",outgoing->GetName()); + histname = Form("background_dop_%s_%s",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, energyNChannels*4, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); return false; } - histname = Form("doppler_%s_t",outgoing->GetName()); + histname = Form("doppler_%s_%s_t",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); - histname = Form("doppler_s800_%s_t",outgoing->GetName()); + histname = Form("doppler_s800_%s_%s_t",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, &track)); - histname = Form("doppler_theta_%s_t",outgoing->GetName()); + histname = Form("doppler_theta_%s_%s_t",incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 100, 0, TMath::Pi(), hit.GetTheta(), From 9618a4ccd653d1d7ea7479222e949a45f5f86d49 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Wed, 7 Jun 2023 09:31:28 -0400 Subject: [PATCH 17/29] Update to e19028 analysis. --- histos/MakeHistos_e19028.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/histos/MakeHistos_e19028.cxx b/histos/MakeHistos_e19028.cxx index 36479b79..8b0ac69e 100644 --- a/histos/MakeHistos_e19028.cxx +++ b/histos/MakeHistos_e19028.cxx @@ -147,27 +147,27 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ 200, -0.1, 0.1, s800->GetDta()); - Double_t ata = s800->GetAta(); - Double_t bta = s800->GetBta(); + Double_t ata = s800->GetAta()*TMath::RadToDeg(); + Double_t bta = s800->GetBta()*TMath::RadToDeg(); histname = Form("ata_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, + 120, -6.0, 6.0, ata); histname = Form("bta_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, + 120, -6.0, 6.0, bta); histname = Form("ata_bta_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 200, -0.1, 0.1, + 120, -6.0, 6.0, bta, - 200, -0.1, 0.1, + 120, -6.0, 6.0, ata); histname = Form("yta_%s_%s", incoming->GetName(), @@ -180,7 +180,7 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ outgoing->GetName()); Double_t scatter = sqrt(ata*ata + bta*bta); obj.FillHistogram(dirname, histname, - 200, 0, 0.1, + 60, 0, 6, scatter); return true; From e78b219105825cb16a0055c90e46462ddc59a149 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Thu, 8 Jun 2023 09:47:55 -0400 Subject: [PATCH 18/29] Broadened incoming PID ranges --- histos/MakeHistos_e19028.cxx | 4 ++-- histos/MakeHistos_e19028_Trigger.cxx | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/histos/MakeHistos_e19028.cxx b/histos/MakeHistos_e19028.cxx index 8b0ac69e..da4534b4 100644 --- a/histos/MakeHistos_e19028.cxx +++ b/histos/MakeHistos_e19028.cxx @@ -85,9 +85,9 @@ bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { //LR (e19028 Run0022, 74Kr setting, emtpy cell) obj.FillHistogram(dirname, histname, - 600, -1800, -1200, + 1400, -2400, -1000, s800->GetOBJ_E1Raw_MESY(), - 800, 3000, 3800, + 1400, 2600, 4000, s800->GetXF_E1Raw_MESY()); return true; diff --git a/histos/MakeHistos_e19028_Trigger.cxx b/histos/MakeHistos_e19028_Trigger.cxx index cfb113df..9d707451 100644 --- a/histos/MakeHistos_e19028_Trigger.cxx +++ b/histos/MakeHistos_e19028_Trigger.cxx @@ -31,7 +31,6 @@ #define Q8 6 #define Q9 21 -//#define BETA .37 std::map HoleQMap; std::map LayerMap; @@ -84,9 +83,9 @@ bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { //LR (e19028 Run0022, 74Kr setting, emtpy cell) obj.FillHistogram(dirname, histname, - 600, -1800, -1200, + 1400, -2400, -1000, s800->GetOBJ_E1Raw_MESY(), - 800, 3000, 3800, + 1400, 2600, 4000, s800->GetXF_E1Raw_MESY()); return true; From 2c127c68b389e41cd1bd80b32ff0d2c44b903597 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Thu, 8 Jun 2023 14:45:11 -0400 Subject: [PATCH 19/29] More range adjustments ... --- histos/MakeHistos_e19028.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/histos/MakeHistos_e19028.cxx b/histos/MakeHistos_e19028.cxx index da4534b4..b63dc865 100644 --- a/histos/MakeHistos_e19028.cxx +++ b/histos/MakeHistos_e19028.cxx @@ -153,21 +153,21 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 120, -6.0, 6.0, + 1200, -6.0, 6.0, ata); histname = Form("bta_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 120, -6.0, 6.0, + 1200, -6.0, 6.0, bta); histname = Form("ata_bta_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 120, -6.0, 6.0, + 1200, -6.0, 6.0, bta, - 120, -6.0, 6.0, + 1200, -6.0, 6.0, ata); histname = Form("yta_%s_%s", incoming->GetName(), @@ -180,7 +180,7 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ outgoing->GetName()); Double_t scatter = sqrt(ata*ata + bta*bta); obj.FillHistogram(dirname, histname, - 60, 0, 6, + 600, 0, 6, scatter); return true; From 15b15e82e681d4698546947c930160fccea49679 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Thu, 8 Jun 2023 19:05:44 -0400 Subject: [PATCH 20/29] added crdc_?_x spectra --- histos/MakeHistos_e19028.cxx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/histos/MakeHistos_e19028.cxx b/histos/MakeHistos_e19028.cxx index b63dc865..11193cc1 100644 --- a/histos/MakeHistos_e19028.cxx +++ b/histos/MakeHistos_e19028.cxx @@ -140,9 +140,22 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ return false; std::string dirname = "S800"; - std::string histname = Form("dta_%s_%s", + + std::string histname = Form("crdc1_x_%s_%s", incoming->GetName(), outgoing->GetName()); + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = Form("crdc2_x_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(1).GetDispersiveX()); + + histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); obj.FillHistogram(dirname, histname, 200, -0.1, 0.1, s800->GetDta()); @@ -515,16 +528,6 @@ void MakeHistograms(TRuntimeObjects& obj) { } } } - - histname = "CRDC1_X"; - dirname = "CRDC"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(0).GetDispersiveX()); - - histname = "CRDC2_X"; - obj.FillHistogram(dirname,histname,800,-400,400, - s800->GetCrdc(1).GetDispersiveX()); - } if(numobj!=list->GetSize()) From d72e11d7e425a55f996e80ccea9ba54ac3448ba3 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 25 Jul 2023 11:05:38 -0400 Subject: [PATCH 21/29] Installed a guardrail at 224 on the crdc maximum pad. --- libraries/TDetSystems/TS800/#TS800Hit.cxx# | 762 --------------------- libraries/TDetSystems/TS800/TS800.cxx | 1 + libraries/TDetSystems/TS800/TS800Hit.cxx | 1 + 3 files changed, 2 insertions(+), 762 deletions(-) delete mode 100644 libraries/TDetSystems/TS800/#TS800Hit.cxx# diff --git a/libraries/TDetSystems/TS800/#TS800Hit.cxx# b/libraries/TDetSystems/TS800/#TS800Hit.cxx# deleted file mode 100644 index 459f8856..00000000 --- a/libraries/TDetSystems/TS800/#TS800Hit.cxx# +++ /dev/null @@ -1,762 +0,0 @@ -#include "Globals.h" - -#include "TS800Hit.h" -#include "TRandom.h" -#include "GCanvas.h" -#include "TH2.h" -#include "TGraph.h" -#include "TF1.h" -#include "TVirtualFitter.h" - -TTrigger::TTrigger() { - Clear(); -} - -TTrigger::~TTrigger() { -} - -void TTrigger::Copy(TObject &obj) const { - TDetectorHit::Copy(obj); - TTrigger &trig =(TTrigger&)obj; - trig.fregistr = fregistr; - trig.fs800source = fs800source; - trig.fexternalsource1 = fexternalsource1; - trig.fexternalsource2 = fexternalsource2; - trig.fsecondarysource = fsecondarysource; -} - -void TTrigger::Clear(Option_t *opt) { - fregistr = -1; - fs800source = -1; - fexternalsource1 = -1; - fexternalsource2 = -1; - fsecondarysource = -1; -} - -void TTrigger::Print(Option_t *opt) const { } - -TTof::TTof() { - Clear(); -} - -TTof::~TTof() { -} - -void TTof::Copy(TObject &obj) const { - TDetectorHit::Copy(obj); - TTof &tof_ =(TTof&)obj; - tof_.frf = frf; - tof_.fobj = fobj; - tof_.fxfp = fxfp; - tof_.fsi = fsi; - tof_.ftac_obj = ftac_obj; - tof_.ftac_xfp = ftac_xfp; -} - -void TTof::Clear(Option_t *opt) { - frf = -1; - fobj = -1; - fxfp = -1; - fsi = -1; - ftac_obj = -1; - ftac_xfp = -1; -} - -void TTof::Print(Option_t *opt) const { } - -/******* End of Ttof. Beginning of TScintillator **********/ - -TScintillator::TScintillator() { - Clear(); -} - -TScintillator::~TScintillator() { -} - -void TScintillator::Copy(TObject &obj) const { - TDetectorHit::Copy(obj); - TScintillator &scinti =(TScintillator&)obj; - scinti.fID = fID; - scinti.fdE_up = fdE_up; - scinti.fdE_down = fdE_down; - scinti.fTime_up = fTime_up; - scinti.fTime_down = fTime_down; - -} - -void TScintillator::Clear(Option_t *opt) { - fID = -1; - fdE_up = -1; - fdE_down = -1; - fTime_up = -1; - fTime_down = -1; -} - -void TScintillator::Print(Option_t *opt) const { } - - -/******* End of TScintillator. Beginning of TIonChamber **********/ - -TIonChamber::TIonChamber() { - Clear(); -} - -TIonChamber::~TIonChamber() { -} - -void TIonChamber::Set(int ch, int data){ - fChan.push_back(ch); - fData.push_back(data); -} - -float TIonChamber::GetAve(){ - float temp =0.0; - //if(fdE==-1.0) { - - for(unsigned int x=0;xCalEnergy(fData.at(x)); - } - else{ - temp += fData.at(x); - } - } - if(temp>0) - temp = temp/((float)fData.size()); - return temp; -} - - -float TIonChamber::GetSum(){ - float temp =0.0; - //if(fdE==-1.0) { - /* - for(unsigned int x=0;xCalEnergy(fData.at(x)); - } - else{ - temp += fData.at(x); - } - } - if(temp>0) - temp = temp/((float)fData.size());*/ - - for(int x=0;xCalEnergy(GetData(x)); - }else{ - temp+=GetData(x); - } - } - return temp; -} - -//FROM GRROOT -//bool Calibration::BuildIonChamber(GIonChamber* in, TRACK* track, IC* out){ -// out->Clear(); -// out->SetCal(ICCal(in)); -// double sum = ICSum(out->GetCal()); -// double IC_corg = 1; -// double IC_coro = 0; -// if(fIC_cor[0]!=NULL) -// IC_corg = fIC_cor[0]->GetBinContent(fevent/10000+1); -// if(fIC_cor[1]!=NULL) -// IC_coro = fIC_cor[1]->GetBinContent(fevent/10000+1); -// sum *= IC_corg; -// sum += IC_coro; -// out->SetSum(sum); -// out->SetDE(ICDE(sum,track)); -// if(!isnan(sum) && sum>fSett->ICThresh()){ -// fichctr++; -// return true; -// } -// return false; -//} -//Float_t Calibration::ICDE(Float_t sum, TRACK* track){ -// Float_t x = track->GetXFP(); -// Float_t y = track->GetYFP(); -// if(!isnan(sum) && !isnan(track->GetAFP())){ -// if(!isnan(y)) -// sum += sum*fSett->dE_ytilt()*y; -// if(!isnan(x) && x < fSett->dE_x0tilt()) -// sum *= exp(fSett->dE_xtilt()* (fSett->dE_x0tilt() -x) ); -// fs800valid = 0; -// return sum * fde_slope + fde_offset; -// } else { -// return sqrt(-1.0); -// } -//} - -//We already have ICSum, it's our current getdE() unction. We need to somehow get the -//track from the crdc into this function, and figure out what IC_corg is. - -//TODO: We need to change this function to correct the sum for each event -// based on the track through the CRDCs - -float TIonChamber::GetdE(){ - //std::cout << "GetdE() NOT IMPLEMENTED! Just returning GetSum()" << std::endl; - return GetSum(); -} - -//Calculate energy loss in Ion Chamber corrected -//for particle track -float TIonChamber::GetdECorr(TCrdc *crdc){ - float sum = GetdE(); - float x = crdc->GetDispersiveX(); - float y = crdc->GetNonDispersiveY(); - - float xtilt = GValue::Value("IC_DE_XTILT"); - float ytilt = GValue::Value("IC_DE_YTILT"); - float x0tilt = GValue::Value("IC_DE_X0TILT"); - - /* std::cout << "---------------------" << std::endl; - std::cout << " xtilt = " << xtilt << std::endl; - std::cout << " ytilt = " << ytilt << std::endl; - std::cout << " x0tilt = " << x0tilt << std::endl; - std::cout << BLUE << " SUM = " << sum << RESET_COLOR << std::endl; - */ - sum += sum * ytilt * y; - // std::cout << GREEN << " SUM2 = " << sum << RESET_COLOR << std::endl; - sum *= TMath::Exp(xtilt*(x0tilt-x)); - //std::cout << RED << " SUM3 = " << sum << RESET_COLOR << std::endl; - return sum; -} - -void TIonChamber::Copy(TObject &obj) const { - TDetectorHit::Copy(obj); - TIonChamber &ic =(TIonChamber&)obj; - ic.fChan = fChan; - ic.fData = fData; - -} - -void TIonChamber::Clear(Option_t *opt) { - TDetectorHit::Clear(opt); - //fdE = -1; - fChan.clear(); - fData.clear(); -} - -void TIonChamber::Print(Option_t *opt) const { } - -/******* End of TIonChamber. Beginning of TWhatever **********/ - - -TCrdc::TCrdc() { - Clear(); -} - -TCrdc::~TCrdc() { -} - -TF1 *TCrdc::fgaus = new TF1("fgaus","gaus"); - - -int TCrdc::GetMaxPad() const { -// double temp = 0; -// int place =0; - if(!data.size()) - return -1.0; - - std::cout << " Data has size? = " << data.size() << std::endl; - std::map sum; - -// temp = data.at(0); - for(unsigned int i = 0; i < data.size(); i++){ - /* - std::cout << " ------ " << std::endl; - std::cout << " Data : " << data.at(i) << " at " << i << std::endl; - std::cout << " Sample : " << sample.at(i) << " at " << i << std::endl; - std::cout << " Channel : " << channel.at(i) << " at " << i << std::endl; - */ - - - /*if(data.at(i)>0){ - WeightedSumNum += float(data.at(i))*float(channel.at(i)); - WeightedSumDen += float(channel.at(i)); - - }*/ - - if(!IsGoodSample(i)) { - continue; - } - - TChannel *c = TChannel::GetChannel(Address(i)); - double cal_data; - if(c){ - cal_data = c->CalEnergy(data.at(i)); - } - else{ - cal_data = (double)data.at(i); - } - sum[channel.at(i)] += cal_data; - } - - std::map::iterator it; - int max = -1; - double maxd =-1; - for(it = sum.begin();it!=sum.end();it++) { - if(it->second > maxd){ - max = it->first; - maxd = it->second; - } - } - //return (float)(channel.at(place))+gRandom->Uniform(); - return max; -} - -int TCrdc::GetMaxPadSum() const{ - if(!data.size()) - return -1.0; - - std::map sum; - - for(unsigned int i = 0; i < data.size(); i++){ - bool good = false; - if (i == 0 && data.size()>1) { - if(channel.at(i) == channel.at(i+1)) - good = true; - } - else if(i == data.size()-1 && data.size()>2) { - if(channel.at(i) == channel.at(i-1)) - good = true; - } else if(data.size()>2) { - if((channel.at(i) == channel.at(i-1)) || - (channel.at(i) == channel.at(i+1))) - good = true; - } - - if(!good){ - continue; - } - - TChannel *c = TChannel::GetChannel(Address(i)); - double cal_data; - if(c){ - cal_data = c->CalEnergy(data.at(i)); - } - else{ - cal_data = (double)data.at(i); - } - - sum[channel.at(i)] += cal_data; - } - - std::map::iterator it; - double maxd =-1.0; - for(it = sum.begin();it!=sum.end();it++) { - if(it->second > maxd){ - maxd = it->second; - } - } - //return (float)(channel.at(place))+gRandom->Uniform(); - return maxd; -} - -void TCrdc::DrawChannels(Option_t *opt,bool calibrate) const { - if(!gPad) - new GCanvas(); - else { - //gPad->Clear(); - //GCanvas* c = (GCanvas*)gPad->GetCanvas(); - //c->Clear(); - } - - std::vector hits; - //int currentchannel = -1; - //TH2I *currenthist = 0; - TH2I hist(Form("crdc_%i",fId),Form("crdc_%i",fId),224,0,224,128,0,128); - for(int x=0;xSize();x++) { - //if(channel.at(x)!=currentchannel) { - - //TH1I hist(Form("channel_%02i",channel.at(x)),Form("channel_%02i",channel.at(x)),512,0,512); - //hits.push_back(hist); - //currentchannel = channel.at(x); - //currenthist = &(hits.back()); - double cal_data; - //printf("channel.size() = %i \t ",channel.size()); - //printf("address = %08x \t ",Address(x)); - //printf("channel = %i \t ",channel.at(x)); - //printf("x = %i ",x); - TChannel *c = TChannel::GetChannel(Address(x)); - if(c && calibrate) { - cal_data = c->CalEnergy(data.at(x)); -// printf("cal_data[%03i] = %f\n",channel.at(x),cal_data); - } else { - if(!c) - printf("failed to find TChannel for 0x%08x\n",Address(x)); - cal_data = data.at(x); - //printf("cal_data[%03i] = %f\n",channel.at(x),cal_data); - } - hist.Fill(channel.at(x),sample.at(x),cal_data); - //} - //hist.Fill(sample.at(x),data.at(x)); - } - //c->Divide(1,hits.size()); - //for(int x=0;xcd(x+1); - // hits.at(x).DrawCopy(); - //} - //printf("GetMaxPad() = %i\n",GetMaxPad()); - //printf("GetDipersiveX() = %.02f\n",GetDispersiveX()); - hist.DrawCopy("colz"); - return; -} - -void TCrdc::DrawHit(Option_t *opt) const { - GCanvas *c = 0; - if(!gPad) - c = new GCanvas(); - else { - //gPad->Clear(); - c = (GCanvas*)gPad->GetCanvas(); - c->Clear(); - } - TH1I *mat = new TH1I("hit_pattern","hit_pattern",256,0,256); - int currentchannel = -1; - int currentx = -1; - //int currenty = -1; - int datasum =0; - for(int x=0;xFill(currentx,datasum); - datasum = 0; - currentchannel = channel.at(x); - currentx = channel.at(x); - //currenty = channel.at(x)%16; - } - datasum+=data.at(x); - - } - if(currentchannel!=-1) - mat->Fill(currentx,datasum); - - std::string options = ""; - options.append(opt); - mat->Draw(options.c_str()); - - return; -} - - -int TCrdc::GetWidth() { - if(Size()<2) - return 0; - return sample.back()-sample.front()+1; -} - -void TCrdc::Copy(TObject &obj) const { - TDetectorHit::Copy(obj); - TCrdc &c = (TCrdc&)obj; - c.fId = fId; - c.channel = channel; - c.sample = sample; - c.data = data; - c.anode = anode; - c.time = time; -//c.fCRDCXslope = fCRDCXslope; -//c.fCRDCYslope = fCRDCYslope; -//c.fCRDCXoff = fCRDCXoff; -//c.fCRDCYoff = fCRDCYoff; -} - -void TCrdc::Clear(Option_t *opt) { - TDetectorHit::Clear(opt); - fId = -1; - anode = 0; - time = 0; - channel.clear(); - sample.clear(); - data.clear(); -} - -/* -float TCrdc::GetDispersiveX() const{ - if (GetMaxPad() ==-1){ - return sqrt(-1); - } - - float x_slope = sqrt(-1); - float x_offset = sqrt(-1); - if(fId==0) { - x_slope = GValue::Value("CRDC1_X_SLOPE"); - x_offset = GValue::Value("CRDC1_X_OFFSET"); - } else if(fId==1) { - x_slope = GValue::Value("CRDC2_X_SLOPE"); - x_offset = GValue::Value("CRDC2_X_OFFSET"); - } - - std::map datamap; - int mpad = GetMaxPad(); - for(int i=0;i(mpad+10))) - continue; - datamap[channel.at(i)] += GetData(i); - } - - - int i=0; - std::map::iterator it; - TGraph g(datamap.size()); - for(it=datamap.begin();it!=datamap.end();it++) { - g.SetPoint(i++,it->first,it->second); - } - TVirtualFitter::SetMaxIterations(10); - g.Fit(fgaus,"qgoff"); // "gaus","q","goff"); - TVirtualFitter::SetMaxIterations(5000); - //new GCanvas; - //g->Draw("AC"); - //new GCanvas; - //printf("fgaus->GetParameter(1) = %.02f\n",fgaus->GetParameter(1)); - //return (GetMaxPad()*x_slope+x_offset); - double pad = fgaus->GetParameter(1); - //fgaus->Reset(); - return (pad*x_slope+x_offset); -} -*/ - -//float TCrdc::GetDispersiveX() const{ -// if (GetMaxPad() ==-1){ -// return sqrt(-1); -// } - -// float x_slope = sqrt(-1); -// float x_offset = sqrt(-1); -// if(fId==0) { -// x_slope = GValue::Value("CRDC1_X_SLOPE"); -// x_offset = GValue::Value("CRDC1_X_OFFSET"); -// } else if(fId==1) { -// x_slope = GValue::Value("CRDC2_X_SLOPE"); -// x_offset = GValue::Value("CRDC2_X_OFFSET"); -// } -// if(std::isnan(x_slope)) -// x_slope = 1.0; -// if(std::isnan(x_offset)) -// x_offset = 0.0; -// - - -// std::map datamap; -// int mpad = GetMaxPad(); -// double datasum = 0; -// for(int i=0;i(mpad+10))) -// continue; -// datamap[channel.at(i)] += GetData(i); -// datasum += GetData(i); -// } -// std::map::iterator it; -// double wchansum = 0.0; -// for(it=datamap.begin();it!=datamap.end();it++) { -// wchansum += it->first*(it->second/datasum); -// } -// return (wchansum*x_slope+x_offset); -//} - -bool TCrdc::IsGoodSample(int i) const { - if (i == 0 && data.size()>1) { - return channel.at(i) == channel.at(i+1); - - } else if(i == (int)data.size()-1 && data.size()>2) { - return channel.at(i) == channel.at(i-1); - - } else if(data.size()>2) { - return (channel.at(i) == channel.at(i-1) || - (channel.at(i) == channel.at(i+1))); - } - return false; -} - -float TCrdc::GetDispersiveX() const{ - int maxpad = GetMaxPad(); - std::cout << " Before Max Pad Return " << std::endl; - if (maxpad ==-1){ - return sqrt(-1); - } - std::cout << " After Max Pad Return " << std::endl; - - float x_slope = sqrt(-1); - float x_offset = sqrt(-1); - if(fId==0) { - x_slope = GValue::Value("CRDC1_X_SLOPE"); - x_offset = GValue::Value("CRDC1_X_OFFSET"); - } else if(fId==1) { - x_slope = GValue::Value("CRDC2_X_SLOPE"); - x_offset = GValue::Value("CRDC2_X_OFFSET"); - } - if(std::isnan(x_slope)) - x_slope = 1.0; - if(std::isnan(x_offset)) - x_offset = 0.0; - - std::map datamap; - const int GRAVITY_WIDTH = 14;//determines how many pads one uses in averaging - const int NUM_PADS = 224; - int lowpad = maxpad - GRAVITY_WIDTH/2; - int highpad = lowpad + GRAVITY_WIDTH; - if (lowpad < 0){ - lowpad = 0; - } - if (highpad >= NUM_PADS){ - highpad = NUM_PADS-1; - } - - - double datasum = 0; - double weighted_sum = 0; - for(int i=0;ihighpad) || - !IsGoodSample(i)) { - continue; - } - - TChannel *c = TChannel::GetChannel(Address(i)); - double cal_data; - if (c){ - cal_data = c->CalEnergy(GetData(i)); - } - else{ - cal_data = (double)GetData(i); - } - - datasum += cal_data; - weighted_sum += channel.at(i)*cal_data; - } - - // + 0.5 so that we take the middle of the pad, not the left edge. - double mean_chan = weighted_sum/datasum + 0.5; - return (mean_chan*x_slope+x_offset); -} - - -float TCrdc::GetNonDispersiveY() { - if (GetMaxPad() ==-1){ - return sqrt(-1); - } - float y_slope = sqrt(-1); - float y_offset = sqrt(-1); - if(fId==0) { - y_slope = GValue::Value("CRDC1_Y_SLOPE"); - y_offset = GValue::Value("CRDC1_Y_OFFSET"); - } else if(fId==1) { - y_slope = GValue::Value("CRDC2_Y_SLOPE"); - y_offset = GValue::Value("CRDC2_Y_OFFSET"); - } - - // std::cout << " ------------------ " << std::endl; - // std::cout << " 2 Slope = " << y_slope << std::endl; - // std::cout << " 2 Offst = " << y_offset << std::endl; - - // return ((GetTimeRand()*y_slope+y_offset)); - float tmp = ((float)time)*y_slope+y_offset; - //printf("fId[%i]: %.05f * %.03f + %.05f = %.05f\n",fId,y_slope,(float)time,y_offset,tmp); - return tmp; -} - -void TCrdc::Print(Option_t *opt) const { } - -TCrdcPad::TCrdcPad() { Clear(); } - -TCrdcPad::TCrdcPad(int chan) { - fChannel = chan; - fNumSamples =0; - Clear(); - for(int x=0;x::iterator it=fTrace.begin();it!=fTrace.end();it++) { - for(int x=0;x> 10; int databits = (word2&(0x03ff)); int real_channel = (connector_number << 6) + channel_number; + if(real_channel == 224) continue; /*std::cout << " sample Number : " << std::dec << sample_number << std::endl; std::cout << " channel Number : " << std::dec << channel_number << std::endl; diff --git a/libraries/TDetSystems/TS800/TS800Hit.cxx b/libraries/TDetSystems/TS800/TS800Hit.cxx index 97542ebe..0f42d912 100644 --- a/libraries/TDetSystems/TS800/TS800Hit.cxx +++ b/libraries/TDetSystems/TS800/TS800Hit.cxx @@ -281,6 +281,7 @@ int TCrdc::GetMaxPad() const { // temp = data.at(0); for(unsigned int i = 0; i < data.size(); i++){ + if(channel.at(i) == 224) continue; // e21001 extra channel causing problems /* std::cout << " ------ " << std::endl; std::cout << " Data : " << data.at(i) << " at " << i << std::endl; From a4b5247c559f1befa98db4c5862721a017911226 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 25 Jul 2023 14:14:52 -0400 Subject: [PATCH 22/29] e21001 Coulex --- histos/MakeHistos_e21001.cxx | 556 +++++++++++++++++++++++++++++++++++ 1 file changed, 556 insertions(+) create mode 100644 histos/MakeHistos_e21001.cxx diff --git a/histos/MakeHistos_e21001.cxx b/histos/MakeHistos_e21001.cxx new file mode 100644 index 00000000..97720ffb --- /dev/null +++ b/histos/MakeHistos_e21001.cxx @@ -0,0 +1,556 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TBank88.h" +#include "TS800.h" +#include "GCutG.h" + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 11 +#define Q4 1 +#define Q5 22 +#define Q6 14 +#define Q7 12 +#define Q8 6 +#define Q9 21 + + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. + +GCutG *incoming_cut=0; + +GCutG *outgoing_cut=0; + +GCutG *gt_time=0; + +bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(outgoing) { + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + histname = Form("incoming_%s", outgoing->GetName()); + } else { + histname = "incoming"; + } + + //LR (e19028 Run0022, 74Kr setting, emtpy cell) + obj.FillHistogram(dirname, histname, + 1500, -5000, -2000, + s800->GetOBJ_E1Raw_MESY(), + 1500, 500, 3500, + s800->GetXF_E1Raw_MESY()); + + return true; +} + + +bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { + + if(!s800) + return false; + + std::string dirname = "S800"; + std::string histname; + if(incoming) { + if( !incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + histname = Form("outgoing_%s", incoming->GetName()); + } else { + histname = "outgoing"; + } + + obj.FillHistogram(dirname, histname, + 1000, -4600, -3600, + s800->GetCorrTOF_OBJ_MESY(), + 1200, 6000, 20000, + s800->GetIonChamber().Charge()); + return true; + +} + +bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TS800 *s800 = obj.GetDetector(); + + if(!s800) + return false; + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + // if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + // s800->GetIonChamber().GetSum()) ) + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + std::string dirname = "S800"; + + std::string histname = Form("crdc1_x_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname,histname,800,-400,400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = Form("crdc2_x_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname,histname, + 800, -400, 400, + s800->GetCrdc(1).GetDispersiveX()); + + histname = Form("crdc1_x_TOF_OBJ_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname,histname, + 1000, -4600, -3600, + s800->GetCorrTOF_OBJ_MESY(), + 800, -400, 400, + s800->GetCrdc(0).GetDispersiveX()); + + histname = Form("AFP_TOF_OBJ_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname,histname, + 1000, -4600, -3600, + s800->GetCorrTOF_OBJ_MESY(), + 100, -0.05, 0.05, + s800->GetAFP()); + + histname = Form("dta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -0.1, 0.1, + s800->GetDta()); + + Double_t ata = s800->GetAta()*TMath::RadToDeg(); + Double_t bta = s800->GetBta()*TMath::RadToDeg(); + histname = Form("ata_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 1200, -6.0, 6.0, + ata); + histname = Form("bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 1200, -6.0, 6.0, + bta); + histname = Form("ata_bta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 1200, -6.0, 6.0, + bta, + 1200, -6.0, 6.0, + ata); + histname = Form("yta_%s_%s", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 200, -20, 20, + s800->GetYta()); + histname = Form("scatter_%s_%s", + incoming->GetName(), + outgoing->GetName()); + Double_t scatter = sqrt(ata*ata + bta*bta); + obj.FillHistogram(dirname, histname, + 600, 0, 6, + scatter); + + return true; +} + +bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + std::string dirname = "S800"; + std::string histname; + + histname = "trigger_bit"; + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + + if(!incoming || !outgoing) + return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if( !outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().Charge()) ) + return false; + + histname = "trigger_bit_PID"; + for(int j=0;j<16;j++) { + if(((bits>>j)&0x0001)) + obj.FillHistogram(dirname, histname, 20, 0, 20, j); + } + histname = "trigger_raw_PID"; + obj.FillHistogram(dirname, histname, + 20, 0, 20, + s800->GetTrigger().GetRegistr()); + return true; + +} + +bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, + GCutG *outgoing, GCutG *gt_time) { + + if(!incoming || !outgoing) + return false; + + TGretina *gretina = obj.GetDetector(); + TS800 *s800 = obj.GetDetector(); + + if(!gretina || !s800) + return false; + + // if(!((s800->GetTrigger().GetRegistr()&0x0002)>>1)) + // return false; + + if(!incoming->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) ) + return false; + + if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ) + return false; + // s800->GetIonChamber().Charge()) ) + + std::string dirname = "gretina"; + + Int_t energyNChannels = 2000; + Double_t energyLlim = 0.; + Double_t energyUlim = 8000.; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset, yoffset, zoffset); + + for(int x=0;xSize();x++) { + TGretinaHit hit = gretina->GetGretinaHit(x); + std::string histname = "energy"; + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + histname = "overview"; + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 120, 0, 120, + hit.GetCrystalId()); + + histname = Form("doppler_%s_%s",incoming->GetName(), outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + histname = Form("doppler_s800_%s_%s",incoming->GetName(), + outgoing->GetName()); + TVector3 track = s800->Track(); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + + histname = Form("doppler_theta_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + histname = Form("theta_phi_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_%s_%s",incoming->GetName(), outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_%s",outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + + if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ + histname = Form("theta_phi_fw_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_fw_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_fw_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } else { + histname = Form("theta_phi_bw_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi(), + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("theta_bw_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetTheta()); + histname = Form("phi_bw_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, TMath::Pi(), + hit.GetPhi()); + } + + // Time cut + if(!gt_time) + return false; + + if( !gt_time->IsInside(s800->GetTimestamp()-hit.GetTime(), + hit.GetCoreEnergy()) ){ + histname = Form("background_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetCoreEnergy()); + histname = Form("background_dop_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels*4, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + return false; + } + + histname = Form("doppler_%s_%s_t",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + histname = Form("doppler_s800_%s_%s_t",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + + histname = Form("doppler_theta_%s_%s_t",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + } + + + return true; +} + + +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + //std::cout << "---------------------------------" <(); + TS800 *s800 = obj.GetDetector(); + //std::cout << " Dets Gotten" << std::endl; + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + TList *gates = &(obj.GetGates()); + + TIter next(gates); + GCutG* gate = 0; + while ((gate = (GCutG*)next())) { + TString cutname = gate->GetName(); + if(!incoming_cut && cutname.Contains("in")) + incoming_cut = gate; + + if(!outgoing_cut && cutname.Contains("out")) + outgoing_cut = gate; + } + + if(!gt_time) { + gt_time = (GCutG*)gates->FindObject("gt_time"); + } + + std::string histname = ""; + std::string dirname = ""; + + + if(s800) { + dirname = "S800"; + + IncomingS800(obj, s800, 0); + IncomingS800(obj, s800, incoming_cut); + + OutgoingS800(obj, s800, 0); + OutgoingS800(obj, s800, outgoing_cut); + + DTA(obj, incoming_cut, outgoing_cut); + + if(gretina) { + + HandleGretina(obj, incoming_cut, outgoing_cut, gt_time); + + dirname = "gretina"; + for(unsigned int i=0;iSize();i++) { + TGretinaHit hit = gretina->GetGretinaHit(i); + histname = "dtime_all"; + // obj.FillHistogram(dirname,histname, + // 500, -250, 250, + // s800->GetTimestamp()-hit.GetTimestamp(), + // 2000, 0, 8000, + // hit.GetCoreEnergy()); + histname = "dtimet0_all"; + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 2000, 0, 8000, + hit.GetCoreEnergy()); + unsigned short bits = s800->GetTrigger().GetRegistr(); + for(int j=0;j<5;j++) { + if((bits>>j)&0x0001) { + // histname = Form("dtime_all_reg%i",j); + // obj.FillHistogram(dirname,histname, + // 500, -250, 250, + // s800->GetTimestamp()-hit.GetTimestamp(), + // 1000, 0, 8000, + // hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i",j); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + if(incoming_cut && !outgoing_cut && + incoming_cut->IsInside(s800->GetOBJ_E1Raw_MESY(), + s800->GetXF_E1Raw_MESY()) && + outgoing_cut->IsInside(s800->GetCorrTOF_OBJ_MESY(), + s800->GetIonChamber().GetSum()) ){ + // s800->GetIonChamber().Charge()) ){ + + // histname = Form("dtime_all_reg%i_%s_%s",j, + // incoming_cut->GetName(), + // outgoing_cut->GetName()); + // obj.FillHistogram(dirname,histname, + // 500, -250, 250, + // s800->GetTimestamp()-hit.GetTimestamp(), + // 1000, 0, 8000, + // hit.GetCoreEnergy()); + histname = Form("dtimet0_reg%i_%s_%s",j, + incoming_cut->GetName(), + outgoing_cut->GetName()); + obj.FillHistogram(dirname,histname, + 500, 0, 500, + s800->GetTimestamp()-hit.GetTime(), + 1000, 0, 8000, + hit.GetCoreEnergy()); + } + } + } + } + } + } + + if(numobj!=list->GetSize()) + list->Sort(); + +} + From a04184846a024b778fdb998ece41469138df0f1d Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 25 Jul 2023 15:21:21 -0400 Subject: [PATCH 23/29] e21001 Coulex --- histos/MakeHistos_e21001.cxx | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/histos/MakeHistos_e21001.cxx b/histos/MakeHistos_e21001.cxx index 97720ffb..c7ba006a 100644 --- a/histos/MakeHistos_e21001.cxx +++ b/histos/MakeHistos_e21001.cxx @@ -315,6 +315,11 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, energyNChannels*4, energyLlim, energyUlim, hit.GetCoreEnergy()); + histname = "hole"; + obj.FillHistogram(dirname, histname, + 30, 0, 30, + hit.GetHoleNumber()); + histname = "overview"; obj.FillHistogram(dirname, histname, energyNChannels*4, energyLlim, energyUlim, @@ -342,10 +347,26 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); - histname = Form("theta_phi_%s_%s",incoming->GetName(), + histname = Form("hole_theta_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, + 30, 0, 30, + hit.GetHoleNumber(), 500, 0, TMath::Pi(), + hit.GetTheta()); + + histname = Form("hole_phi_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 30, 0, 30, + hit.GetHoleNumber(), + 500, 0, 2*TMath::Pi(), + hit.GetPhi()); + + histname = Form("theta_phi_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 500, 0, 2*TMath::Pi(), hit.GetPhi(), 500, 0, TMath::Pi(), hit.GetTheta()); @@ -355,14 +376,14 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, hit.GetTheta()); histname = Form("phi_%s",outgoing->GetName()); obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), + 500, 0, 2*TMath::Pi(), hit.GetPhi()); if( hit.GetCrystalPosition().Theta() < TMath::Pi()/2. ){ histname = Form("theta_phi_fw_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), + 500, 0, 2*TMath::Pi(), hit.GetPhi(), 500, 0, TMath::Pi(), hit.GetTheta()); @@ -374,13 +395,13 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, histname = Form("phi_fw_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), + 500, 0, 2*TMath::Pi(), hit.GetPhi()); } else { histname = Form("theta_phi_bw_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), + 500, 0, 2*TMath::Pi(), hit.GetPhi(), 500, 0, TMath::Pi(), hit.GetTheta()); @@ -392,7 +413,7 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, histname = Form("phi_bw_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 500, 0, TMath::Pi(), + 500, 0, 2*TMath::Pi(), hit.GetPhi()); } From 60db8626804bc8fe284f8a12f1bc9a067218793b Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Wed, 26 Jul 2023 17:13:24 -0400 Subject: [PATCH 24/29] e21001 update --- histos/MakeHistos_e21001.cxx | 70 ++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/histos/MakeHistos_e21001.cxx b/histos/MakeHistos_e21001.cxx index c7ba006a..83cd9e2a 100644 --- a/histos/MakeHistos_e21001.cxx +++ b/histos/MakeHistos_e21001.cxx @@ -83,7 +83,6 @@ bool OutgoingS800(TRuntimeObjects &obj, TS800 *s800, GCutG *outgoing) { histname = "incoming"; } - //LR (e19028 Run0022, 74Kr setting, emtpy cell) obj.FillHistogram(dirname, histname, 1500, -5000, -2000, s800->GetOBJ_E1Raw_MESY(), @@ -106,6 +105,15 @@ bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { s800->GetXF_E1Raw_MESY()) ) return false; histname = Form("outgoing_%s", incoming->GetName()); + + obj.FillHistogram(dirname, Form("CorrTOF_OBJ_MESY_%s", incoming->GetName()), + 1000, -4600, -3600, + s800->GetCorrTOF_OBJ_MESY()); + + obj.FillHistogram(dirname, Form("IonChamber_Charge_%s", incoming->GetName()), + 1200, 6000, 20000, + s800->GetIonChamber().Charge()); + } else { histname = "outgoing"; } @@ -115,7 +123,17 @@ bool IncomingS800(TRuntimeObjects &obj,TS800 *s800,GCutG *incoming) { s800->GetCorrTOF_OBJ_MESY(), 1200, 6000, 20000, s800->GetIonChamber().Charge()); - return true; + + histname = "CorrTOF_OBJ_MESY"; + obj.FillHistogram(dirname, histname, + 1000, -4600, -3600, + s800->GetCorrTOF_OBJ_MESY()); + histname = "IonChamber_Charge"; + obj.FillHistogram(dirname, histname, + 1200, 6000, 20000, + s800->GetIonChamber().Charge()); + + return true; } @@ -339,6 +357,14 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, &track)); + histname = Form("doppler_s800_theta_%s_%s",incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 100, 0, TMath::Pi(), + hit.GetTheta(), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + histname = Form("doppler_theta_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, @@ -346,7 +372,7 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, hit.GetTheta(), energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); - + histname = Form("hole_theta_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, @@ -455,6 +481,44 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, hit.GetTheta(), energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); + + Double_t ata = s800->GetAta()*TMath::RadToDeg(); + Double_t bta = s800->GetBta()*TMath::RadToDeg(); + Double_t scatter = sqrt(ata*ata + bta*bta); + + histname = Form("doppler_scatter_%s_%s_t", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 60, 0, 6, + scatter, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, 0)); + + histname = Form("doppler_s800_scatter_%s_%s_t", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + 60, 0, 6, + scatter, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + + if(scatter < 2.0) { + histname = Form("doppler_s800_0-2deg_%s_%s_t", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + } else { + histname = Form("doppler_s800_2-6deg_%s_%s_t", + incoming->GetName(), + outgoing->GetName()); + obj.FillHistogram(dirname, histname, + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(beta, &track)); + } } From f1a965e9ae9a30e9f4d2ffb91ef070a3367b5d91 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 1 Aug 2023 16:49:11 -0400 Subject: [PATCH 25/29] Update to histos libraries --- histos/MakeHistosInBeam.cxx | 14 ++++----- histos/MakeHistos_e21001.cxx | 55 ++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/histos/MakeHistosInBeam.cxx b/histos/MakeHistosInBeam.cxx index c63e9484..0f2d53b8 100644 --- a/histos/MakeHistosInBeam.cxx +++ b/histos/MakeHistosInBeam.cxx @@ -142,20 +142,20 @@ void MakeHistograms(TRuntimeObjects& obj) { obj.FillHistogram("s800","ata", 200, -100, 100, - s800Sim->GetS800SimHit(0).GetATA()); + s800Sim->GetS800SimHit(0).GetATA()*1000.); obj.FillHistogram("s800","bta", 200, -100, 100, - s800Sim->GetS800SimHit(0).GetBTA()); + s800Sim->GetS800SimHit(0).GetBTA()*1000.); - Double_t xsin, ysin, scatter; + Double_t ata, bta, scatter; - xsin = sin(s800Sim->GetS800SimHit(0).GetATA()/1000.); - ysin = -sin(s800Sim->GetS800SimHit(0).GetBTA()/1000.); - scatter = asin(sqrt(xsin*xsin + ysin*ysin))*1000.; + ata = s800Sim->GetS800SimHit(0).GetATA()*1000.; + bta = s800Sim->GetS800SimHit(0).GetBTA()*1000.; + scatter = sqrt(ata*ata + bta*bta); obj.FillHistogram("s800","scatter", - 4096, 0, 300, + 200, 0, 200, scatter); } diff --git a/histos/MakeHistos_e21001.cxx b/histos/MakeHistos_e21001.cxx index 83cd9e2a..657faf56 100644 --- a/histos/MakeHistos_e21001.cxx +++ b/histos/MakeHistos_e21001.cxx @@ -197,27 +197,27 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ 200, -0.1, 0.1, s800->GetDta()); - Double_t ata = s800->GetAta()*TMath::RadToDeg(); - Double_t bta = s800->GetBta()*TMath::RadToDeg(); + Double_t ata = s800->GetAta()*1000.; + Double_t bta = s800->GetBta()*1000.; histname = Form("ata_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 1200, -6.0, 6.0, + 200, -100, 100, ata); histname = Form("bta_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 1200, -6.0, 6.0, + 200, -100, 100, bta); histname = Form("ata_bta_%s_%s", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 1200, -6.0, 6.0, + 200, -100, 100, bta, - 1200, -6.0, 6.0, + 200, -100, 100, ata); histname = Form("yta_%s_%s", incoming->GetName(), @@ -230,7 +230,7 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ outgoing->GetName()); Double_t scatter = sqrt(ata*ata + bta*bta); obj.FillHistogram(dirname, histname, - 600, 0, 6, + 100, 0, 100, scatter); return true; @@ -238,10 +238,11 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ - TGretina *gretina = obj.GetDetector(); + // TGretina *gretina = obj.GetDetector(); TS800 *s800 = obj.GetDetector(); - if(!gretina || !s800) + // if(!gretina || !s800) + if(!s800) return false; std::string dirname = "S800"; @@ -269,12 +270,16 @@ bool TriggerRegister(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ s800->GetIonChamber().Charge()) ) return false; - histname = "trigger_bit_PID"; + histname = Form("trigger_bit_%s_%s", + incoming_cut->GetName(), + outgoing_cut->GetName()); for(int j=0;j<16;j++) { if(((bits>>j)&0x0001)) obj.FillHistogram(dirname, histname, 20, 0, 20, j); } - histname = "trigger_raw_PID"; + histname = Form("trigger_raw_%s_%s", + incoming_cut->GetName(), + outgoing_cut->GetName()); obj.FillHistogram(dirname, histname, 20, 0, 20, s800->GetTrigger().GetRegistr()); @@ -302,9 +307,10 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, return false; if(!outgoing->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ) + s800->GetIonChamber().Charge()) ) return false; - // s800->GetIonChamber().Charge()) ) + // s800->GetIonChamber().GetSum()) ) + std::string dirname = "gretina"; @@ -482,15 +488,15 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); - Double_t ata = s800->GetAta()*TMath::RadToDeg(); - Double_t bta = s800->GetBta()*TMath::RadToDeg(); + Double_t ata = s800->GetAta()*1000.; + Double_t bta = s800->GetBta()*1000.; Double_t scatter = sqrt(ata*ata + bta*bta); histname = Form("doppler_scatter_%s_%s_t", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 60, 0, 6, + 100, 0, 100, scatter, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, 0)); @@ -499,20 +505,20 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 60, 0, 6, + 100, 0, 100, scatter, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, &track)); - if(scatter < 2.0) { - histname = Form("doppler_s800_0-2deg_%s_%s_t", + if(scatter < 35.0) { + histname = Form("doppler_s800_0-35mrad_%s_%s_t", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, energyNChannels, energyLlim, energyUlim, hit.GetDoppler(beta, &track)); } else { - histname = Form("doppler_s800_2-6deg_%s_%s_t", + histname = Form("doppler_s800_35-100mrad_%s_%s_t", incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, @@ -569,7 +575,8 @@ void MakeHistograms(TRuntimeObjects& obj) { OutgoingS800(obj, s800, outgoing_cut); DTA(obj, incoming_cut, outgoing_cut); - + TriggerRegister(obj, incoming_cut, outgoing_cut); + if(gretina) { HandleGretina(obj, incoming_cut, outgoing_cut, gt_time); @@ -608,9 +615,9 @@ void MakeHistograms(TRuntimeObjects& obj) { incoming_cut->IsInside(s800->GetOBJ_E1Raw_MESY(), s800->GetXF_E1Raw_MESY()) && outgoing_cut->IsInside(s800->GetCorrTOF_OBJ_MESY(), - s800->GetIonChamber().GetSum()) ){ - // s800->GetIonChamber().Charge()) ){ - + s800->GetIonChamber().Charge()) ){ + // s800->GetIonChamber().GetSum()) ){ + // histname = Form("dtime_all_reg%i_%s_%s",j, // incoming_cut->GetName(), // outgoing_cut->GetName()); From b2723953fa22d193276d2869a19aa7db97c91d07 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 8 Aug 2023 08:37:23 -0400 Subject: [PATCH 26/29] e21001 analysis update --- histos/MakeHistosInBeam.cxx | 5 + histos/MakeHistos_UCGretina_e21001.cxx | 541 +++++++++++++++++++++++++ histos/MakeHistos_e21001.cxx | 26 +- 3 files changed, 561 insertions(+), 11 deletions(-) create mode 100644 histos/MakeHistos_UCGretina_e21001.cxx diff --git a/histos/MakeHistosInBeam.cxx b/histos/MakeHistosInBeam.cxx index 0f2d53b8..f50ebf24 100644 --- a/histos/MakeHistosInBeam.cxx +++ b/histos/MakeHistosInBeam.cxx @@ -157,6 +157,11 @@ void MakeHistograms(TRuntimeObjects& obj) { obj.FillHistogram("s800","scatter", 200, 0, 200, scatter); + + obj.FillHistogram("s800","yta", + 400, -20, 20, + s800Sim->GetS800SimHit(0).GetYTA()); + } if(!gretina) diff --git a/histos/MakeHistos_UCGretina_e21001.cxx b/histos/MakeHistos_UCGretina_e21001.cxx new file mode 100644 index 00000000..8f958d2c --- /dev/null +++ b/histos/MakeHistos_UCGretina_e21001.cxx @@ -0,0 +1,541 @@ + +#include "TRuntimeObjects.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "TGretina.h" +#include "TS800.h" +#include "TS800Sim.h" +#include "TGretSim.h" +#include "GValue.h" + + +#include "TChannel.h" +#include "GValue.h" + +#define Q1 15 +#define Q2 7 +#define Q3 8 +#define Q4 16 +#define Q5 9 +#define Q6 14 +#define Q7 17 +#define Q8 6 +#define Q9 19 + +std::map HoleQMap; +std::map LayerMap; + +void InitMap() { + HoleQMap[Q1] = 1; + HoleQMap[Q2] = 2; + HoleQMap[Q3] = 3; + HoleQMap[Q4] = 4; + HoleQMap[Q5] = 5; + HoleQMap[Q6] = 6; + HoleQMap[Q7] = 7; + HoleQMap[Q8] = 8; + HoleQMap[Q9] = 9; + + LayerMap[0] = "alpha"; + LayerMap[1] = "beta"; + LayerMap[2] = "gamma"; + LayerMap[3] = "delta"; + LayerMap[4] = "epsilon"; + LayerMap[5] = "phi"; + +} + +#define INTEGRATION 128.0 + +// extern "C" is needed to prevent name mangling. +// The function signature must be exactly as shown here, +// or else bad things will happen. +extern "C" +void MakeHistograms(TRuntimeObjects& obj) { + InitMap(); + TGretina *gretina = obj.GetDetector(); + // TS800 *s800 = obj.GetDetector(); + TS800Sim *s800Sim = obj.GetDetector(); + TGretSim *gretSim = obj.GetDetector(); + + TList *list = &(obj.GetObjects()); + int numobj = list->GetSize(); + + Int_t energyNChannels = 8192; + Double_t energyLlim = 0.; + Double_t energyUlim = 8192.; + + if(gretSim){ + for(unsigned int x=0; xSize(); x++){ + TGretSimHit hit = gretSim->GetGretinaSimHit(x); + obj.FillHistogram("sim","emitted_energy", + energyNChannels, energyLlim, energyUlim, + hit.GetEn()); + obj.FillHistogram("sim","emitted_theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("sim","emitted_z", + 1000,-50., 50., + hit.GetZ()); + obj.FillHistogram("sim","beta", + 500, 0, 0.5, + hit.GetBeta()); + obj.FillHistogram("sim","beta_z", + 1000,-5,5., + hit.GetZ(), + 300, 0.2, 0.5, + hit.GetBeta()); + } + } + + if(!s800Sim) + return; + + if(s800Sim->Size() > 0){ + // std::cout << "In MakeHistos:" << std::endl; + + // std::cout << " time stamp = " + // << s800Sim->Timestamp() << std::endl; + + // std::cout << " size = " + // << s800Sim->Size() + // << std::endl; + + // std::cout << std::flush; + + Double_t dta = s800Sim->GetS800SimHit(0).GetDTA(); + + // std::cout << " ATA = " + // << s800Sim->GetS800SimHit(0).GetATA() << std::endl; + + // std::cout << " BTA = " + // << s800Sim->GetS800SimHit(0).GetBTA() << std::endl; + + // std::cout << " DTA = " + // << dta << std::endl; + + + obj.FillHistogram("s800","dta", + 200, -0.10, 0.10, + dta); + + // Rough dta acceptance cut + if(dta < -0.06 || dta > 0.06) + return; + + obj.FillHistogram("s800","dta_cut", + 200, -0.10, 0.10, + dta); + + obj.FillHistogram("s800","ata", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetATA()*1000.); + + obj.FillHistogram("s800","bta", + 200, -100, 100, + s800Sim->GetS800SimHit(0).GetBTA()*1000.); + + Double_t ata, bta, scatter; + + ata = s800Sim->GetS800SimHit(0).GetATA()*1000.; + bta = s800Sim->GetS800SimHit(0).GetBTA()*1000.; + scatter = sqrt(ata*ata + bta*bta); + + obj.FillHistogram("s800","scatter", + 200, 0, 200, + scatter); + + obj.FillHistogram("s800","yta", + 400, -20, 20, + s800Sim->GetS800SimHit(0).GetYTA()); + + } + + if(!gretina) + return; + + double beta = GValue::Value("BETA"); + if(std::isnan(beta)) + beta=0.00; + double xoffset = GValue::Value("GRETINA_X_OFFSET"); + if(std::isnan(xoffset)) + xoffset=0.00; + double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + if(std::isnan(yoffset)) + yoffset=0.00; + double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + if(std::isnan(zoffset)) + zoffset=0.00; + TVector3 targetOffset(xoffset,yoffset,zoffset); + + // (optionally define extra beta values in gvalues file) + const Int_t nBetas = 1; + Double_t betas[nBetas] = {beta}; + + Double_t calorimeterEnergy = 0.; + Double_t calorimeterEnergy_gaus = 0.; + std::vector hits; + + for(unsigned int x=0; xSize(); x++){ + + TGretinaHit hit = gretina->GetGretinaHit(x); + + // e21001: this crystal was shut down due to noise issues. + if(hit.GetCrystalId()==78) + continue; + + // Addback preprocessing + if(hit.GetCoreEnergy() > energyLlim && + hit.GetCoreEnergy() < energyUlim){ + + calorimeterEnergy += hit.GetCoreEnergy(); + calorimeterEnergy_gaus += hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + hits.push_back(hit); + + } + + // directory, histogram + obj.FillHistogram("energy", "overview", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy(), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()); + + obj.FillHistogram("energy", "overview_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.), + 100, 0, 100, hit.GetCrystalId()); + + obj.FillHistogram("energy", "energy_gaus", + energyNChannels, energyLlim, energyUlim, + hit.GetCoreEnergy()*gRandom->Gaus(1,1./1000.)); + + for(int i=0; iGaus(1,1./1000.); + for(unsigned int y=x+1; ySize(); y++){ + + TGretinaHit hit2 = gretina->GetGretinaHit(y); + + // e21001: this crystal was shut down due to noise issues. + if(hit2.GetCrystalId()==78) + continue; + + Double_t e2 = hit2.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.); + + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/16, energyLlim, energyUlim/2, e1, + energyNChannels/16, energyLlim, energyUlim/2, e2); + obj.FillHistogram("energy", + Form("gamma_gamma_dop_%.0f_gaus", betas[i]*10000), + energyNChannels/8, energyLlim, energyUlim, e2, + energyNChannels/8, energyLlim, energyUlim, e1); + } + + obj.FillHistogram("energy", + Form("dop_%.0f", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])); + + obj.FillHistogram("energy", + Form("dop_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.)); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("energy", + Form("dop_fw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.)); + } else { + obj.FillHistogram("energy", + Form("dop_bw_%.0f_gaus", betas[i]*10000), + energyNChannels, energyLlim, energyUlim, + hit.GetDoppler(betas[i])*gRandom->Gaus(1,1./1000.)); + } + } + + obj.FillHistogram("position", "theta_vs_phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + if(hit.GetHoleNumber() < 10){ + obj.FillHistogram("position", "theta_vs_phi_fw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } else { + obj.FillHistogram("position", "theta_vs_phi_bw", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg(), + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + } + + } + + // Addback + obj.FillHistogram("addback", "calorimeter", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy); + obj.FillHistogram("addback", "calorimeter_gaus", + energyNChannels, energyLlim, energyUlim, + calorimeterEnergy_gaus); + + while(hits.size() > 0){ + TGretinaHit currentHit = hits.back(); + hits.pop_back(); + + // Find and add all hits in a cluster of adjacent crystals including + // the current hit. + // + // CAUTION: This clustering includes neighbors of neighbors! + std::vector cluster; + cluster.push_back(currentHit); + unsigned int lastClusterSize = 0; + while(lastClusterSize < cluster.size()){ + for(unsigned int i = 0; i < cluster.size(); i++){ + for(unsigned int j = 0; j < hits.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - hits[j].GetCrystalPosition(); + + obj.FillHistogram("position", "crystal_separation", + 1000, 0., 1000., + distance.Mag()); + + if(distance.Mag() < 80.){ // Neighbors + cluster.push_back(hits.back()); + hits.pop_back(); + } + } + } + lastClusterSize = cluster.size(); + } + + // Calculate the total energy deposited in the cluster, + // and count the pairs of neighbors. + Int_t neighbors = 0; + Double_t addbackEnergy = 0.; + Double_t addbackEnergy_gaus = 0.; + TVector3 firstHitPos; + Int_t firstHitHoleNum = -1; + Double_t firstHitEnergy = 0; + for(unsigned int i = 0; i < cluster.size(); i++){ + addbackEnergy += cluster[i].GetCoreEnergy(); + addbackEnergy_gaus += + cluster[i].GetCoreEnergy()*gRandom->Gaus(1,1./1000.); + + // Find the largest IP in the cluster and save its position + // for Doppler correction. + // if(cluster[i].GetSegmentEng(cluster[i].GetFirstIntPoint()) + // > firstHitEnergy){ + if(cluster[i].GetIntAssignEng(0) > firstHitEnergy){ + firstHitHoleNum = cluster[i].GetHoleNumber(); + firstHitPos = cluster[i].GetIntPosition(0) - targetOffset; + firstHitEnergy = cluster[i].GetIntAssignEng(0); + } + + for(unsigned int j = i+1; j < cluster.size(); j++){ + TVector3 distance = cluster[i].GetCrystalPosition() + - cluster[j].GetCrystalPosition(); + if(distance.Mag() < 80.) neighbors++; + } + } + + // Doppler correct the addback energy. + // *** NEED TO ADD S800 TRAJECTORY *** + + Double_t dopplerABEnergy[nBetas] = {0.}; + Double_t dopplerABEnergy_gaus[nBetas] = {0.}; + for(int b=0; bGetSize()) + list->Sort(); + +} diff --git a/histos/MakeHistos_e21001.cxx b/histos/MakeHistos_e21001.cxx index 657faf56..74a37537 100644 --- a/histos/MakeHistos_e21001.cxx +++ b/histos/MakeHistos_e21001.cxx @@ -223,7 +223,7 @@ bool DTA(TRuntimeObjects &obj, GCutG *incoming, GCutG *outgoing){ incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, - 200, -20, 20, + 400, -20, 20, s800->GetYta()); histname = Form("scatter_%s_%s", incoming->GetName(), @@ -321,16 +321,16 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, double beta = GValue::Value("BETA"); if(std::isnan(beta)) beta=0.00; - double xoffset = GValue::Value("GRETINA_X_OFFSET"); - if(std::isnan(xoffset)) - xoffset=0.00; - double yoffset = GValue::Value("GRETINA_Y_OFFSET"); - if(std::isnan(yoffset)) - yoffset=0.00; - double zoffset = GValue::Value("GRETINA_Z_OFFSET"); - if(std::isnan(zoffset)) - zoffset=0.00; - TVector3 targetOffset(xoffset, yoffset, zoffset); + // double xoffset = GValue::Value("GRETINA_X_OFFSET"); + // if(std::isnan(xoffset)) + // xoffset=0.00; + // double yoffset = GValue::Value("GRETINA_Y_OFFSET"); + // if(std::isnan(yoffset)) + // yoffset=0.00; + // double zoffset = GValue::Value("GRETINA_Z_OFFSET"); + // if(std::isnan(zoffset)) + // zoffset=0.00; + // TVector3 targetOffset(xoffset, yoffset, zoffset); for(int x=0;xSize();x++) { TGretinaHit hit = gretina->GetGretinaHit(x); @@ -351,6 +351,10 @@ bool HandleGretina(TRuntimeObjects &obj,GCutG *incoming, 120, 0, 120, hit.GetCrystalId()); + // e21001: this crystal was shut down due to noise issues. + if(hit.GetCrystalId()==78) + continue; + histname = Form("doppler_%s_%s",incoming->GetName(), outgoing->GetName()); obj.FillHistogram(dirname, histname, energyNChannels, energyLlim, energyUlim, From 1df03a3d3b1af80f60321d876bec5dc316b9f593 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Sat, 21 Oct 2023 21:03:54 -0400 Subject: [PATCH 27/29] Added Track() method to TS800SimHit returning a vector along the beam direction. --- include/TS800SimHit.h | 3 ++- libraries/TDetSystems/TS800Sim/TS800SimHit.cxx | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/TS800SimHit.h b/include/TS800SimHit.h index 6086142f..0c9f2cb1 100644 --- a/include/TS800SimHit.h +++ b/include/TS800SimHit.h @@ -31,7 +31,8 @@ class TS800SimHit : public TDetectorHit { float GetBTA() const { return fBTA; } float GetDTA() const { return fDTA; } float GetYTA() const { return fYTA; } - + TVector3 Track(); + double fATA; double fBTA; double fDTA; diff --git a/libraries/TDetSystems/TS800Sim/TS800SimHit.cxx b/libraries/TDetSystems/TS800Sim/TS800SimHit.cxx index 610f2f7a..34ed5dbe 100644 --- a/libraries/TDetSystems/TS800Sim/TS800SimHit.cxx +++ b/libraries/TDetSystems/TS800Sim/TS800SimHit.cxx @@ -28,6 +28,15 @@ const char *TS800SimHit::GetName() const { return name.c_str(); } +TVector3 TS800SimHit::Track(){ + double ata = TMath::Sin(GetATA()); + double bta = TMath::Sin(GetBTA()); + + TVector3 track(ata,-bta,sqrt(1-ata*ata-bta*bta)); + + return track; +} + void TS800SimHit::Print(Option_t *opt) const { std::cout << "TS800SimHit:" << std::endl; From 11ddeb1a049c8327e56263b38d1f3debe0379c28 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Tue, 16 Jan 2024 07:24:21 -0500 Subject: [PATCH 28/29] Update MakeHistosInBeam.cxx to include polarization spectra. --- histos/MakeHistosInBeam.cxx | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/histos/MakeHistosInBeam.cxx b/histos/MakeHistosInBeam.cxx index f50ebf24..117facd3 100644 --- a/histos/MakeHistosInBeam.cxx +++ b/histos/MakeHistosInBeam.cxx @@ -265,6 +265,14 @@ void MakeHistograms(TRuntimeObjects& obj) { } } + obj.FillHistogram("position", "theta", + 180, 0., 180., + hit.GetTheta()*TMath::RadToDeg()); + + obj.FillHistogram("position", "phi", + 360, 0., 360., + hit.GetPhi()*TMath::RadToDeg()); + obj.FillHistogram("position", "theta_vs_phi", 360, 0., 360., hit.GetPhi()*TMath::RadToDeg(), @@ -284,6 +292,51 @@ void MakeHistograms(TRuntimeObjects& obj) { 180, 0., 180., hit.GetTheta()*TMath::RadToDeg()); } + + // Polarization + + // r1, r2 from two highest-energy IPs + Int_t i1 = -1; + Int_t i2 = -1; + Double_t e1 = 0; + Double_t e2 = 0; + Int_t xtal = hit.GetCrystalId(); + for(Int_t i = 0; i < hit.Size(); i++){ + Double_t e = hit.GetInteractionPoint(i).GetDecompE(); + if(e > e1){ + i1 = i; + e1 = e; + } + if(e < e1 && e > e2){ + i2 = i; + e2 = e; + } + } + + if(gretSim->Size() > 0 + && gretSim->GetGretinaSimHit(0).IsFEP() + && i1 >= 0 && i2 >= 0){ + + TVector3 pos1 = hit.GetInteractionPoint(i1).GetLocalPosition(); + TVector3 r1 = TGretina::CrystalToGlobal(xtal, + pos1.X(), pos1.Y(), pos1.Z()); + TVector3 pos2 = hit.GetInteractionPoint(i2).GetLocalPosition(); + TVector3 r2 = TGretina::CrystalToGlobal(xtal, + pos2.X(), pos2.Y(), pos2.Z()); + r2 = r2 - r1; + TVector3 zprime = r1.Unit(); + TVector3 yprime = zprime.Cross( TVector3(0, 0, 1) ); + yprime = yprime.Unit(); + TVector3 xprime = yprime.Cross(zprime); + + Double_t xi = TMath::ATan2(r2.Dot(yprime), r2.Dot(xprime)); + + obj.FillHistogram("polarization", "xi", + 360, -180., 180., + xi*TMath::RadToDeg()); + + } + } From 39ef6c7fd604c77b0b4e420b10054024832bfa23 Mon Sep 17 00:00:00 2001 From: Lew Riley Date: Sat, 25 May 2024 15:33:21 -0400 Subject: [PATCH 29/29] update to histogram library for simulations --- histos/MakeHistosInBeam.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/histos/MakeHistosInBeam.cxx b/histos/MakeHistosInBeam.cxx index 117facd3..2d9621c4 100644 --- a/histos/MakeHistosInBeam.cxx +++ b/histos/MakeHistosInBeam.cxx @@ -88,13 +88,13 @@ void MakeHistograms(TRuntimeObjects& obj) { 360, 0., 360., hit.GetPhi()*TMath::RadToDeg()); obj.FillHistogram("sim","emitted_z", - 1000,-50., 50., + 600,-30, 30, hit.GetZ()); obj.FillHistogram("sim","beta", 500, 0, 0.5, hit.GetBeta()); obj.FillHistogram("sim","beta_z", - 1000,-5,5., + 600, -30, 30, hit.GetZ(), 300, 0.2, 0.5, hit.GetBeta());