10 #include "TTreeIndex.h" 11 #include "TVirtualIndex.h" 16 #include "TPolyMarker.h" 28 int banksize =
event->LocateBank(
nullptr,
"GRF1", &ptr);
30 uint32_t type = 0xffffffff;
31 uint32_t value = 0xffffffff;
35 for(
int x = 0; x < banksize; x++) {
36 value = *(
reinterpret_cast<int*
>(ptr) + x);
37 type = value & 0xf0000000;
42 chanadd = (value & 0x0003fff0) >> 4;
44 case 0xa0000000:
timelow = value & 0x0fffffff;
break;
45 case 0xb0000000:
timehigh = value & 0x00003fff;
break;
48 timemidas = (
unsigned int)(event->GetTimeStamp());
87 std::map<int, int>::iterator it;
124 const int total_events = 1E7;
125 std::shared_ptr<TMidasEvent>
event = std::make_shared<TMidasEvent>();
126 eventQ->reserve(total_events);
128 while(infile->
Read(event) > 0 && eventQ->size() < total_events) {
129 switch(event->GetEventId()) {
131 printf(
DRED "start of run\n");
136 printf(
DGREEN "end of run\n");
141 if(event->GetEventId() != 1) {
149 if(events_read % 250000 == 0) {
163 auto* midvshigh =
new TList;
166 std::map<int, int>::iterator mapit;
168 auto* midvshighhist =
new TH2D(Form(
"midvshigh_0x%04x", mapit->first), Form(
"midvshigh_0x%04x", mapit->first),
169 5000, 0, 5000, 5000, 0, 5000);
170 midvshigh->Add(midvshighhist);
182 int* lowest_hightime;
186 lowest_hightime[i] = 0;
189 std::vector<TEventTime*>::iterator it;
191 for(it = eventQ->begin(); it != eventQ->end(); it++) {
193 int hightime = (*it)->TimeStampHigh();
194 unsigned long midtime = (*it)->MidasTime() - lowmidtime;
199 if((*it)->DetectorType() == 1) {
200 (
dynamic_cast<TH2D*
>(midvshigh->At((*it)->DigIndex())))->Fill(midtime, hightime);
201 if(hightime < lowest_hightime[(*it)->DigIndex()]) {
210 if(lowest_hightime[mapit->second] < lowest_hightime[lowest_dig]) {
211 lowest_dig = mapit->second;
216 printf(
"The lowest digitizer is %d\n", lowest_dig);
217 printf(
"***** High time shifts *******\n");
219 printf(
"0x%04x:\t %d\n", mapit->first, lowest_hightime[mapit->second]);
221 correction[mapit->second] = ((lowest_hightime[mapit->second] - lowest_hightime[lowest_dig]) & 0x00003fff)<<28;
223 printf(
"********************\n");
227 delete[] lowest_hightime;
236 auto* roughlist =
new TList;
239 std::map<int, bool> keep_filling;
240 std::map<int, int>::iterator mapit;
243 new TH1C(Form(
"rough_0x%04x", mapit->first), Form(
"rough_0x%04x", mapit->first), 50E6, -25E6, 25E6);
244 roughlist->Add(roughhist);
245 keep_filling[mapit->first] =
true;
253 std::vector<TEventTime*>::iterator hit1;
254 std::vector<TEventTime*>::iterator hit2;
256 const int range = 1000;
257 for(hit1 = eventQ->begin(); hit1 != eventQ->end(); hit1++) {
259 if(event1count % 250000 == 0) {
260 printf(
"Processing Event %d /%lu \r", event1count, eventQ->size());
269 int64_t time1 = (*hit1)->GetTimeStamp() - correction[(*hit1)->DigIndex()];
271 if(event1count > range) {
274 hit2 = eventQ->begin();
278 while(hit2 != eventQ->end() && event2count < range * 2) {
283 int digitizer = (*hit2)->Digitizer();
284 if(keep_filling[digitizer]) {
286 dynamic_cast<TH1C*
>(roughlist->At((*hit2)->DigIndex()));
287 int64_t time2 = (*hit2)->GetTimeStamp() - correction[(*hit2)->DigIndex()];
288 Int_t bin =
static_cast<Int_t
>(time2 - time1);
290 if(fillhist->FindBin(bin) > 0 && fillhist->FindBin(bin) < fillhist->GetNbinsX()) {
291 if(fillhist->GetBinContent(fillhist->Fill(bin)) > 126) {
292 keep_filling[digitizer] =
false;
293 printf(
"\nDigitizer 0x%04x is done filling\n", digitizer);
303 fillhist =
dynamic_cast<TH1C*
>(roughlist->At(mapit->second));
304 correction[mapit->second] +=
static_cast<int64_t
>(fillhist->GetBinCenter(fillhist->GetMaximumBin()));
307 printf(
"***** Rough time shifts *******\n");
310 printf(
"0x%04x:\t %lld\n", mapit->first, correction[mapit->second]);
312 printf(
"0x%04x:\t %ld\n", mapit->first, correction[mapit->second]);
315 printf(
"********************\n");
322 void GetTimeDiff(std::vector<TEventTime*>* eventQ, int64_t* correction)
328 auto* list =
new TList;
331 std::map<int, int>::iterator mapit;
334 new TH1D(Form(
"timediff_0x%04x", mapit->first), Form(
"timediff_0x%04x", mapit->first), 1000, -500, 500);
343 std::vector<TEventTime*>::iterator hit1;
344 std::vector<TEventTime*>::iterator hit2;
346 const int range = 1250;
347 for(hit1 = eventQ->begin(); hit1 != eventQ->end(); hit1++) {
349 if(event1count % 75000 == 0) {
350 printf(
"Processing Event %d / %lu \r", event1count, eventQ->size());
356 if((*hit1)->Digitizer() == 0 && (*hit1)->DetectorType() != 1) {
364 int64_t time1 = (*hit1)->GetTimeStamp() - correction[(*hit1)->DigIndex()];
367 if(event1count > range) {
370 hit2 = eventQ->begin();
374 while(hit2 != eventQ->end() && event2count < range * 2) {
377 if((*hit2)->Digitizer() == 0 && (*hit2)->DetectorType() != 1) {
383 fillhist =
dynamic_cast<TH1D*
>(list->At((*hit2)->DigIndex()));
384 int64_t time2 = (*hit2)->GetTimeStamp() - correction[(*hit2)->DigIndex()];
385 if(time2 - time1 < 2147483647 &&
386 time2 - time1 > -2147483647) {
387 Int_t bin =
static_cast<Int_t
>(time2 - time1);
396 fillhist =
dynamic_cast<TH1D*
>(list->At(mapit->second));
397 correction[mapit->second] +=
static_cast<int64_t
>(fillhist->GetBinCenter(fillhist->GetMaximumBin()));
398 auto* pm =
new TPolyMarker;
399 pm->SetNextPoint(fillhist->GetBinCenter(fillhist->GetMaximumBin()),
400 fillhist->GetBinContent(fillhist->GetMaximumBin()) + 10);
401 pm->SetMarkerStyle(23);
402 pm->SetMarkerColor(kRed);
403 pm->SetMarkerSize(1.3);
404 fillhist->GetListOfFunctions()->Add(pm);
408 printf(
"***** Final time shifts *******\n");
411 printf(
"0x%04x:\t %lld\n", mapit->first, correction[mapit->second]);
413 printf(
"0x%04x:\t %ld\n", mapit->first, correction[mapit->second]);
416 printf(
"********************\n");
427 printf(
"Usage: ./offsetfind <input.mid>\n");
434 auto* outfile =
new TFile(
"outfile.root",
"RECREATE");
437 auto* eventQ =
new std::vector<TEventTime*>;
TEventTime(std::shared_ptr< TMidasEvent > event)
unsigned long MidasTime()
static void OrderDigitizerMap()
static std::map< int, int > digmap
void GetRoughTimeDiff(std::vector< TEventTime *> *eventQ, int64_t *correction)
static unsigned long GetLowestMidasTime()
int main(int argc, char **argv)
static int64_t lowest_time
Reader for MIDAS .mid files.
static unsigned long low_timemidas
static int GetBestDigitizer()
int Read(std::shared_ptr< TRawEvent > event) override
Read one event from the file.
bool Open(const char *filename) override
Open input file.
void GetTimeDiff(std::vector< TEventTime *> *eventQ, int64_t *correction)
void CheckHighTimeStamp(std::vector< TEventTime *> *eventQ, int64_t *correction)
int QueueEvents(TMidasFile *infile, std::vector< TEventTime *> *eventQ)