#include "fQEventManager.h" #include #include #include #include #include #include #include #include #include "fiTQun_shared.h" #ifndef NOSKLIBRARIES #include "skheadC.h" #include "skparmC.h" #include "skbadcC.h" #include "sktqC.h" #else #include "WCSimWrap.h" #endif // In g77, "real*4" functions return double //#ifdef FQ_G77 #if defined(f2cFortran)&&!defined(gFortran) #define FORTRETURN_FLOAT double #else #define FORTRETURN_FLOAT float #endif extern"C" { #ifndef NOSKLIBRARIES void fortinit_(char*, char*, int, int); int fortread_(); void skclosef_(int*); void skread_(int *); void set_timing_gate_nsec2_(float *, float *); void kzmnum_(int *, int *); void skrdsub_(int *, int *, int *); FORTRETURN_FLOAT diftevsk_(int *); void savetqbanks_(); void restoretqbanks_(); int getfakepi0_(int *, int *, int *); #endif } fQEventManager* fQEventManager::staticthis = NULL; char fQEventManager::ofname[1024]; fQEventManager::fQEventManager(){ fQuiet=1; flgHist=0;// Don't output tHit histograms // flgHist=1; if (!(fiTQun_shared::Get()->AreYouReady())) { std::cout << "fQEventManager::fQEventManager: fiTQun_shared not initialized!" << std::endl; exit(-1); } flgData = false; PMTGainCorr = 1.; WAttenLCorr = 1.; #ifndef NOSKLIBRARIES SKConsts_tvar = new SKTVarConsts(fiTQun_shared::Get()->GetSKVer()); #endif fNPMT = fiTQun_shared::Get()->MAXNPMT(); PMT_iHit = new int[fNPMT]; PMT_q = new double[fNPMT]; PMT_t = new double[fNPMT]; PMTall_nhit=0; PMTall_icab = new int[30*fNPMT]; PMTall_q = new double[30*fNPMT]; PMTall_t = new double[30*fNPMT]; MinMax_PMTall_t[0]=0.; MinMax_PMTall_t[1]=0.; nEvt=0; } fQEventManager::~fQEventManager(){ delete[] PMT_iHit; delete[] PMT_q; delete[] PMT_t; delete[] PMTall_icab; delete[] PMTall_q; delete[] PMTall_t; std::cout << "Destructing fQEventManager!!" << std::endl; } int fQEventManager::SetGate(float t_Start, float t_End, bool flgShiftGate, bool flgMaskDeadTimePMT){ for (int icab=0; icabPMTtype[icab]<0) PMT_iHit[icab]=-1;//ignore missing PMTs } if (flgMaskDeadTimePMT) { std::cout << "fQEventManager::SetGate: Masking dead-time PMTs!" << std::endl; for (int ih=0; iht_Start-1000. && PMTall_t[ih]GetSKVer()<=3) {// ATM for (int icab=0; icab=t_Start && PMTall_t[ih]=t_Start && PMT_t[icab]NSubEvt(); if (nsubev==0)nsubev=1; for (int isub=0; isubSubEvt(isub); double aSubToffs = wc->GetTOffset(isub); for (int ich = 0; ichGetNcherenkovdigihits(); ich++){ WCSimRootCherenkovDigiHit *cDigiHit = dynamic_cast( evt->GetCherenkovDigiHits()->At(ich) ); int icab = cDigiHit->GetTubeId() - 1; //convert to C++ index double tmp_t = cDigiHit->GetT()+aSubToffs; if (!(tmp_t>=t_Start && tmp_tGetQ(); PMT_t[icab] = tmp_t; PMT_iHit[icab]=1;//hit! nhitPMT++; } } #endif return nhitPMT; } void fQEventManager::LoadEvent() { flgData = false; PMTGainCorr = 1.; WAttenLCorr = 1.; #ifndef NOSKLIBRARIES int iRun=skhead_.nrunsk;//Run number int iSub=skhead_.nsubsk;//Run number int iEv=skhead_.nevsk;//Run number int fpi0nrun, fpi0nsub, fpi0nev; int iret = getfakepi0_(&fpi0nrun,&fpi0nsub,&fpi0nev); if (iret) {// contains FAKEPI0 bank std::cout << "Detected FAKEPI0 bank!" << std::endl; iRun = fpi0nrun; iSub = fpi0nsub; iEv = fpi0nev; } std::cout << Form("Loading event: Run %d, Sub %d, Event %d",iRun,iSub,iEv) << std::endl; if (skhead_.mdrnsk!=0 && skhead_.mdrnsk!=999999) {// Data flgData = true; std::cout << " Obtaining detector parametors for Run" << iRun << std::endl; PMTGainCorr = SKConsts_tvar->GetGainFact(iRun); std::cout << " PMT gain correction factor: " << PMTGainCorr << std::endl; WAttenLCorr = SKConsts_tvar->GetAttenLFact(iRun); std::cout << " Attenuation length correction factor: " << WAttenLCorr << std::endl; } else flgData = false;// MC #else #endif GetAllHits(); nEvt++; } void fQEventManager::GetAllHits() { TFile *fHist=NULL; TH1F *h_thit_all, *h_thit_sub; if (flgHist) { if (nEvt>0) { fHist = new TFile(Form("%s_tHit.root",ofname),"UPDATE"); } else { fHist = new TFile(Form("%s_tHit.root",ofname),"RECREATE"); } h_thit_all = new TH1F(Form("h_thit_%d_all",nEvt),Form("Raw hit time, iEvt=%d",nEvt),10000,-50000,50000); } PMTall_nhit=0; n_Gate=0; MinMax_PMTall_t[0]=1e300; MinMax_PMTall_t[1]=-1e300; #ifndef NOSKLIBRARIES if (fiTQun_shared::Get()->GetSKVer()<=3) {// ATM int parent_48bitClock[3]; int LUN=10; int ierr; int nsub_ATM,isub_ATM; kzmnum_(&nsub_ATM,&isub_ATM);// Get total number of subevents if (isub_ATM!=1) std::cout << Form("fQEventManager::GetAllHits: isub_ATM!=1, isub=%d",isub_ATM) << std::endl; std::cout << Form("ATM: Reading %d subevents...",nsub_ATM) << std::endl; for (isub_ATM=0; isub_ATM=100) { std::cout << "n_Gate>=100!" << std::endl; continue; // exit(-1); } t_Gate[n_Gate][0]=1e100; t_Gate[n_Gate][1]=-1e100; for (int ih=0; ihqThresh)) continue; if (fiTQun_shared::Get()->PMTtype[icab]==-1) continue;//ignore missing PMTs if (combad_.ibad[icab]!=0) continue;//ignore bad channels PMTall_icab[PMTall_nhit]=icab; PMTall_q[PMTall_nhit]=q_tmp; PMTall_t[PMTall_nhit]=t_tmp; if (flgHist) h_thit_sub->Fill(PMTall_t[PMTall_nhit]); if (PMTall_t[PMTall_nhit]MinMax_PMTall_t[1]) MinMax_PMTall_t[1]=PMTall_t[PMTall_nhit]; if (PMTall_t[PMTall_nhit]t_Gate[n_Gate][1]) t_Gate[n_Gate][1]=PMTall_t[PMTall_nhit]; PMTall_nhit++; } if (n_Gate>0) { if (!(t_Gate[n_Gate][0]>t_Gate[n_Gate-1][1])) { t_Gate[n_Gate][0]=t_Gate[n_Gate-1][1]; } } std::cout << Form(", Gate=[%.1f,%.1f]",t_Gate[n_Gate][0],t_Gate[n_Gate][1]); if (t_Gate[n_Gate][0]Write(); } } std::cout << Form("n_Gate=%d",n_Gate) << std::endl; isub_ATM=0; skrdsub_(&LUN,&isub_ATM,&ierr);//restore } else {// QBEE for (int i=0; i bihtiflz(sktqz_.ihtiflz[i]); if (!bihtiflz.test(1)) continue;// Only consider hits within 40us gate int icab = sktqz_.icabiz[i]-1;// C++ indexing if (!(icabqThresh)) continue; if (fiTQun_shared::Get()->PMTtype[icab]==-1) continue;//ignore missing PMTs if (combad_.ibad[icab]!=0) continue;//ignore bad channels PMTall_icab[PMTall_nhit]=icab; PMTall_q[PMTall_nhit]=sktqz_.qiskz[i]; PMTall_t[PMTall_nhit]=sktqz_.tiskz[i]; if (PMTall_t[PMTall_nhit]MinMax_PMTall_t[1]) MinMax_PMTall_t[1]=PMTall_t[PMTall_nhit]; PMTall_nhit++; } } #else WCSimWrap * wc = WCSimWrap::Get(); // get wcsim information if (!fQuiet) std::cout<<" nsubev="<NSubEvt()<NSubEvt(); isubev++){ WCSimRootTrigger * evt = wc->SubEvt(isubev); double aSubToffs = wc->GetTOffset(isubev); if (!fQuiet) std::cout<<" SubEv"< qThresh="<GetNcherenkovdigihits(); i++) { WCSimRootCherenkovDigiHit *cDigiHit = dynamic_cast ( evt->GetCherenkovDigiHits()->At(i) ); if (!fQuiet) std::cout<<" digit"<GetQ()<GetT()+aSubToffs<800.){ // if (!fQuiet) std::cout<<" WARNING! T-offs=" // <GetT()+aSubToffs<GetTubeId()-1;//convert to c++ index if (icab>=fNPMT){//ID PMT if (!fQuiet) std::cout<<" WARNING! icab>fNPMT =" <GetQ()>qThresh)){ // if (!fQuiet) std::cout<<" WARNING! Q<=qThresh =" // <GetQ()<PMTtype[icab]==-1){ if (!fQuiet) std::cout<<" WARNING! PMTtype["<