Commit f7cb060e authored by Klaas Padeken's avatar Klaas Padeken
Browse files

Make time correction for the mupix (use just 10bits and correct clock)

parent ec7d0fb6
......@@ -27,7 +27,6 @@ EventLoaderMuPixTelescope::EventLoaderMuPixTelescope(Configuration& config, std:
inputDirectory_ = config_.getPath("input_directory");
buffer_depth_ = config.get<unsigned>("buffer_depth");
isSorted_ = config_.get<bool>("is_sorted");
timeOffset_ = config_.get<double>("time_offset");
if(config.count({"run", "input_file"}) > 1) {
throw InvalidCombinationError(config, {"run", "input_file"}, "run and input_file are mutually exclusive.");
} else if(config_.has("input_file")) {
......@@ -47,6 +46,8 @@ void EventLoaderMuPixTelescope::initialize() {
if(typeString_to_typeID.find(detector_->getType()) == typeString_to_typeID.end()) {
throw KeyValueParseError("tag " + std::to_string(tag_), "Sensor tag not supported");
}
//take the offset from the geometry file
timeOffset_= detector_->timeOffset();
type_ = typeString_to_typeID.at(detector_->getType());
LOG(INFO) << "Detector " << detector_->getType() << "is assigned to type id " << type_;
std::stringstream ss;
......@@ -99,6 +100,9 @@ void EventLoaderMuPixTelescope::initialize() {
hTimeStamp = new TH1F("pixelTS", "pixelTS; TS in clock cycles; ", 1024, -0.5, 1023.5);
hHitsEvent = new TH1F("hHitsEvent", "hHitsEvent; # hits per event; ", 300, -.5, 299.5);
hitsPerkEvent = new TH1F("hHitsPerkEvent", "hitsper1kevents; corry events /1k; hits per 1k events", 1000, -.5, 999.5);
raw_fpga_vs_chip = new TH2F("raw_fpga_vs_chip","fpga vs chip clock;chip clock;fpga clock", 1024,0,1023,2048,0,2047);
raw_fpga_vs_chip_corrected = new TH2F("raw_fpga_vs_chip_corrected","fpga vs chip clock;chip clock;fpga clock", 1024,0,1023,2048,0,2047);
chip_delay = new TH1F("chip_delay", "Delay of chip events wrt. telescope frame;fpga clock@ chip clock 0;#events",2048,-1023,1023);
}
void EventLoaderMuPixTelescope::finalize(const std::shared_ptr<ReadonlyClipboard>&) {
......@@ -170,13 +174,14 @@ StatusCode EventLoaderMuPixTelescope::read_unsorted(const std::shared_ptr<Clipbo
fillBuffer();
// Return value telling analysis to keep running
if(pixelbuffer_.size() == 0)
return StatusCode::NoData;
return StatusCode::EndRun;
prev_event_end_ = clipboard->getEvent()->end();
return StatusCode::Success;
}
void EventLoaderMuPixTelescope::fillBuffer() {
long unsigned int temp_fpga_time=0;
int raw_time=0;
// here we need to check quite a number of cases
while(pixelbuffer_.size() < buffer_depth_) {
if(blockFile_->read_next(tf_)) {
......@@ -193,10 +198,25 @@ void EventLoaderMuPixTelescope::fillBuffer() {
// all hits in one frame are from the same sensor. Copy them
for(uint i = 0; i < tf_.num_hits(); ++i) {
h = tf_.get_hit(i, type_);
//this assumes a few things:
//time from fpga is using a 500MHz clock (4 times the clock used for the hit timestamp
temp_fpga_time = (tf_.timestamp() >> 2) ;
//just take 10 bits from the hit timestamp
raw_time=h.timestamp_raw()&0x3FF;
//get the fpga time +1bit just for plots
raw_fpga_vs_chip->Fill(raw_time,temp_fpga_time&0x7FF);
chip_delay->Fill((temp_fpga_time&0x3FF)-raw_time );
//if the chip timestamp is smaller than the fpga we have a bit flip on the 11th bit
if((temp_fpga_time&0x3FF)<raw_time){
temp_fpga_time-=1024;
}
raw_fpga_vs_chip_corrected->Fill(raw_time,temp_fpga_time&0x7FF);
// convert timestamp to ns - i'd like to do this already on the mupix8_DAQ side, but have not found the time
// yet, assuming 10bit ts
double px_timestamp =
8 * static_cast<double>(((tf_.timestamp() >> 2) & 0xFFFFFFFFFFC00) + h.timestamp_raw()) - timeOffset_;
8 * static_cast<double>((temp_fpga_time & 0xFFFFFFFFFFC00) + raw_time) - timeOffset_;
LOG(TRACE) << "Pixel timestamp " << px_timestamp;
// setting tot and charge to zero here - needs to be improved
pixelbuffer_.push(std::make_shared<Pixel>(detector_->getName(), h.column(), h.row(), 0, 0, px_timestamp));
......
......@@ -82,6 +82,9 @@ namespace corryvreckan {
TH1F* hitsPerkEvent;
TH2F* hdiscardedHitmap;
TH2F* hHitMap;
TH2F* raw_fpga_vs_chip;
TH2F* raw_fpga_vs_chip_corrected;
TH1F* chip_delay;
static std::map<std::string, int> typeString_to_typeID;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment