23 #include <JANA/JApplication.h>
24 #include <JANA/JFactory.h>
25 #include <TDirectory.h>
93 const double Ebw_PS = 0.05;
95 const double Ebh_PS = 13.0;
96 const int NEb_PS = int((Ebh_PS-Ebl_PS)/Ebw_PS);
97 const double Ebw_TAG = 0.1;
98 const double Ebl_TAG = 2.5;
99 const double Ebh_TAG = 10.5;
100 const int NEb_TAG = int((Ebh_TAG-Ebl_TAG)/Ebw_TAG);
102 const double Tbl_TAG = -100.0;
103 const double Tbh_TAG = 100.0;
104 const int NTb_TAG = 200;
106 const int NEdb = 200;
const double Edbl = -1.0;
const double Edbh = 1.0;
111 dRandom =
new TRandom3(0);
114 TDirectory *psFluxDir = gDirectory->mkdir(
"PS_flux");
117 psflux_num_events =
new TH1I(
"psflux_num_events",
"PS flux number of events",3,0.5,3.5);
118 hFiducialTime =
new TH1F(
"fiducialTime",
"Fiducial time", 1, 0, 1);
119 hBeamCurrentTime =
new TH1I(
"beamCurrentTime",
"; Event time from DBeamCurrent for all events (seconds)", 1000, 0, 500);
120 hBeamCurrentTimeFiducial =
new TH1I(
"beamCurrentTimeFiducial",
"; Event time from DBeamCurrent for fiducial events (seconds)", 1000, 0, 500);
123 gDirectory->mkdir(
"PSC_PS")->cd();
124 hPS_E =
new TH1I(
"PS_E",
"PS pair energy; PS pair energy [GeV]",NEb_PS,Ebl_PS,Ebh_PS);
125 hPS_tdiffVsE =
new TH2I(
"PS_tdiffVsE",
"PS pair time difference vs. PS pair energy;PS pair energy [GeV];PS pair time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,200,-10.0,10.0);
126 hPSC_tdiffVsE =
new TH2I(
"PSC_tdiffVsE",
"PSC pair time difference vs. PS pair energy;PS pair energy [GeV];PSC pair time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,200,-10.0,10.0);
127 hPSPSC_tdiffVsE =
new TH2I(
"PSPSC_tdiffVsE",
"PSC/PS pair time difference vs. PS pair energy;PS pair energy [GeV];PSC/PS pair time difference of differences [ns]",NEb_PS,Ebl_PS,Ebh_PS,200,-10.0,10.0);
128 hPS_EVsEuni =
new TH2I(
"PS_EVsEuni",
"PS pair energy vs. uniform pair energy; PS uniform pair energy [GeV]; PS pair energy [GeV]",NEb_PS,Ebl_PS,Ebh_PS,NEb_PS,Ebl_PS,Ebh_PS);
131 gDirectory->mkdir(
"PSC_PS_TAGH")->cd();
132 hPSTAGH_tdiffVsEdiff =
new TH2I(
"PSTAGH_tdiffVsEdiff",
"PS pair - TAGH: PS-TAGH time difference vs. PS-TAGH energy difference;E(PS) - E(TAGH) [GeV];PSC/TAGH time difference [ns]",NEdb,Edbl,Edbh,NTb_TAG,Tbl_TAG,Tbh_TAG);
133 hPSTAGH_tdiffVsEtagh =
new TH2I(
"PSTAGH_tdiffVsEtagh",
"PSC/TAGH time difference vs. TAGH energy; TAGH energy [GeV];PSC/TAGH time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,NTb_TAG,Tbl_TAG,Tbh_TAG);
134 hPSTAGH_tdiffVsCounter =
new TH2I(
"PSTAGH_tdiffVsCounter",
"PSC/TAGH time difference vs. TAGH Counter; TAGH Counter;PSC/TAGH time difference [ns]",
NC_TAGH,0.5,0.5+
NC_TAGH,NTb_TAG,Tbl_TAG,Tbh_TAG);
135 hPSTAGH_EdiffVsTAGHCounterID =
new TH2I(
"PSTAGH_EdiffVsTAGHCounterID",
"PS pair - TAGH: PS-TAGH energy difference vs. TAGH counter ID;TAGH counter ID;E(PS) - E(TAGH) [GeV]",
NC_TAGH,0.5,0.5+
NC_TAGH,NEdb,Edbl,Edbh);
136 hPSTAGH_EdiffVsEtagh =
new TH2I(
"PSTAGH_EdiffVsEtagh",
"PS pair - TAGH: PS-TAGH energy difference vs. TAGH energy;TAGH energy [GeV];E(PS) - E(TAGH) [GeV]",NEb_TAG,Ebl_TAG,Ebh_TAG,NEdb,Edbl,Edbh);
139 gDirectory->mkdir(
"PSC_PS_TAGM")->cd();
140 hPSTAGM_tdiffVsEdiff =
new TH2I(
"PSTAGM_tdiffVsEdiff",
"PS pair - TAGM: PS-TAGM time difference vs. PS-TAGM energy difference;E(PS) - E(TAGM) [GeV];PSC/TAGM time difference [ns]",NEdb,Edbl,Edbh,NTb_TAG,Tbl_TAG,Tbh_TAG);
141 hPSTAGM_tdiffVsEtagm =
new TH2I(
"PSTAGM_tdiffVsEtagm",
"PSC/TAGM time difference vs. TAGM energy; TAGM energy [GeV];PSC/TAGM time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,NTb_TAG,Tbl_TAG,Tbh_TAG);
142 hPSTAGM_tdiffVsColumn =
new TH2I(
"PSTAGM_tdiffVsColumn",
"PSC/TAGM time difference vs. TAGM Column; TAGM Column;PSC/TAGM time difference [ns]",
NC_TAGM,0.5,0.5+
NC_TAGM,NTb_TAG,Tbl_TAG,Tbh_TAG);
143 hPSTAGM_EdiffVsTAGMColumn =
new TH2I(
"PSTAGM_EdiffVsTAGMColumn",
"PS pair - TAGM: PS-TAGM energy difference vs. TAGM column;TAGM column;E(PS) - E(TAGM) [GeV]",
NC_TAGM,0.5,0.5+
NC_TAGM,NEdb,Edbl,Edbh);
144 hPSTAGM_EdiffVsEtagm =
new TH2I(
"PSTAGM_EdiffVsEtagm",
"PS pair - TAGM: PS-TAGM energy difference vs. TAGM energy;TAGM energy [GeV];E(PS) - E(TAGM) [GeV]",NEb_PS,Ebl_PS,Ebh_PS,NEdb,Edbl,Edbh);
146 gDirectory->mkdir(
"PSC_PS_TAG")->cd();
147 hPSTAG_tdiffVsEtag =
new TH2I(
"PSTAG_tdiffVsEtag",
"PSC/TAG time difference vs. TAG energy; TAG energy [GeV];PSC/TAG time difference [ns]",NEb_PS,Ebl_PS,Ebh_PS,NTb_TAG,Tbl_TAG,Tbh_TAG);
149 gDirectory->cd(
"../");
151 double locNumTAGHhits = 500;
152 double locNumTAGMhits = 200;
170 locTreeBranchRegister.
Register_Single<Double_t>(
"PSPairEnergyUniform");
183 dTreeInterface->Create_Branches(locTreeBranchRegister);
196 dBeamCurrentFactory->init();
197 dBeamCurrentFactory->brun(eventLoop, runnumber);
200 vector<const DPSGeometry*> psGeomVect;
201 eventLoop->Get(psGeomVect);
202 if (psGeomVect.size() < 1)
203 return OBJECT_NOT_AVAILABLE;
207 double wl_min=0.05,wr_min = 0.05;
208 double Ebw_PS = wl_min + wr_min;
211 double range = fabs(Ebh_PS-Ebl_PS);
212 int NEb_PS = range/Ebw_PS-int(range/Ebw_PS) < 0.5 ? int(range/Ebw_PS) : int(range/Ebw_PS) + 1;
213 double Elows_PS[NEb_PS+1];
214 for (
int i=0;i<NEb_PS+1;i++) {
215 Elows_PS[i] = Ebl_PS + i*
Ebw_PS;
218 vector<const DTAGHGeometry*> taghGeomVect;
219 eventLoop->Get(taghGeomVect);
220 if (taghGeomVect.size() < 1)
221 return OBJECT_NOT_AVAILABLE;
226 Elows_TAGH[i] = taghGeom.
getElow(NC_TAGH-i);
231 vector<const DTAGMGeometry*> tagmGeomVect;
232 eventLoop->Get(tagmGeomVect);
233 if (tagmGeomVect.size() < 1)
234 return OBJECT_NOT_AVAILABLE;
239 Elows_TAGM[i] = tagmGeom.
getElow(NC_TAGM-i);
244 const int NEdiff = 200;
245 double EdiffLows[NEdiff+1];
246 for (
int i=0;i<NEdiff+1;i++) {
247 EdiffLows[i] = -1.0 + i*0.01;
249 const int NTb_PS = 200;
250 double Tlows_PS[NTb_PS+1];
251 for (
int i=0;i<=NTb_PS;i++) {
252 Tlows_PS[i] = -10.0+i*0.1;
255 vector<double> locBeamPeriodVector;
256 eventLoop->GetCalib(
"PHOTON_BEAM/RF/beam_period", locBeamPeriodVector);
257 dBeamBunchPeriod = locBeamPeriodVector[0];
260 japp->RootFillLock(
this);
271 japp->RootFillUnLock(
this);
288 vector<const DPSCPair*> cpairs;
291 vector<const DPSPair*> fpairs;
295 vector<const DBeamPhoton*> beamPhotons;
296 loop->Get(beamPhotons);
299 vector<const DPSGeometry*> psGeomVect;
300 loop->Get(psGeomVect);
301 if (psGeomVect.size() < 1)
302 return OBJECT_NOT_AVAILABLE;
306 vector<const DBeamCurrent*> beamCurrent;
307 loop->Get(beamCurrent);
310 if(!beamCurrent.empty()) {
312 t_start = beamCurrent[0]->t;
314 t_end = beamCurrent[0]->t;
319 japp->RootFillLock(
this);
321 if(!beamCurrent.empty()) {
323 if(beamCurrent[0]->is_fiducial) {
330 if (cpairs.size()>=1) {
332 const DPSCHit* clhit = cpairs[0]->ee.first;
333 const DPSCHit* crhit = cpairs[0]->ee.second;
334 double PSC_tdiff = clhit->
t-crhit->
t;
335 if (fabs(PSC_tdiff) > 6.) {
japp->RootFillUnLock(
this);
return NOERROR;}
339 if (fpairs.size()>=1) {
346 if(flhit->
column < geomModuleColumn[clhit->
module-1][0] || flhit->
column > geomModuleColumn[clhit->
module-1][1]) {
japp->RootFillUnLock(
this);
return NOERROR;}
347 if(frhit->
column < geomModuleColumn[crhit->
module-1][0] || frhit->
column > geomModuleColumn[crhit->
module-1][1]) {
japp->RootFillUnLock(
this);
return NOERROR;}
357 double E_pair = flhit->
E+frhit->
E;
358 double E_pair_uni = E_left_rndm+E_right_rndm;
359 double PS_tdiff = flhit->
t-frhit->
t;
365 if(fabs(PS_tdiff) < 0.5*dBeamBunchPeriod && fabs(PSC_tdiff) < 0.5*dBeamBunchPeriod)
369 dTreeFillData.Fill_Single<ULong64_t>(
"EventNumber", eventnumber);
370 if(!beamCurrent.empty())
371 dTreeFillData.Fill_Single<Bool_t>(
"IsFiducial", beamCurrent[0]->is_fiducial);
372 dTreeFillData.Fill_Single<Double_t>(
"PSCtimeL", clhit->
t);
373 dTreeFillData.Fill_Single<Double_t>(
"PSCtimeR", crhit->
t);
374 dTreeFillData.Fill_Single<Double_t>(
"PStimeL", flhit->
t);
375 dTreeFillData.Fill_Single<Double_t>(
"PStimeR", frhit->
t);
376 dTreeFillData.Fill_Single<Double_t>(
"PSenergyL", flhit->
E);
377 dTreeFillData.Fill_Single<Double_t>(
"PSenergyR", frhit->
E);
378 dTreeFillData.Fill_Single<Double_t>(
"PSPairEnergy", E_pair);
379 dTreeFillData.Fill_Single<Double_t>(
"PSPairEnergyUniform", E_pair_uni);
387 for(
unsigned int i=0; i < beamPhotons.size(); i++) {
389 beamPhotons[i]->GetSingle(tag);
393 double Ediff = E_pair-tag->
E;
394 double tdiff_left = clhit->
t-tag->
t;
397 if(fabs(tdiff_left) > 10.*dBeamBunchPeriod || fabs(Ediff) > 4.0)
400 dTreeFillData.Fill_Array<Double_t>(
"TAGHenergy", tag->
E, itagh);
401 dTreeFillData.Fill_Array<Double_t>(
"TAGHtime", tag->
t, itagh);
402 dTreeFillData.Fill_Array<Int_t>(
"TAGHcounter", tag->
counter_id, itagh);
408 if (Ediff < -0.45 || Ediff > 0.15)
415 for(
unsigned int i=0; i < beamPhotons.size(); i++) {
417 beamPhotons[i]->GetSingle(tag);
421 double Ediff = E_pair-tag->
E;
422 double tdiff_left = clhit->
t-tag->
t;
425 if(fabs(tdiff_left) > 10.*dBeamBunchPeriod || fabs(Ediff) > 4.0)
428 dTreeFillData.Fill_Array<Double_t>(
"TAGMenergy", tag->
E, itagm);
429 dTreeFillData.Fill_Array<Double_t>(
"TAGMtime", tag->
t, itagm);
430 dTreeFillData.Fill_Array<Int_t>(
"TAGMcolumn", tag->
column, itagm);
436 if (Ediff < -0.25 || Ediff > 0.15)
444 dTreeFillData.Fill_Single<Int_t>(
"NumTAGMhits", locTAGMhits);
445 dTreeFillData.Fill_Single<Int_t>(
"NumTAGHhits", locTAGHhits);
447 dTreeInterface->Fill(dTreeFillData);
451 japp->RootFillUnLock(
this);
466 double finalFiducialTime = dBeamCurrentFactory->IntegratedFiducialTime(t_start, t_end);
480 delete dTreeInterface;
static TH2I * hPSTAGM_tdiffVsColumn
double getElow(unsigned int counter) const
static TH2I * hPSTAG_tdiffVsEtag
static TH1I * hBeamCurrentTimeFiducial
JEventProcessor_PS_flux()
void Register_Single(string locBranchName)
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TH2I * hPSTAGH_tdiffVsEdiff
static TH2I * hPSC_tdiffVsE
double getEhigh(int arm, int column) const
static TH2I * hPSTAGM_EdiffVsEtagm
double getEhigh(unsigned int column) const
static TH2I * hPS_EVsEuni
static TH2I * hPS_tdiffVsE
jerror_t init(void)
Called once at program start.
static TH1F * hFiducialTime
jerror_t fini(void)
Called after last event of last event source has been processed.
static DTreeInterface * Create_DTreeInterface(string locTreeName, string locFileName)
static TH2I * hPSTAGM_EdiffVsTAGMColumn
static TH2I * hPSTAGM_tdiffVsEtagm
static TH1I * psflux_num_events
void Register_FundamentalArray(string locBranchName, string locArraySizeName, size_t locInitialArraySize=10)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static const int NUM_COARSE_COLUMNS
double getElow(unsigned int column) const
static TH2I * hPSTAGH_EdiffVsTAGHCounterID
double getEhigh(unsigned int counter) const
static TH2I * hPSTAGM_tdiffVsEdiff
static const unsigned int kColumnCount
static TH1I * hBeamCurrentTime
~JEventProcessor_PS_flux()
static const int NUM_FINE_COLUMNS
static TH2I * hPSPSC_tdiffVsE
static const unsigned int kCounterCount
static TH2I * hPSTAGH_tdiffVsEtagh
static TH2I * hPSTAGH_EdiffVsEtagh
static TH2I * hPSTAGH_tdiffVsCounter
static thread_local DTreeFillData dTreeFillData
double getElow(int arm, int column) const