128 const int total_events = 1E7;
129 std::shared_ptr<TMidasEvent>
event = std::make_shared<TMidasEvent>();
130 eventQ->reserve(total_events);
132 while(infile->
Read(event) > 0 && eventQ->size() < total_events) {
133 switch(event->GetEventId()) {
135 printf(
DRED "start of run\n");
140 printf(
DGREEN "end of run\n");
145 if(event->GetEventId() != 1) {
153 if(events_read % 250000 == 0) {
167 auto* midvshigh =
new TList;
170 std::map<int, int>::iterator mapit;
172 auto* midvshighhist =
new TH2D(Form(
"midvshigh_0x%04x", mapit->first), Form(
"midvshigh_0x%04x", mapit->first),
173 5000, 0, 5000, 5000, 0, 5000);
174 midvshigh->Add(midvshighhist);
184 lowest_hightime[i] = 0;
187 std::vector<TEventTime*>::iterator it;
189 for(it = eventQ->begin(); it != eventQ->end(); it++) {
191 int hightime = (*it)->TimeStampHigh();
192 uint64_t midtime = (*it)->MidasTime() - lowmidtime;
197 if((*it)->DetectorType() == 1) {
198 dynamic_cast<TH2D*
>(midvshigh->At((*it)->DigIndex()))->Fill(
static_cast<double>(midtime), hightime);
199 if(hightime < lowest_hightime[(*it)->DigIndex()]) {
208 if(lowest_hightime[mapit->second] < lowest_hightime[lowest_dig]) {
209 lowest_dig = mapit->second;
214 printf(
"The lowest digitizer is %d\n", lowest_dig);
215 printf(
"***** High time shifts *******\n");
217 printf(
"0x%04x:\t %d\n", mapit->first, lowest_hightime[mapit->second]);
219 correction[mapit->second] = ((lowest_hightime[mapit->second] - lowest_hightime[lowest_dig]) & 0x00003fff) << 28;
221 printf(
"********************\n");
225 delete[] lowest_hightime;
234 auto* roughlist =
new TList;
237 std::map<int, bool> keep_filling;
238 std::map<int, int>::iterator mapit;
241 new TH1C(Form(
"rough_0x%04x", mapit->first), Form(
"rough_0x%04x", mapit->first), 50E6, -25E6, 25E6);
242 roughlist->Add(roughhist);
243 keep_filling[mapit->first] =
true;
249 TH1C* fillhist =
nullptr;
251 std::vector<TEventTime*>::iterator hit1;
252 std::vector<TEventTime*>::iterator hit2;
254 const int range = 1000;
255 for(hit1 = eventQ->begin(); hit1 != eventQ->end(); hit1++) {
257 if(event1count % 250000 == 0) {
258 printf(
"Processing Event %d /%lu \r", event1count, eventQ->size());
267 int64_t time1 = (*hit1)->GetTimeStamp() - correction[(*hit1)->DigIndex()];
269 if(event1count > range) {
272 hit2 = eventQ->begin();
276 while(hit2 != eventQ->end() && event2count < range * 2) {
281 int digitizer = (*hit2)->Digitizer();
282 if(keep_filling[digitizer]) {
283 fillhist =
dynamic_cast<TH1C*
>(roughlist->At((*hit2)->DigIndex()));
284 int64_t time2 = (*hit2)->GetTimeStamp() - correction[(*hit2)->DigIndex()];
285 auto bin =
static_cast<Int_t
>(time2 - time1);
287 if(fillhist->FindBin(bin) > 0 && fillhist->FindBin(bin) < fillhist->GetNbinsX()) {
288 if(fillhist->GetBinContent(fillhist->Fill(bin)) > 126) {
289 keep_filling[digitizer] =
false;
290 printf(
"\nDigitizer 0x%04x is done filling\n", digitizer);
300 fillhist =
dynamic_cast<TH1C*
>(roughlist->At(mapit->second));
301 correction[mapit->second] +=
static_cast<int64_t
>(fillhist->GetBinCenter(fillhist->GetMaximumBin()));
304 printf(
"***** Rough time shifts *******\n");
307 printf(
"0x%04x:\t %lld\n", mapit->first, correction[mapit->second]);
309 printf(
"0x%04x:\t %ld\n", mapit->first, correction[mapit->second]);
312 printf(
"********************\n");
319void GetTimeDiff(std::vector<TEventTime*>* eventQ, int64_t* correction)
325 auto* list =
new TList;
328 std::map<int, int>::iterator mapit;
331 new TH1D(Form(
"timediff_0x%04x", mapit->first), Form(
"timediff_0x%04x", mapit->first), 1000, -500, 500);
338 TH1D* fillhist =
nullptr;
340 std::vector<TEventTime*>::iterator hit1;
341 std::vector<TEventTime*>::iterator hit2;
343 const int range = 1250;
344 for(hit1 = eventQ->begin(); hit1 != eventQ->end(); hit1++) {
346 if(event1count % 75000 == 0) {
347 printf(
"Processing Event %d / %lu \r", event1count, eventQ->size());
353 if((*hit1)->Digitizer() == 0 && (*hit1)->DetectorType() != 1) {
361 int64_t time1 = (*hit1)->GetTimeStamp() - correction[(*hit1)->DigIndex()];
364 if(event1count > range) {
367 hit2 = eventQ->begin();
371 while(hit2 != eventQ->end() && event2count < range * 2) {
374 if((*hit2)->Digitizer() == 0 && (*hit2)->DetectorType() != 1) {
380 fillhist =
dynamic_cast<TH1D*
>(list->At((*hit2)->DigIndex()));
381 int64_t time2 = (*hit2)->GetTimeStamp() - correction[(*hit2)->DigIndex()];
382 if(time2 - time1 < 2147483647 &&
383 time2 - time1 > -2147483647) {
384 auto bin =
static_cast<Int_t
>(time2 - time1);
393 fillhist =
dynamic_cast<TH1D*
>(list->At(mapit->second));
394 correction[mapit->second] +=
static_cast<int64_t
>(fillhist->GetBinCenter(fillhist->GetMaximumBin()));
395 auto* pm =
new TPolyMarker;
396 pm->SetNextPoint(fillhist->GetBinCenter(fillhist->GetMaximumBin()),
397 fillhist->GetBinContent(fillhist->GetMaximumBin()) + 10);
398 pm->SetMarkerStyle(23);
399 pm->SetMarkerColor(kRed);
400 pm->SetMarkerSize(1.3);
401 fillhist->GetListOfFunctions()->Add(pm);
405 printf(
"***** Final time shifts *******\n");
408 printf(
"0x%04x:\t %lld\n", mapit->first, correction[mapit->second]);
410 printf(
"0x%04x:\t %ld\n", mapit->first, correction[mapit->second]);
413 printf(
"********************\n");