// UnCal.cc // Contact person: Gabriel Orebi Gann - Author // See UnCal.hh for more details //———————————————————————// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; namespace RAT { UnCal::UnCal() { } void UnCal::BeginOfRun(DS::Run &run) { fNcrate = 19; fNcard = 16; fNchannel = 32; fNcell = 16; fNTotCell = fNcrate * fNcard *fNchannel * fNcell; fTotChannel = fNcrate * fNcard *fNchannel; fUnCalbank = DB::Get()->GetLink("DAQ"); int UnCalType = fUnCalbank->GetI("uncal_type"); int ECAType = fUnCalbank->GetI("eca_type"); int ECAPDSTpattern = fUnCalbank->GetI("eca_pdst_pattern"); int ECAPDSTrate = fUnCalbank->GetI("eca_pdst_rate"); int ECATSLPpattern = fUnCalbank->GetI("eca_tslp_pattern"); int ECATSLPrate = fUnCalbank->GetI("eca_tslp_rate"); //int PCAType = fUnCalbank->GetI("pca_type"); UnCal::UnCalibStatus(UnCalType, fDoECA, fDoPCA, fDoMC); bool mc; UnCal::UnCalibStatus(ECAType, fDoPed, fDoTslp, mc); fDoUncal = true; if(!fDoECA && !fDoPCA && !fDoMC)fDoUncal = false; //Get the pattern and rate std::stringstream pdst_pattern_rate, tslp_pattern_rate; pdst_pattern_rate << ECAPDSTpattern <<"_"<GetLink("ECA_PDST", pdst_pattern_rate.str()); fTslpbank = DB::Get()->GetLink("ECA_TSLP", tslp_pattern_rate.str()); if(fDoPed){ try{ fPedsbank->GetS("index"); } catch(DBNotFoundError){ UnCal::Die("",5,ECAPDSTpattern,ECAPDSTrate); } fPedQHS = fPedsbank->GetFArrayFromD("pdst_qhs"); fPedQHL = fPedsbank->GetFArrayFromD("pdst_qhl"); fPedQLX = fPedsbank->GetFArrayFromD("pdst_qlx"); //fPedTAC = fPedsbank->GetDArray("pdst_tac"); fPedSigQHS = fPedsbank->GetFArrayFromD("pdst_qhswidth"); fPedSigQHL = fPedsbank->GetFArrayFromD("pdst_qhlwidth"); fPedSigQLX = fPedsbank->GetFArrayFromD("pdst_qlxwidth"); fPedSigTAC = fPedsbank->GetFArrayFromD("pdst_tacwidth"); } if(fDoTslp){ try{ fTslpbank->GetS("index"); } catch(DBNotFoundError){ UnCal::Die("",5,ECAPDSTpattern,ECAPDSTrate); } fTslope = fTslpbank->GetFArrayFromD("tslp_points"); fNSlopePoints = fTslpbank->GetI("tslp_ntimes"); fNdim = static_cast(fNSlopePoints / 32)+1; fTslopeX = fTslpbank->GetFArrayFromD("tslp_times"); fTslopeBadTemp = fTslpbank->GetIArray("tslp_bad"); // Sort status words by cell fTslopeBad.resize(fNTotCell); if((int)fTslopeBadTemp.size() != fNTotCell*fNdim){ warn<<"=================================================="<GetPMTInfo(); DS::EV& ev = ds.GetEV(iev); DS::MCEV& mcev = ds.GetMCEV(iev); size_t npmttrue = mcev.GetMCHits().GetAllCount(); size_t nhit = ev.GetUncalPMTs().GetCount(); // NOTE normal only size_t npmtuncal = ev.GetUncalPMTs().GetAllCount(); ULong64_t totalQ = 0; // If no uncalibration requested, and no PMTUncal to be digitised if(!fDoUncal && (npmtuncal==0))return; // For a regular run we expect: // Data: SHOULD NOT BE UNCALIBRATING DATA! // MC: NHit == 0 until we create some PMTUncal // NPMTUncal == 0 since we haven't uncalibrated yet // Die, if the numbers of Cal / UnCal PMTs / NHit are not as expected if(nhit != 0)UnCal::Die("MC",1,nhit,npmttrue); if(npmtuncal!=0)UnCal::Die("MC",2,npmtuncal,0); for(size_t ih = 0; ih200.&& temp<3700.))G4cout<<"TAC = "<0) fTAC += throwme; } // Convert from ns back to ADC counts void UnCal::TSlope(int cccc) { // Assume time reversal already handled in the event builder double result = 0.; // Get the TAC slope points for this cell // And find where in time the hit fell // ONLY USE GOOD POINTS ON TAC SLOPE (i.e. not bad/susp) // but using the curl region is fine std::vector bad = fTslopeBad[cccc]; float *adc = new float[fNSlopePoints]; int ilow = -1; int ihigh = 99; //bool status = 0; int lastgood = 0; int penultimate = 0; for(int i=0;iTestBit(bad,i))continue; penultimate = lastgood; lastgood = i; // bracket value if((fTAC>=fTslopeX[i])&&(i>ilow))ilow = i; if((fTAC<=fTslopeX[i])&&(itime[fNSlopePoints-1], it was too early(!), lose it // (Latter should never happen, since max TSlopeX > GTValid, unless the points were bad) // NO: might happen for bad points so again, extrapolate based on last two good points if(ihigh>=fNSlopePoints){ // UnCal::DontDie("early",1,(int)fTAC,(int)fTslopeX[0],(int)fTslopeX[fNSlopePoints-1]); // result = 0; // fTAC = result; // delete[] adc; // return; ihigh = lastgood; ilow = penultimate; debug<<"UnCalib: "<4095)time=4095; //if(!(time>200.&& time<3700.))G4cout<<"TAC = "<4095)charge=4095; return charge; } bool UnCal::FileExists(std::string filename) { struct stat stFileInfo; bool open; int intStat; // Attempt to get the file attributes intStat = stat(filename.c_str(),&stFileInfo); if(intStat == 0) { open = true; } else { open = false; } return(open); } // Handle errors void UnCal::DontDie(std::string message, int flag_err, int info1, int info2, int info3) { warn << YELLOW << " UnCal SETBACK:" << CLR << newline; if(flag_err==1){ // PMT hit is outside TAC region warn<<"This PMT, hit at "<