// $Id$ // // Created June 22, 2005 David Lawrence // The following flag can be used to switch from the classic mode where // the event loop is implemented in main() to a JANA based event-loop. // NOTE: for consistency, one should set the value of #define JANA_ENABLED // in smear.cc to the same value! #define USE_JANA 1 #include #include using namespace std; #include #include #include #include #include #include #if USE_JANA #include #include "MyProcessor.h" #include "JFactoryGenerator_ThreadCancelHandler.h" #include //#include #include #endif #include "units.h" #include "HDDM/hddm_s.hpp" void Smear(hddm_s::HDDM *record); void ParseCommandLineArguments(int narg, char* argv[]); void Usage(void); extern void SetSeeds(const char *vals); #if ! USE_JANA void ctrlCHandleMCSmear(int x); #endif char *INFILENAME = NULL; char *OUTFILENAME = NULL; int QUIT = 0; bool ADD_NOISE = false; bool SMEAR_HITS = true; bool SMEAR_BCAL = true; bool FDC_ELOSS_OFF = false; bool IGNORE_SEEDS = false; // setup response parameters double BCAL_DARKRATE_GHZ = 0.;// 0.0176 (from calibDB BCAL/bcal_parms) for 4x4 array double BCAL_SIGMA_SIG_RELATIVE = 0.;// 0.105 (from calibDB BCAL/bcal_parms) double BCAL_SIGMA_PED_RELATIVE = 0.;// 0.139 (from calibDB BCAL/bcal_parms) double BCAL_SIPM_GAIN_VARIATION = 0.;// 0.04 (from calibDB BCAL/bcal_parms) double BCAL_XTALK_FRACT = 0.;// 0.157 (from calibDB BCAL/bcal_parms) double BCAL_INTWINDOW_NS = 0.;// 100 (from calibDB BCAL/bcal_parms) double BCAL_DEVICEPDE = 0.;// 0.21 (from calibDB BCAL/bcal_parms) double BCAL_SAMPLING_FRACT = 0.;// 0.095 (from calibDB BCAL/bcal_parms) double BCAL_PHOTONSPERSIDEPERMEV_INFIBER = 0.0;// 75 (from calibDB BCAL/bcal_parms) double BCAL_AVG_DARK_DIGI_VALS_PER_EVENT = 0.0; // 240 used to set thresholds double BCAL_SAMPLINGCOEFA = 0.0; // 0.042 (from calibDB BCAL/bcal_parms) double BCAL_SAMPLINGCOEFB = 0.0; // 0.013 (from calibDB BCAL/bcal_parms) double BCAL_TIMEDIFFCOEFA = 0.0; // 0.07 * sqrt( 2 ) (from calibDB BCAL/bcal_parms) double BCAL_TIMEDIFFCOEFB = 0.0; // 0.00 * sqrt( 2 ) (from calibDB BCAL/bcal_parms) double BCAL_TDC_THRESHOLD = 44.7; // mV double BCAL_ADC_THRESHOLD = 4.0; // mV double BCAL_FADC_TIME_RESOLUTION = 4.0/sqrt(12.0); // ns // BCAL flags bool NO_T_SMEAR = false; bool NO_DARK_PULSES = false; bool FULL_DARK_HITS = false; bool NO_SAMPLING_FLUCTUATIONS = false; bool NO_SAMPLING_FLOOR_TERM = false; bool NO_POISSON_STATISTICS = false; bool NO_TIME_JITTER = false; bool BCAL_DEBUG_HISTS = false; double FTOF_BAR_THRESHOLD = 0.0; double STC_PADDLE_THRESHOLD = 0.0; double PSC_THRESHOLD = 0.0; double PS_THRESHOLD = 0.0; double TAGM_TSIGMA = 0.200; // ns double TAGH_TSIGMA = 0.350; // ns double TAGM_FADC_TSIGMA = 0.350; // ns double TAGH_FADC_TSIGMA = 0.450; // ns double TAGM_NPIX_PER_GEV = 1.e5; double TAGH_NPE_PER_GEV = 5.e5; // The following are place holders to be filled in with realistic numbers later double PS_SIGMA = 0.200; // ns double PSC_SIGMA = 0.200; //ns double PS_NPIX_PER_GEV = 1.e5; double PSC_PHOTONS_PERMEV = 5.e5; double FCAL_PHOT_STAT_COEF = 0.0; //0.035; double FCAL_BLOCK_THRESHOLD = 0.0; //20.0*k_MeV; double CDC_TDRIFT_SIGMA = 0.0; // 150.0/55.0*1E-9 seconds double CDC_TIME_WINDOW = 0.0; // 1000.0E-9 seconds double CDC_PEDESTAL_SIGMA = 0.0; // in fC double CDC_THRESHOLD_FACTOR = 0.0; // number of pedestal sigmas for determining sparcification threshold double FDC_TDRIFT_SIGMA = 0.0; // 200.0/55.0*1.0E-9 seconds double FDC_CATHODE_SIGMA = 0.0; // 150.0 microns double FDC_PED_NOISE = 0.0; // in pC calculated in SmearFDC double FDC_THRESHOLD_FACTOR = 0.0; // number of pedestal sigmas for determining sparcification threshold double FDC_HIT_DROP_FRACTION = 0.0; // 1000.0E-9 double FDC_TIME_WINDOW = 0.0; // 1000.0E-9 in seconds double FDC_THRESH_KEV = 0.0; // fdc anode discriminator threshold double START_SIGMA = 0.0; // 300ps double START_PHOTONS_PERMEV = 0.0; // used to be 8000 should be more like 200 // TOF parameters will be read from data base later double TOF_SIGMA = 100.*k_psec; double TOF_PHOTONS_PERMEV = 400.; double TRIGGER_LOOKBACK_TIME = -100; // ns bool DROP_TRUTH_HITS=false; // CDC geometry parameters (for noise) vector NCDC_STRAWS; vector CDC_RING_RADIUS; // FDC geometry and rate parameters (for noise) vector FDC_LAYER_Z; double FDC_RATE_COEFFICIENT; #include using namespace jana; static JCalibration *jcalib=NULL; // histogram pthread_mutex_t root_mutex = PTHREAD_MUTEX_INITIALIZER; TH2F *fdc_drift_time_smear_hist; TH2F *fdc_drift_dist_smear_hist; TH2F *fdc_drift_time; TH1F *fdc_cathode_charge; TH2F *cdc_drift_time; TH1F *cdc_charge; TH1F *fdc_anode_mult; TH2F *cdc_drift_smear; //----------- // main //----------- int main(int narg,char* argv[]) { #if ! USE_JANA // Set up to catch SIGINTs for graceful exits signal(SIGINT,ctrlCHandleMCSmear); #endif ParseCommandLineArguments(narg, argv); // Create DApplication object and use it to create JCalibration object DApplication dapp(narg, argv); dapp.AddFactoryGenerator(new JFactoryGenerator_ThreadCancelHandler()); jcalib = dapp.GetJCalibration(1); // Make sure jcalib is set if(!jcalib){ _DBG_<<"ERROR - jcalib not set!"< tofparms; jcalib->Get("TOF/tof_parms", tofparms); TOF_SIGMA = tofparms["TOF_SIGMA"]; TOF_PHOTONS_PERMEV = tofparms["TOF_PHOTONS_PERMEV"]; } // get the BCAL parameters { cout<<"get BCAL/bcal_parms parameters from calibDB"< bcalparms; jcalib->Get("BCAL/bcal_parms", bcalparms); BCAL_DARKRATE_GHZ = bcalparms["BCAL_DARKRATE_GHZ"]; BCAL_SIGMA_SIG_RELATIVE = bcalparms["BCAL_SIGMA_SIG_RELATIVE"]; BCAL_SIGMA_PED_RELATIVE = bcalparms["BCAL_SIGMA_PED_RELATIVE"]; BCAL_SIPM_GAIN_VARIATION = bcalparms["BCAL_SIPM_GAIN_VARIATION"]; BCAL_XTALK_FRACT = bcalparms["BCAL_XTALK_FRACT"]; BCAL_INTWINDOW_NS = bcalparms["BCAL_INTWINDOW_NS"]; BCAL_DEVICEPDE = bcalparms["BCAL_DEVICEPDE"]; BCAL_SAMPLING_FRACT = bcalparms["BCAL_SAMPLING_FRACT"]; BCAL_AVG_DARK_DIGI_VALS_PER_EVENT = bcalparms["BCAL_AVG_DARK_DIGI_VALS_PER_EVENT"]; BCAL_PHOTONSPERSIDEPERMEV_INFIBER = bcalparms["BCAL_PHOTONSPERSIDEPERMEV_INFIBER"]; BCAL_SAMPLINGCOEFA = bcalparms["BCAL_SAMPLINGCOEFA"]; BCAL_SAMPLINGCOEFB = bcalparms["BCAL_SAMPLINGCOEFB"]; BCAL_TIMEDIFFCOEFA = bcalparms["BCAL_TIMEDIFFCOEFA"]; BCAL_TIMEDIFFCOEFB = bcalparms["BCAL_TIMEDIFFCOEFB"]; } { cout<<"get FCAL/fcal_parms parameters from calibDB"< fcalparms; jcalib->Get("FCAL/fcal_parms", fcalparms); if (FCAL_PHOT_STAT_COEF == 0.0) FCAL_PHOT_STAT_COEF = fcalparms["FCAL_PHOT_STAT_COEF"]; if (FCAL_BLOCK_THRESHOLD == 0.0) FCAL_BLOCK_THRESHOLD = fcalparms["FCAL_BLOCK_THRESHOLD"]; } { cout<<"get CDC/cdc_parms parameters from calibDB"< cdcparms; jcalib->Get("CDC/cdc_parms", cdcparms); if (CDC_TDRIFT_SIGMA == 0.0) CDC_TDRIFT_SIGMA = cdcparms["CDC_TDRIFT_SIGMA"]; if (CDC_TIME_WINDOW == 0.0) CDC_TIME_WINDOW = cdcparms["CDC_TIME_WINDOW"]; if (CDC_PEDESTAL_SIGMA == 0.0) CDC_PEDESTAL_SIGMA = cdcparms["CDC_PEDESTAL_SIGMA"]; if (CDC_THRESHOLD_FACTOR == 0.0) CDC_THRESHOLD_FACTOR = cdcparms["CDC_THRESHOLD_FACTOR"]; } { cout<<"get FDC/fdc_parms parameters from calibDB"< fdcparms; jcalib->Get("FDC/fdc_parms", fdcparms); if (FDC_TDRIFT_SIGMA == 0.0) FDC_TDRIFT_SIGMA = fdcparms["FDC_TDRIFT_SIGMA"]; if (FDC_CATHODE_SIGMA ==0.0) FDC_CATHODE_SIGMA = fdcparms["FDC_CATHODE_SIGMA"]; if (FDC_THRESHOLD_FACTOR == 0.0) FDC_THRESHOLD_FACTOR = fdcparms["FDC_THRESHOLD_FACTOR"]; FDC_PED_NOISE = fdcparms["FDC_PED_NOISE"]; if (FDC_TIME_WINDOW == 0.0) FDC_TIME_WINDOW = fdcparms["FDC_TIME_WINDOW"]; if (FDC_HIT_DROP_FRACTION == 0.0) FDC_HIT_DROP_FRACTION = fdcparms["FDC_HIT_DROP_FRACTION"]; if (FDC_THRESH_KEV == 0.0) FDC_THRESH_KEV = fdcparms["FDC_THRESH_KEV"]; } { cout<<"get START_COUNTER/start_parms parameters from calibDB"< startparms; jcalib->Get("START_COUNTER/start_parms", startparms); START_SIGMA = startparms["START_SIGMA"] ; START_PHOTONS_PERMEV = startparms["START_PHOTONS_PERMEV"]; } // hist file TFile *hfile = new TFile("smear.root","RECREATE","smearing histograms"); fdc_drift_time_smear_hist=new TH2F("fdc_drift_time_smear_hist","Drift time smearing for FDC", 300,0.0,0.6,400,-200,200); fdc_drift_dist_smear_hist=new TH2F("fdc_drift_dist_smear_hist","Drift distance smearing for FDC", 100,0.0,0.6,400,-0.5,0.5); double tmax=TRIGGER_LOOKBACK_TIME+FDC_TIME_WINDOW; int num_time_bins=int(FDC_TIME_WINDOW); fdc_drift_time=new TH2F("fdc_drift_time","FDC drift distance vs. time",num_time_bins,TRIGGER_LOOKBACK_TIME,tmax,100,0,1.); fdc_anode_mult = new TH1F("fdc_anode_mult","wire hit multiplicity",20,-0.5,19.5); fdc_cathode_charge = new TH1F("fdc_cathode_charge","charge on strips",1000,0,1000); tmax=TRIGGER_LOOKBACK_TIME+CDC_TIME_WINDOW; num_time_bins=int(CDC_TIME_WINDOW); cdc_drift_time = new TH2F("cdc_drift_time","CDC drift distance vs time",num_time_bins,TRIGGER_LOOKBACK_TIME,tmax,80,0.,0.8); cdc_drift_smear = new TH2F("cdc_drift_smear","CDC drift smearing", 100,0.0,800.0,100,-0.1,0.1); cdc_charge = new TH1F("cdc_charge","Measured charge in straw",1000,-10e3,40e3); #if ! USE_JANA cout << " input file: " << INFILENAME << endl; cout << " output file: " << OUTFILENAME << endl; // Open Input file ifstream ifs(INFILENAME); if (!ifs.is_open()) { cout << " Error opening input file \"" << INFILENAME << "\"!" << endl; exit(-1); } hddm_s::istream fin(ifs); // Output file ofstream ofs(OUTFILENAME); if (!ofs.is_open()){ cout << " Error opening output file \"" << OUTFILENAME << "\"!" << endl; exit(-1); } hddm_s::HDDM fout(ofs); // Loop over events in input file hddm_s::HDDM *record; int NEvents = 0; time_t last_time = time(NULL); while (ifs->good()) { fin >> *record; NEvents++; time_t now = time(NULL); if(now != last_time){ cout << " " << NEvents << " events processed \r"; cout.flush(); last_time = now; } // Smear values Smear(record); // Write event to output file *fout << *record; if (QUIT) break; } cout << endl; // close input and output files ifs.close(); ofs.close(); cout << " " << NEvents << " events read" << endl; #else DGeometry *dgeom=dapp.GetDGeometry(1); // Get number of cdc wires per ring and the radii of each ring vector >cdcwires; dgeom->GetCDCWires(cdcwires); for (unsigned int i=0;iorigin.Perp()); } // Get the FDC z positions for the wire planes dgeom->GetFDCZ(FDC_LAYER_Z); // Coefficient used to calculate FDCsingle wire rate. We calculate // it once here just to save calculating it for every wire in every event FDC_RATE_COEFFICIENT = exp(-log(4.0)/23.0)/2.0/log(24.0)*FDC_TIME_WINDOW/1000.0E-9; // Something is a little off in my calculation above so I scale it down via // an emprical factor: FDC_RATE_COEFFICIENT *= 0.353; MyProcessor myproc; dapp.Run(&myproc); #endif hfile->Write(); hfile->Close(); return 0; } //----------- // ParseCommandLineArguments //----------- void ParseCommandLineArguments(int narg, char* argv[]) { bool warn_obsolete = false; for (int i=1; i