NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
IceDB2Root.cxx
Go to the documentation of this file.
1
17
19
161
162#include "IceDB2Root.h"
163#include "Riostream.h"
164
165ClassImp(IceDB2Root); // Class implementation to enable ROOT I/O
166
167IceDB2Root::IceDB2Root(const char* name,const char* title) : NcJob(name,title)
168{
174
175 fDBName="mysql://icedb.umh.ac.be/I3OmDb";
176 fUser="www";
177 fPassword="";
178 fRootFileName="";
179 fOutfile=0;
180
181 fPdg=0;
182 fMuDaqdb=0;
183 fTWRDaqdb=0;
184 fJEBTDaqdb=0;
185 fJEBADaqdb=0;
186}
187
189{
195
196 if (fPdg)
197 {
198 delete fPdg;
199 fPdg=0;
200 }
201
202 if (fMuDaqdb)
203 {
204 delete fMuDaqdb;
205 fMuDaqdb=0;
206 }
207
208 if (fTWRDaqdb)
209 {
210 delete fTWRDaqdb;
211 fTWRDaqdb=0;
212 }
213
214 if (fJEBTDaqdb)
215 {
216 delete fJEBTDaqdb;
217 fJEBTDaqdb=0;
218 }
219
220 if (fJEBADaqdb)
221 {
222 delete fJEBADaqdb;
223 fJEBADaqdb=0;
224 }
225}
226
227void IceDB2Root::SetDatabase(TString name, TString user, TString password)
228{
234
235 fDBName=name;
236 fUser=user;
237 fPassword=password;
238}
239
241{
247
248 fRootFileName=name;
249}
250
252{
258
259 return fTime;
260}
261
262void IceDB2Root::SetUT(Int_t y, Int_t m, Int_t d, Int_t hh, Int_t mm, Int_t ss)
263{
270
271 fTime.SetUT(y,m,d,hh,mm,ss);
272}
273
274TDatabasePDG* IceDB2Root::GetPDG()
275{
281
282 return fPdg;
283}
284
286{
294
295 if (name=="MuDaq") return fMuDaqdb;
296 if (name=="TWRDaq") return fTWRDaqdb;
297 if (name=="JEBTDaq") return fJEBTDaqdb;
298 if (name=="JEBADaq") return fJEBADaqdb;
299 return 0;
300}
301
302void IceDB2Root::Exec(Option_t* opt)
303{
322
323 if (fOutfile)
324 {
325 delete fOutfile;
326 fOutfile=0;
327 }
328 if (fRootFileName != "")
329 {
330 fOutfile=new TFile(fRootFileName.Data(),"RECREATE","Calibration data in IcePack structure");
331 }
332
333 // Create the particle database and extend it with some F2000 specific definitions
334 if (fPdg) delete fPdg;
335 fPdg=new TDatabasePDG();
336 fPdg->SetNameTitle("PDG-DBASE","The extended PDG particle database");
337 Double_t me=fPdg->GetParticle(11)->Mass();
338 fPdg->AddParticle("brems" ,"brems" ,0,1,0,0,"none",10001001,0,0);
339 fPdg->AddParticle("deltae" ,"deltae" ,me,1,0,-3,"Lepton",10001002,0,0);
340 fPdg->AddParticle("pairprod","pairprod",0,1,0,0,"none",10001003,0,0);
341 fPdg->AddParticle("nucl_int","nucl_Int",0,1,0,0,"none",10001004,0,0);
342 fPdg->AddParticle("mu_pair" ,"mu_pair" ,0,1,0,0,"none",10001005,0,0);
343 fPdg->AddParticle("hadrons" ,"hadrons" ,0,1,0,0,"none",10001006,0,0);
344 fPdg->AddParticle("fiberlaser","fiberlaser",0,1,0,0,"none",10002100,0,0);
345 fPdg->AddParticle("n2laser" ,"n2laser" ,0,1,0,0,"none",10002101,0,0);
346 fPdg->AddParticle("yaglaser" ,"yaglaser" ,0,1,0,0,"none",10002201,0,0);
347 fPdg->AddParticle("z_primary","z_primary",0,1,0,0,"none",10003000,0,0);
348 fPdg->AddParticle("a_primary","a_primary",0,1,0,0,"none",10003500,0,0);
349
350 // Initialise the job working environment
353
354 cout << " ***" << endl;
355 cout << " *** Start processing of job " << GetName() << " ***" << endl;
356 cout << " ***" << endl;
357 cout << " Database : " << fDBName.Data() << endl;
358 if (fOutfile) cout << " ROOT output file : " << fOutfile->GetName() << endl;
359
360 // Get all the data
361 GetMuDaqData();
363
366
369
372
374
375 // Invoke all available sub-tasks (if any)
376 CleanTasks();
377 ExecuteTasks(opt);
378
379 // Write the datastructures to the output file
380 if (fOutfile)
381 {
382 fOutfile->cd();
383 if (fMuDaqdb) fMuDaqdb->Write();
384 if (fTWRDaqdb) fTWRDaqdb->Write();
385 if (fJEBTDaqdb) fJEBTDaqdb->Write();
386 if (fJEBADaqdb) fJEBADaqdb->Write();
387 if (fPdg) fPdg->Write();
388 }
389
390 // Flush remaining memory resident data to the output file
391 if (fOutfile) fOutfile->Write();
392}
393
395{
401
402 // Connect to the DB server
403 TSQLServer* server=TSQLServer::Connect(fDBName.Data(),fUser.Data(),fPassword.Data());
404 if (!server)
405 {
406 cout << " *IceDB2Root GetMuDaqData* Database " << fDBName.Data() << " could not be accessed." << endl;
407 return;
408 }
409
410 // The MuDaq OM database object
411 if (fMuDaqdb)
412 {
413 fMuDaqdb->Reset();
414 }
415 else
416 {
417 fMuDaqdb=new NcObjMatrix();
418 fMuDaqdb->SetNameTitle("MuDaq-OMDBASE","The MuDaq OM geometry, calib. etc... database");
419 fMuDaqdb->SetOwner();
420 }
421
422 // Prescription of the various (de)calibration functions
423 TF1 fadccal("fadccal","(x-[1])*[0]");
424 TF1 fadcdecal("fadcdecal","(x/[0])+[1]");
425 fadccal.SetParName(0,"BETA-ADC");
426 fadccal.SetParName(1,"PED-ADC");
427 fadcdecal.SetParName(0,"BETA-ADC");
428 fadcdecal.SetParName(1,"PED-ADC");
429
430 TF1 ftdccal("ftdccal","(x*[0])-[1]-([0]-1.)*32767.-[2]/sqrt([3])");
431 TF1 ftdcdecal("ftdcdecal","(x+([0]-1.)*32767.+[1]+[2]/sqrt([3]))/[0]");
432 ftdccal.SetParName(0,"BETA-TDC");
433 ftdccal.SetParName(1,"T0");
434 ftdccal.SetParName(2,"ALPHA-TDC");
435 ftdccal.SetParName(3,"ADC-SLEW");
436 ftdcdecal.SetParName(0,"BETA-TDC");
437 ftdcdecal.SetParName(1,"T0");
438 ftdcdecal.SetParName(2,"ALPHA-TDC");
439 ftdcdecal.SetParName(3,"ADC-SLEW");
440
441 TF1 ftotcal("ftotcal","x*[0]");
442 TF1 ftotdecal("ftotdecal","x/[0]");
443 ftotcal.SetParName(0,"BETA-TOT");
444 ftotdecal.SetParName(0,"BETA-TOT");
445
446 // The cross talk probability function
447 TF1 fxtalkp("fxtalkp","(1.+[2]-[2]+[3]-[3])/(1.+exp(([0]-x)/[1]))");
448 fxtalkp.SetParName(0,"C");
449 fxtalkp.SetParName(1,"B");
450 fxtalkp.SetParName(2,"dLE-min");
451 fxtalkp.SetParName(3,"dLE-max");
452
453 // The basic OM contents
454 IceAOM om;
455
456 // Slots to hold the various (de)calibration functions
457 om.AddNamedSlot("ADC");
458 om.AddNamedSlot("LE");
459 om.AddNamedSlot("TOT");
460 // Slots with hardware parameters
461 om.AddNamedSlot("TYPE"); // -1=unknown 0=std_coax 1=std_twisted/std_hybrid 2=desy_hybrid 3=uci_fiber 4=lbl_dom 5=dAOM_ld 6=dAOM_led 9=desy_active_fiber
462 om.AddNamedSlot("ORIENT");
463 om.AddNamedSlot("THRESH");
464 om.AddNamedSlot("SENSIT");
465 om.AddNamedSlot("READOUT"); // 0=unknown 1=electrical 2=optical 3=digital
466
467 // Default values
468 Float_t type=-1;
469 om.SetSignal(type,"TYPE");
470 Float_t costh=0;
471 om.SetSignal(costh,"ORIENT");
472 Float_t thresh=0;
473 om.SetSignal(thresh,"THRES");
474 Float_t sensit=1;
475 om.SetSignal(sensit,"SENSIT");
476 Float_t readout=0;
477 om.SetSignal(readout,"READOUT");
478
479 // Variables needed
480 TSQLStatement* st;
481 IceAOM* omx=0;
482 Int_t omid;
483 Double_t pos[3]={0,0,0};
484 Float_t ped, beta, alpha;
485 Int_t jtrans,jrec;
486 Float_t c, b, dlemin, dlemax;
487 TF1* fcal=0;
488 TF1* fdecal=0;
489 NcTimestamp validitystart, validityend;
490 Int_t revision[682];
491
492 // Difference between Amanda and IceCube coordinates
493 Float_t dx=-339.8;
494 Float_t dy=-117.4;
495 Float_t dz=-224.6;
496
497 // Get positions of Amanda OMs in Amanda coordinates
498 for(omid=0; omid<=681; omid++) revision[omid]=0;
499 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, X, Y, Z, AmandaOm.TypeId, Orientation FROM GeometryOm INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE GeometryOm.StringId=AmandaOm.StringId AND GeometryOm.TubeId=AmandaOm.TubeId AND GeometryOm.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=2;");
500 if (!st)
501 {
502 cout << " *IceDB2Root GetMuDaqData* Positions could not be read from DB" << endl;
503 }
504 else {
505 st->Process();
506 st->StoreResult();
507 while(st->NextResultRow())
508 {
509 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
510 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
511 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
512 omid=st->GetInt(3);
513 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
514 {
515 revision[omid]=st->GetInt(2);
516 // Get OM, create a new one if necessary
517 omx=(IceAOM*)fMuDaqdb->GetObject(omid,1);
518 if (!omx)
519 {
520 omx=new IceAOM(om);
521 omx->SetUniqueID(omid);
522 fMuDaqdb->EnterObject(omid,1,omx);
523 }
524 // Enter calibration values
525 pos[0]=st->GetDouble(4)+dx;
526 pos[1]=st->GetDouble(5)+dy;
527 pos[2]=st->GetDouble(6)+dz;
528 omx->SetPosition(pos,"car");
529 type=(Float_t)st->GetInt(7);
530 omx->SetSignal(type,"TYPE");
531 costh=(Float_t)st->GetInt(8);
532 omx->SetSignal(costh,"ORIENT");
533 }
534 }
535 }
536
537 // Get sensitivity/threshold of Amanda OMs
538 for(omid=0; omid<=681; omid++) revision[omid]=0;
539 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id, sc_sensit, sc_thresh FROM AmandaStatusOm INNER JOIN CalibrationDetail WHERE AmandaStatusOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=804;");
540 if (!st)
541 {
542 cout << " *IceDB2Root GetMuDaqData* Sensitivity/threshold could not be read from DB" << endl;
543 }
544 else {
545 st->Process();
546 st->StoreResult();
547 while(st->NextResultRow())
548 {
549 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
550 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
551 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
552 omid=st->GetInt(3);
553 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
554 {
555 revision[omid]=st->GetInt(2);
556 // Get OM, create a new one if necessary
557 omx=(IceAOM*)fMuDaqdb->GetObject(omid,1);
558 if (!omx)
559 {
560 omx=new IceAOM(om);
561 omx->SetUniqueID(omid);
562 fMuDaqdb->EnterObject(omid,1,omx);
563 }
564 // Enter calibration values
565 thresh=(Float_t)st->GetDouble(4);
566 sensit=(Float_t)st->GetDouble(5);
567 omx->SetSignal(thresh,"THRES");
568 omx->SetSignal(sensit,"SENSIT");
569 }
570 }
571 }
572
573 // Get readout types of Amanda OMs
574 for(omid=0; omid<=681; omid++) revision[omid]=0;
575 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, CableType FROM AmandaTWRCableType INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE AmandaTWRCableType.StringId=AmandaOm.StringId AND AmandaTWRCableType.TubeId=AmandaOm.TubeId AND AmandaTWRCableType.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=853;");
576 if (!st)
577 {
578 cout << " *IceDB2Root GetMuDaqData* Readout types could not be read from DB" << endl;
579 }
580 else {
581 st->Process();
582 st->StoreResult();
583 while(st->NextResultRow())
584 {
585 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
586 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
587 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
588 omid=st->GetInt(3);
589 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
590 {
591 revision[omid]=st->GetInt(2);
592 // Get OM, create a new one if necessary
593 omx=(IceAOM*)fMuDaqdb->GetObject(omid,1);
594 if (!omx)
595 {
596 omx=new IceAOM(om);
597 omx->SetUniqueID(omid);
598 fMuDaqdb->EnterObject(omid,1,omx);
599 }
600 // Enter calibration values
601 if(st->GetUInt(4) == 0) readout=1; // Electrical
602 else if(st->GetUInt(4) == 10) readout=2; // Optical
603 else readout=0; // Unknown
604 omx->SetSignal(readout,"READOUT");
605 }
606 }
607 }
608
609 // Get muDAQ amplitude calibration constants
610 for(omid=0; omid<=681; omid++) revision[omid]=0;
611 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id, ac_pedestal, ac_spepeak FROM AmandaAmplOm INNER JOIN CalibrationDetail WHERE AmandaAmplOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=802;");
612 if (!st)
613 {
614 cout << " *IceDB2Root GetMuDaqData* Amplitude calibrations could not be read from DB" << endl;
615 }
616 else {
617 st->Process();
618 st->StoreResult();
619 while(st->NextResultRow())
620 {
621 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
622 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
623 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
624 omid=st->GetInt(3);
625 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
626 {
627 revision[omid]=st->GetInt(2);
628 // Get OM, create a new one if necessary
629 omx=(IceAOM*)fMuDaqdb->GetObject(omid,1);
630 if (!omx)
631 {
632 omx=new IceAOM(om);
633 omx->SetUniqueID(omid);
634 fMuDaqdb->EnterObject(omid,1,omx);
635 }
636 // Set calibration functions
637 omx->SetCalFunction(&fadccal,1);
638 omx->SetDecalFunction(&fadcdecal,1);
639 // Get calibration values
640 ped=(Float_t)st->GetDouble(4);
641 if (st->GetDouble(5)>0) beta=(Float_t)(1/st->GetDouble(5));
642 else beta=-999999;
643 // Flag amplitude slots of bad OMs as dead and don't provide amplitude (de)calib functions
644 if (ped<-1e5 || beta<=0)
645 {
646 omx->SetDead(1);
647 omx->SetCalFunction(0,1);
648 omx->SetDecalFunction(0,1);
649 }
650 // Set calibration function parameters
651 fcal=omx->GetCalFunction(1);
652 fdecal=omx->GetDecalFunction(1);
653 if (fcal)
654 {
655 fcal->SetParameter(0,beta);
656 fcal->SetParameter(1,ped);
657 }
658 if (fdecal)
659 {
660 fdecal->SetParameter(0,beta);
661 if (!beta) fdecal->SetParameter(0,1);
662 fdecal->SetParameter(1,ped);
663 }
664 }
665 }
666 }
667
668 // Get muDAQ time calibration constants
669 for(omid=0; omid<=681; omid++) revision[omid]=0;
670 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id, tc_tzero, tc_beta_t, tc_alpha_t FROM AmandaTimeOm INNER JOIN CalibrationDetail WHERE AmandaTimeOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=805;");
671 if (!st)
672 {
673 cout << " *IceDB2Root GetMuDaqData* Time calibrations could not be read from DB" << endl;
674 }
675 else {
676 st->Process();
677 st->StoreResult();
678 while(st->NextResultRow())
679 {
680 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
681 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
682 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
683 omid=st->GetInt(3);
684 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
685 {
686 revision[omid]=st->GetInt(2);
687 // Get OM, create a new one if necessary
688 omx=(IceAOM*)fMuDaqdb->GetObject(omid,1);
689 if (!omx)
690 {
691 omx=new IceAOM(om);
692 omx->SetUniqueID(omid);
693 fMuDaqdb->EnterObject(omid,1,omx);
694 }
695 // Set calibration functions
696 omx->SetCalFunction(&ftdccal,2);
697 omx->SetDecalFunction(&ftdcdecal,2);
698 omx->SetCalFunction(&ftotcal,3);
699 omx->SetDecalFunction(&ftotdecal,3);
700 // Get calibration values
701 ped=(Float_t)st->GetDouble(4);
702 beta=(Float_t)st->GetDouble(5);
703 alpha=(Float_t)st->GetDouble(6);
704 // Flag time slots of bad OMs as dead and don't provide time (de)calib functions
705 if (ped<-1e5 || beta<=0 || alpha<0)
706 {
707 omx->SetDead(2);
708 omx->SetDead(3);
709 omx->SetCalFunction(0,2);
710 omx->SetDecalFunction(0,2);
711 omx->SetCalFunction(0,3);
712 omx->SetDecalFunction(0,3);
713 }
714 // Set calibration function parameters
715 fcal=omx->GetCalFunction(2);
716 fdecal=omx->GetDecalFunction(2);
717 if (fcal)
718 {
719 fcal->SetParameter(0,beta);
720 fcal->SetParameter(1,ped);
721 fcal->SetParameter(2,alpha);
722 fcal->SetParameter(3,1.e20);
723 }
724 if (fdecal)
725 {
726 fdecal->SetParameter(0,beta);
727 if (!beta) fdecal->SetParameter(0,1);
728 fdecal->SetParameter(1,ped);
729 fdecal->SetParameter(2,alpha);
730 fdecal->SetParameter(3,1.e20);
731 }
732 fcal=omx->GetCalFunction(3);
733 fdecal=omx->GetDecalFunction(3);
734 if (fcal)
735 {
736 fcal->SetParameter(0,beta);
737 }
738 if (fdecal)
739 {
740 fdecal->SetParameter(0,beta);
741 }
742 }
743 }
744 }
745
746 // Get Xtalk probability constants
747 for(omid=0; omid<=681; omid++) revision[omid]=0;
748 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_talker_id, om_receiver_id, threshold, width, timelow, timehigh FROM AmandaXtalkOm INNER JOIN CalibrationDetail WHERE AmandaXtalkOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=807;");
749 if (!st)
750 {
751 cout << " *IceDB2Root GetMuDaqData* Xtalk probability constants could not be read from DB" << endl;
752 }
753 else {
754 st->Process();
755 st->StoreResult();
756 while(st->NextResultRow())
757 {
758 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
759 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
760 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
761 jtrans=st->GetInt(3);
762 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[jtrans])
763 {
764 revision[jtrans]=st->GetInt(2);
765 jrec=st->GetInt(4);
766 // Get transmitter OM, create a new one if necessary
767 omx=(IceAOM*)fMuDaqdb->GetObject(jtrans,1);
768 if (!omx)
769 {
770 omx=new IceAOM(om);
771 omx->SetUniqueID(jtrans);
772 fMuDaqdb->EnterObject(jtrans,1,omx);
773 }
774 // Get calibration values
775 c=(Float_t)st->GetDouble(5);
776 b=(Float_t)st->GetDouble(6);
777 dlemin=(Float_t)st->GetDouble(7);
778 dlemax=(Float_t)st->GetDouble(8);
779 // Make Xtalk probability function and set parameters
780 TF1* fx=new TF1(fxtalkp);
781 fx->SetParameter(0,c);
782 if (b) fx->SetParameter(1,b);
783 else fx->SetParameter(1,1);
784 fx->SetParameter(2,dlemin);
785 fx->SetParameter(3,dlemax);
786 fMuDaqdb->EnterObject(jtrans,jrec+1,fx);
787 }
788 }
789 }
790
791 // Flag OMs in bad OM list as dead
792 for(omid=0; omid<=681; omid++) revision[omid]=0;
793 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id FROM AmandaBadOm INNER JOIN CalibrationDetail WHERE AmandaBadOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=803;");
794 if (!st)
795 {
796 cout << " *IceDB2Root GetMuDaqData* Bad OM list could not be read from DB" << endl;
797 }
798 else {
799 st->Process();
800 st->StoreResult();
801 while(st->NextResultRow())
802 {
803 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
804 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
805 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
806 omid=st->GetInt(3);
807 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
808 {
809 revision[omid]=st->GetInt(2);
810 // Get OM, create a new one if necessary
811 omx=(IceAOM*)fMuDaqdb->GetObject(omid,1);
812 if (!omx)
813 {
814 omx=new IceAOM(om);
815 omx->SetUniqueID(omid);
816 fMuDaqdb->EnterObject(omid,1,omx);
817 }
818 // Flag OMs as dead
819 omx->SetDead(1);
820 omx->SetCalFunction(0,1);
821 omx->SetDecalFunction(0,1);
822 omx->SetDead(2);
823 omx->SetCalFunction(0,2);
824 omx->SetDecalFunction(0,2);
825 omx->SetDead(3);
826 omx->SetCalFunction(0,3);
827 omx->SetDecalFunction(0,3);
828 }
829 }
830 }
831
832}
833
835{
841
842 // Connect to the DB server
843 TSQLServer* server=TSQLServer::Connect(fDBName.Data(),fUser.Data(),fPassword.Data());
844 if (!server)
845 {
846 cout << " *IceDB2Root GetTWRDaqData* Database " << fDBName.Data() << " could not be accessed." << endl;
847 return;
848 }
849
850 // The TWRDaq OM database object
851 if (fTWRDaqdb)
852 {
853 fTWRDaqdb->Reset();
854 }
855 else
856 {
858 fTWRDaqdb->SetNameTitle("TWRDaq-OMDBASE","The TWRDaq OM geometry, calib. etc... database");
859 fTWRDaqdb->SetOwner();
860 }
861
862 // Prescription of the various (de)calibration functions
863
864 // Conversion of adc to charge in nC
865 // Volt per digit = 5/4096 Assumed capacitance = 20 pF
866 // Charge (in nC) is adc*(5./4096.)*0.02
867 // The database calibration constant is the amount of nC per photon electron (nC/PE)
868 TF1 fadccal("fadccal","x*(5./4096.)/(50.*[0])");
869 TF1 fadcdecal("fadcdecal","x*(50.*[0])/(5./4096.)");
870 fadccal.SetParName(0,"nC/PE");
871 fadcdecal.SetParName(0,"nC/PE");
872
873 TF1 ftdccal("ftdccal","x-[0]");
874 TF1 ftdcdecal("ftdcdecal","x+[0]");
875 ftdccal.SetParName(0,"T0");
876 ftdcdecal.SetParName(0,"T0");
877
878 TF1 ftotcal("ftotcal","x");
879 TF1 ftotdecal("ftotdecal","x");
880
881 // The cross talk probability function
882 TF1 fxtalkp("fxtalkp","(1.+[2]-[2]+[3]-[3])/(1.+exp(([0]-x)/[1]))");
883 fxtalkp.SetParName(0,"C");
884 fxtalkp.SetParName(1,"B");
885 fxtalkp.SetParName(2,"dLE-min");
886 fxtalkp.SetParName(3,"dLE-max");
887
888 // The basic OM contents
889 IceAOM om;
890
891 // Slots to hold the various (de)calibration functions
892 om.AddNamedSlot("ADC");
893 om.AddNamedSlot("LE");
894 om.AddNamedSlot("TOT");
895 // Slots with hardware parameters
896 om.AddNamedSlot("TYPE"); // -1=unknown 0=std_coax 1=std_twisted/std_hybrid 2=desy_hybrid 3=uci_fiber 4=lbl_dom 5=dAOM_ld 6=dAOM_led 9=desy_active_fiber
897 om.AddNamedSlot("ORIENT");
898 om.AddNamedSlot("THRESH");
899 om.AddNamedSlot("SENSIT");
900 om.AddNamedSlot("READOUT"); // 0=unknown 1=electrical 2=optical 3=digital
901 om.AddNamedSlot("BINSIZE");
902 om.AddNamedSlot("EXTSTOP");
903
904 // Default values
905 Float_t type=-1;
906 om.SetSignal(type,"TYPE");
907 Float_t costh=0;
908 om.SetSignal(costh,"ORIENT");
909 Float_t thresh=0;
910 om.SetSignal(thresh,"THRESH");
911 Float_t sensit=1;
912 om.SetSignal(sensit,"SENSIT");
913 Float_t readout=0;
914 om.SetSignal(readout,"READOUT");
915 Float_t binsize=0;
916 om.SetSignal(binsize,"BINSIZE");
917 Float_t stopdelay=0;
918 om.SetSignal(stopdelay,"EXTSTOP");
919
920 // Variables needed
921 TSQLStatement* st;
922 IceAOM* omx=0;
923 Int_t omid;
924 Double_t pos[3]={0,0,0};
925 Float_t peArea, twrT0;
926 Int_t jtrans,jrec;
927 Float_t c, b, dlemin, dlemax;
928 TF1* fcal=0;
929 TF1* fdecal=0;
930 NcTimestamp validitystart, validityend;
931 Int_t revision[682];
932
933 // Get positions of Amanda OMs in IceCube coordinates
934 for(omid=0; omid<=681; omid++) revision[omid]=0;
935 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, X, Y, Z, AmandaOm.TypeId, Orientation FROM GeometryOm INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE GeometryOm.StringId=AmandaOm.StringId AND GeometryOm.TubeId=AmandaOm.TubeId AND GeometryOm.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=2;");
936 if (!st)
937 {
938 cout << " *IceDB2Root GetTWRDaqData* Positions could not be read from DB" << endl;
939 }
940 else {
941 st->Process();
942 st->StoreResult();
943 while(st->NextResultRow())
944 {
945 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
946 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
947 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
948 omid=st->GetInt(3);
949 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
950 {
951 revision[omid]=st->GetInt(2);
952 // Get OM, create a new one if necessary
953 omx=(IceAOM*)fTWRDaqdb->GetObject(omid,1);
954 if (!omx)
955 {
956 omx=new IceAOM(om);
957 omx->SetUniqueID(omid);
958 fTWRDaqdb->EnterObject(omid,1,omx);
959 }
960 // Enter calibration values
961 pos[0]=st->GetDouble(4);
962 pos[1]=st->GetDouble(5);
963 pos[2]=st->GetDouble(6);
964 omx->SetPosition(pos,"car");
965 type=(Float_t)st->GetInt(7);
966 omx->SetSignal(type,"TYPE");
967 costh=(Float_t)st->GetInt(8);
968 omx->SetSignal(costh,"ORIENT");
969 }
970 }
971 }
972
973 // Get sensitivity/threshold of Amanda OMs
974 for(omid=0; omid<=681; omid++) revision[omid]=0;
975 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id, sc_sensit, sc_thresh FROM AmandaStatusOm INNER JOIN CalibrationDetail WHERE AmandaStatusOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=804;");
976 if (!st)
977 {
978 cout << " *IceDB2Root GetTWRDaqData* Sensitivity/threshold could not be read from DB" << endl;
979 }
980 else {
981 st->Process();
982 st->StoreResult();
983 while(st->NextResultRow())
984 {
985 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
986 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
987 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
988 omid=st->GetInt(3);
989 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
990 {
991 revision[omid]=st->GetInt(2);
992 // Get OM, create a new one if necessary
993 omx=(IceAOM*)fTWRDaqdb->GetObject(omid,1);
994 if (!omx)
995 {
996 omx=new IceAOM(om);
997 omx->SetUniqueID(omid);
998 fTWRDaqdb->EnterObject(omid,1,omx);
999 }
1000 // Enter calibration values
1001 thresh=(Float_t)st->GetDouble(4);
1002 sensit=(Float_t)st->GetDouble(5);
1003 omx->SetSignal(thresh,"THRESH");
1004 omx->SetSignal(sensit,"SENSIT");
1005 }
1006 }
1007 }
1008
1009 // Get readout types of Amanda OMs
1010 for(omid=0; omid<=681; omid++) revision[omid]=0;
1011 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, CableType FROM AmandaTWRCableType INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE AmandaTWRCableType.StringId=AmandaOm.StringId AND AmandaTWRCableType.TubeId=AmandaOm.TubeId AND AmandaTWRCableType.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=853;");
1012 if (!st)
1013 {
1014 cout << " *IceDB2Root GetTWRDaqData* Readout types could not be read from DB" << endl;
1015 }
1016 else {
1017 st->Process();
1018 st->StoreResult();
1019 while(st->NextResultRow())
1020 {
1021 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1022 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1023 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1024 omid=st->GetInt(3);
1025 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1026 {
1027 revision[omid]=st->GetInt(2);
1028 // Get OM, create a new one if necessary
1029 omx=(IceAOM*)fTWRDaqdb->GetObject(omid,1);
1030 if (!omx)
1031 {
1032 omx=new IceAOM(om);
1033 omx->SetUniqueID(omid);
1034 fTWRDaqdb->EnterObject(omid,1,omx);
1035 }
1036 // Enter calibration values
1037 if(st->GetUInt(4) == 0) readout=1; // Electrical
1038 else if(st->GetUInt(4) == 10) readout=2; // Optical
1039 else readout=0; // Unknown
1040 omx->SetSignal(readout,"READOUT");
1041 }
1042 }
1043 }
1044
1045 // Get bin sizes and stop delays types of TWRs
1046 for(omid=0; omid<=681; omid++) revision[omid]=0;
1047 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, BinSize, StopDelay FROM AmandaTWRStandard INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE AmandaTWRStandard.StringId=AmandaOm.StringId AND AmandaTWRStandard.TubeId=AmandaOm.TubeId AND AmandaTWRStandard.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=852;");
1048 if (!st)
1049 {
1050 cout << " *IceDB2Root GetTWRDaqData* Bin size and stop delays could not be read from DB" << endl;
1051 }
1052 else {
1053 st->Process();
1054 st->StoreResult();
1055 while(st->NextResultRow())
1056 {
1057 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1058 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1059 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1060 omid=st->GetInt(3);
1061 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1062 {
1063 revision[omid]=st->GetInt(2);
1064 // Get OM, create a new one if necessary
1065 omx=(IceAOM*)fTWRDaqdb->GetObject(omid,1);
1066 if (!omx)
1067 {
1068 omx=new IceAOM(om);
1069 omx->SetUniqueID(omid);
1070 fTWRDaqdb->EnterObject(omid,1,omx);
1071 }
1072 // Enter calibration values
1073 binsize=(Float_t)st->GetInt(4);
1074 stopdelay=(Float_t)st->GetInt(5);
1075 omx->SetSignal(binsize,"BINSIZE");
1076 omx->SetSignal(stopdelay,"EXTSTOP");
1077 }
1078 }
1079 }
1080
1081 // Get TWRDaq amplitude and time calibration constants
1082 for(omid=0; omid<=681; omid++) revision[omid]=0;
1083 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, peArea, twrT0 FROM AmandaTWRCalibration INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE AmandaTWRCalibration.StringId=AmandaOm.StringId AND AmandaTWRCalibration.TubeId=AmandaOm.TubeId AND AmandaTWRCalibration.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=854;");
1084 if (!st)
1085 {
1086 cout << " *IceDB2Root GetTWRDaqData* Bin size and stop delays could not be read from DB" << endl;
1087 }
1088 else {
1089 st->Process();
1090 st->StoreResult();
1091 while(st->NextResultRow())
1092 {
1093 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1094 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1095 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1096 omid=st->GetInt(3);
1097 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1098 {
1099 revision[omid]=st->GetInt(2);
1100 // Get OM, create a new one if necessary
1101 omx=(IceAOM*)fTWRDaqdb->GetObject(omid,1);
1102 if (!omx)
1103 {
1104 omx=new IceAOM(om);
1105 omx->SetUniqueID(omid);
1106 fTWRDaqdb->EnterObject(omid,1,omx);
1107 }
1108 // Set calibration functions
1109 omx->SetCalFunction(&fadccal,1);
1110 omx->SetDecalFunction(&fadcdecal,1);
1111 omx->SetCalFunction(&ftdccal,2);
1112 omx->SetDecalFunction(&ftdcdecal,2);
1113 omx->SetCalFunction(&ftotcal,3);
1114 omx->SetDecalFunction(&ftotdecal,3);
1115 // Get calibration values
1116 peArea=(Float_t)st->GetDouble(4);
1117 twrT0=(Float_t)st->GetDouble(5);
1118 // Flag amplitude slots of bad OMs as dead and don't provide amplitude (de)calib functions
1119 if (peArea<=0 || omx->GetSignal("BINSIZE")<=0)
1120 {
1121 omx->SetDead(1);
1122 omx->SetCalFunction(0,1);
1123 omx->SetDecalFunction(0,1);
1124 }
1125 // Set amplitude calibration function parameters
1126 fcal=omx->GetCalFunction(1);
1127 fdecal=omx->GetDecalFunction(1);
1128 if (fcal)
1129 {
1130 // peArea as read from the DB is the factor that converts the integrated
1131 // area under the peak to the number of pe, that is, the sum over all bins
1132 // of ADC*binsize. In IcePack, we simply add up the bin contents of the
1133 // peak, without multiplying by binsize. Hence, the calibration factor is
1134 // peArea/binsize, rather than peArea.
1135 fcal->SetParameter(0,peArea/omx->GetSignal("BINSIZE"));
1136 }
1137 if (fdecal)
1138 {
1139 fdecal->SetParameter(0,peArea/omx->GetSignal("BINSIZE"));
1140 if (!peArea) fdecal->SetParameter(0,1);
1141 }
1142 // Flag LE slots of bad OMs as dead and don't provide time (de)calib functions
1143 if (twrT0<=0)
1144 {
1145 omx->SetDead(2);
1146 omx->SetCalFunction(0,2);
1147 omx->SetDecalFunction(0,2);
1148 }
1149 // Set time calibration function parameters
1150 fcal=omx->GetCalFunction(2);
1151 fdecal=omx->GetDecalFunction(2);
1152 if (fcal)
1153 {
1154 fcal->SetParameter(0,twrT0);
1155 }
1156 if (fdecal)
1157 {
1158 fdecal->SetParameter(0,twrT0);
1159 }
1160 }
1161 }
1162 }
1163
1164 // Get Xtalk probability constants
1165 for(omid=0; omid<=681; omid++) revision[omid]=0;
1166 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_talker_id, om_receiver_id, threshold, width, timelow, timehigh FROM AmandaXtalkOm INNER JOIN CalibrationDetail WHERE AmandaXtalkOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=807;");
1167 if (!st)
1168 {
1169 cout << " *IceDB2Root GetTWRDaqData* Xtalk probability constants could not be read from DB" << endl;
1170 }
1171 else {
1172 st->Process();
1173 st->StoreResult();
1174 while(st->NextResultRow())
1175 {
1176 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1177 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1178 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1179 jtrans=st->GetInt(3);
1180 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1181 {
1182 revision[jtrans]=st->GetInt(2);
1183 jrec=st->GetInt(4);
1184 // Get transmitter OM, create a new one if necessary
1185 omx=(IceAOM*)fTWRDaqdb->GetObject(jtrans,1);
1186 if (!omx)
1187 {
1188 omx=new IceAOM(om);
1189 omx->SetUniqueID(jtrans);
1190 fTWRDaqdb->EnterObject(jtrans,1,omx);
1191 }
1192 // Get calibration values
1193 c=(Float_t)st->GetDouble(5);
1194 b=(Float_t)st->GetDouble(6);
1195 dlemin=(Float_t)st->GetDouble(7);
1196 dlemax=(Float_t)st->GetDouble(8);
1197 // Make Xtalk probability function and set parameters
1198 TF1* fx=new TF1(fxtalkp);
1199 fx->SetParameter(0,c);
1200 if (b) fx->SetParameter(1,b);
1201 else fx->SetParameter(1,1);
1202 fx->SetParameter(2,dlemin);
1203 fx->SetParameter(3,dlemax);
1204 fTWRDaqdb->EnterObject(jtrans,jrec+1,fx);
1205 }
1206 }
1207 }
1208
1209 // Flag OMs in bad OM list as dead
1210 for(omid=0; omid<=681; omid++) revision[omid]=0;
1211 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id FROM AmandaBadOm INNER JOIN CalibrationDetail WHERE AmandaBadOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=803;");
1212 if (!st)
1213 {
1214 cout << " *IceDB2Root GetTWRDaqData* Bad OM list could not be read from DB" << endl;
1215 }
1216 else {
1217 st->Process();
1218 st->StoreResult();
1219 while(st->NextResultRow())
1220 {
1221 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1222 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1223 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1224 omid=st->GetInt(3);
1225 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1226 {
1227 revision[omid]=st->GetInt(2);
1228 // Get OM, create a new one if necessary
1229 omx=(IceAOM*)fTWRDaqdb->GetObject(omid,1);
1230 if (!omx)
1231 {
1232 omx=new IceAOM(om);
1233 omx->SetUniqueID(omid);
1234 fTWRDaqdb->EnterObject(omid,1,omx);
1235 }
1236 // Flag OMs as dead
1237 omx->SetDead(1);
1238 omx->SetCalFunction(0,1);
1239 omx->SetDecalFunction(0,1);
1240 omx->SetDead(2);
1241 omx->SetCalFunction(0,2);
1242 omx->SetDecalFunction(0,2);
1243 omx->SetDead(3);
1244 omx->SetCalFunction(0,3);
1245 omx->SetDecalFunction(0,3);
1246 }
1247 }
1248 }
1249
1250}
1251
1253{
1259
1260 // Connect to the DB server
1261 TSQLServer* server=TSQLServer::Connect(fDBName.Data(),fUser.Data(),fPassword.Data());
1262 if (!server)
1263 {
1264 cout << " *IceDB2Root GetJEBTDaqData* Database " << fDBName.Data() << " could not be accessed." << endl;
1265 return;
1266 }
1267
1268 // The JEBTDaq OM database object
1269 if (fJEBTDaqdb)
1270 {
1271 fJEBTDaqdb->Reset();
1272 }
1273 else
1274 {
1275 fJEBTDaqdb=new NcObjMatrix();
1276 fJEBTDaqdb->SetNameTitle("JEBTDaq-OMDBASE","The JEBTDaq OM geometry, calib. etc... database");
1277 fJEBTDaqdb->SetOwner();
1278 }
1279
1280 // Prescription of the various (de)calibration functions
1281
1282 // Conversion of adc to charge in nC
1283 // Volt per digit = 5/4096 Assumed capacitance = 20 pF
1284 // Charge (in nC) is adc*(5./4096.)*0.02
1285 // The database calibration constant is the amount of nC per photon electron (nC/PE)
1286 TF1 fadccal("fadccal","x*(5./4096.)/(50.*[0])");
1287 TF1 fadcdecal("fadcdecal","x*(50.*[0])/(5./4096.)");
1288 fadccal.SetParName(0,"nC/PE");
1289 fadcdecal.SetParName(0,"nC/PE");
1290
1291 TF1 ftdccal("ftdccal","x-[0]");
1292 TF1 ftdcdecal("ftdcdecal","x+[0]");
1293 ftdccal.SetParName(0,"T0");
1294 ftdcdecal.SetParName(0,"T0");
1295
1296 TF1 ftotcal("ftotcal","x");
1297 TF1 ftotdecal("ftotdecal","x");
1298
1299 // The cross talk probability function
1300 TF1 fxtalkp("fxtalkp","(1.+[2]-[2]+[3]-[3])/(1.+exp(([0]-x)/[1]))");
1301 fxtalkp.SetParName(0,"C");
1302 fxtalkp.SetParName(1,"B");
1303 fxtalkp.SetParName(2,"dLE-min");
1304 fxtalkp.SetParName(3,"dLE-max");
1305
1306 // The basic OM contents
1307 IceAOM om;
1308
1309 // Slots to hold the various (de)calibration functions
1310 om.AddNamedSlot("ADC");
1311 om.AddNamedSlot("LE");
1312 om.AddNamedSlot("TOT");
1313 // Slots with hardware parameters
1314 om.AddNamedSlot("TYPE"); // -1=unknown 0=std_coax 1=std_twisted/std_hybrid 2=desy_hybrid 3=uci_fiber 4=lbl_dom 5=dAOM_ld 6=dAOM_led 9=desy_active_fiber
1315 om.AddNamedSlot("ORIENT");
1316 om.AddNamedSlot("THRESH");
1317 om.AddNamedSlot("SENSIT");
1318 om.AddNamedSlot("READOUT"); // 0=unknown 1=electrical 2=optical 3=digital
1319 om.AddNamedSlot("BINSIZE");
1320 om.AddNamedSlot("EXTSTOP");
1321 om.AddNamedSlot("GLOBALT0");
1322 om.AddNamedSlot("TWRI3OFFSET");
1323
1324 // Default values
1325 Float_t type=-1;
1326 om.SetSignal(type,"TYPE");
1327 Float_t costh=0;
1328 om.SetSignal(costh,"ORIENT");
1329 Float_t thresh=0;
1330 om.SetSignal(thresh,"THRESH");
1331 Float_t sensit=1;
1332 om.SetSignal(sensit,"SENSIT");
1333 Float_t readout=0;
1334 om.SetSignal(readout,"READOUT");
1335 Float_t binsize=0;
1336 om.SetSignal(binsize,"BINSIZE");
1337 Float_t stopdelay=0;
1338 om.SetSignal(stopdelay,"EXTSTOP");
1339 Float_t globalt0=0;
1340 om.SetSignal(globalt0,"GLOBALT0");
1341 Float_t twri3offset=0;
1342 om.SetSignal(twri3offset,"TWRI3OFFSET");
1343
1344 // Variables needed
1345 TSQLStatement* st;
1346 IceAOM* omx=0;
1347 Int_t omid;
1348 Double_t pos[3]={0,0,0};
1349 Float_t peArea, twrT0;
1350 Int_t jtrans,jrec;
1351 Float_t c, b, dlemin, dlemax;
1352 TF1* fcal=0;
1353 TF1* fdecal=0;
1354 NcTimestamp validitystart, validityend;
1355 Int_t revision[682];
1356
1357 // Get global TWR time offsets
1358 st=server->Statement("SELECT TWRGlobalT0, TWRI3TimeOffset FROM AmandaTWRGlobalConstants;");
1359 if (!st)
1360 {
1361 cout << " *IceDB2Root GetJEBTDaqData* Global TWR time offsets could not be read from DB" << endl;
1362 }
1363 else {
1364 st->Process();
1365 st->StoreResult();
1366 st->NextResultRow();
1367 globalt0=st->GetDouble(0);
1368 twri3offset=st->GetDouble(1);
1369 }
1370
1371 // Get positions of Amanda OMs in IceCube coordinates
1372 for(omid=0; omid<=681; omid++) revision[omid]=0;
1373 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, X, Y, Z, AmandaOm.TypeId, Orientation FROM GeometryOm INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE GeometryOm.StringId=AmandaOm.StringId AND GeometryOm.TubeId=AmandaOm.TubeId AND GeometryOm.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=2;");
1374 if (!st)
1375 {
1376 cout << " *IceDB2Root GetJEBTDaqData* Positions could not be read from DB" << endl;
1377 }
1378 else {
1379 st->Process();
1380 st->StoreResult();
1381 while(st->NextResultRow())
1382 {
1383 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1384 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1385 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1386 omid=st->GetInt(3);
1387 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1388 {
1389 revision[omid]=st->GetInt(2);
1390 // Get OM, create a new one if necessary
1391 omx=(IceAOM*)fJEBTDaqdb->GetObject(omid,1);
1392 if (!omx)
1393 {
1394 omx=new IceAOM(om);
1395 omx->SetUniqueID(omid);
1396 fJEBTDaqdb->EnterObject(omid,1,omx);
1397 }
1398 // Enter calibration values
1399 pos[0]=st->GetDouble(4);
1400 pos[1]=st->GetDouble(5);
1401 pos[2]=st->GetDouble(6);
1402 omx->SetPosition(pos,"car");
1403 type=(Float_t)st->GetInt(7);
1404 omx->SetSignal(type,"TYPE");
1405 costh=(Float_t)st->GetInt(8);
1406 omx->SetSignal(costh,"ORIENT");
1407 if(globalt0) omx->SetSignal(globalt0,"GLOBALT0");
1408 if(twri3offset) omx->SetSignal(twri3offset,"TWRI3OFFSET");
1409 }
1410 }
1411 }
1412
1413 // Get sensitivity/threshold of Amanda OMs
1414 for(omid=0; omid<=681; omid++) revision[omid]=0;
1415 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id, sc_sensit, sc_thresh FROM AmandaStatusOm INNER JOIN CalibrationDetail WHERE AmandaStatusOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=804;");
1416 if (!st)
1417 {
1418 cout << " *IceDB2Root GetJEBTDaqData* Sensitivity/threshold could not be read from DB" << endl;
1419 }
1420 else {
1421 st->Process();
1422 st->StoreResult();
1423 while(st->NextResultRow())
1424 {
1425 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1426 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1427 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1428 omid=st->GetInt(3);
1429 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1430 {
1431 revision[omid]=st->GetInt(2);
1432 // Get OM, create a new one if necessary
1433 omx=(IceAOM*)fJEBTDaqdb->GetObject(omid,1);
1434 if (!omx)
1435 {
1436 omx=new IceAOM(om);
1437 omx->SetUniqueID(omid);
1438 fJEBTDaqdb->EnterObject(omid,1,omx);
1439 }
1440 // Enter calibration values
1441 thresh=(Float_t)st->GetDouble(4);
1442 sensit=(Float_t)st->GetDouble(5);
1443 omx->SetSignal(thresh,"THRESH");
1444 omx->SetSignal(sensit,"SENSIT");
1445 }
1446 }
1447 }
1448
1449 // Get readout types of Amanda OMs
1450 for(omid=0; omid<=681; omid++) revision[omid]=0;
1451 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, CableType FROM AmandaTWRCableType INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE AmandaTWRCableType.StringId=AmandaOm.StringId AND AmandaTWRCableType.TubeId=AmandaOm.TubeId AND AmandaTWRCableType.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=853;");
1452 if (!st)
1453 {
1454 cout << " *IceDB2Root GetJEBTDaqData* Readout types could not be read from DB" << endl;
1455 }
1456 else {
1457 st->Process();
1458 st->StoreResult();
1459 while(st->NextResultRow())
1460 {
1461 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1462 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1463 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1464 omid=st->GetInt(3);
1465 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1466 {
1467 revision[omid]=st->GetInt(2);
1468 // Get OM, create a new one if necessary
1469 omx=(IceAOM*)fJEBTDaqdb->GetObject(omid,1);
1470 if (!omx)
1471 {
1472 omx=new IceAOM(om);
1473 omx->SetUniqueID(omid);
1474 fJEBTDaqdb->EnterObject(omid,1,omx);
1475 }
1476 // Enter calibration values
1477 if(st->GetUInt(4) == 0) readout=1; // Electrical
1478 else if(st->GetUInt(4) == 10) readout=2; // Optical
1479 else readout=0; // Unknown
1480 omx->SetSignal(readout,"READOUT");
1481 }
1482 }
1483 }
1484
1485 // Get bin sizes and stop delays types of TWRs
1486 for(omid=0; omid<=681; omid++) revision[omid]=0;
1487 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, BinSize, StopDelay FROM AmandaTWRStandard INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE AmandaTWRStandard.StringId=AmandaOm.StringId AND AmandaTWRStandard.TubeId=AmandaOm.TubeId AND AmandaTWRStandard.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=852;");
1488 if (!st)
1489 {
1490 cout << " *IceDB2Root GetJEBTDaqData* Bin size and stop delays could not be read from DB" << endl;
1491 }
1492 else {
1493 st->Process();
1494 st->StoreResult();
1495 while(st->NextResultRow())
1496 {
1497 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1498 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1499 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1500 omid=st->GetInt(3);
1501 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1502 {
1503 revision[omid]=st->GetInt(2);
1504 // Get OM, create a new one if necessary
1505 omx=(IceAOM*)fJEBTDaqdb->GetObject(omid,1);
1506 if (!omx)
1507 {
1508 omx=new IceAOM(om);
1509 omx->SetUniqueID(omid);
1510 fJEBTDaqdb->EnterObject(omid,1,omx);
1511 }
1512 // Enter calibration values
1513 binsize=(Float_t)st->GetInt(4);
1514 stopdelay=(Float_t)st->GetInt(5);
1515 omx->SetSignal(binsize,"BINSIZE");
1516 omx->SetSignal(stopdelay,"EXTSTOP");
1517 }
1518 }
1519 }
1520
1521 // Get JEBTDaq amplitude and time calibration constants
1522 for(omid=0; omid<=681; omid++) revision[omid]=0;
1523 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, OmId, peArea, twrT0 FROM AmandaTWRCalibration INNER JOIN AmandaOm INNER JOIN CalibrationDetail WHERE AmandaTWRCalibration.StringId=AmandaOm.StringId AND AmandaTWRCalibration.TubeId=AmandaOm.TubeId AND AmandaTWRCalibration.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=854;");
1524 if (!st)
1525 {
1526 cout << " *IceDB2Root GetJEBTDaqData* Bin size and stop delays could not be read from DB" << endl;
1527 }
1528 else {
1529 st->Process();
1530 st->StoreResult();
1531 while(st->NextResultRow())
1532 {
1533 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1534 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1535 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1536 omid=st->GetInt(3);
1537 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1538 {
1539 revision[omid]=st->GetInt(2);
1540 // Get OM, create a new one if necessary
1541 omx=(IceAOM*)fJEBTDaqdb->GetObject(omid,1);
1542 if (!omx)
1543 {
1544 omx=new IceAOM(om);
1545 omx->SetUniqueID(omid);
1546 fJEBTDaqdb->EnterObject(omid,1,omx);
1547 }
1548 // Set calibration functions
1549 omx->SetCalFunction(&fadccal,1);
1550 omx->SetDecalFunction(&fadcdecal,1);
1551 omx->SetCalFunction(&ftdccal,2);
1552 omx->SetDecalFunction(&ftdcdecal,2);
1553 omx->SetCalFunction(&ftotcal,3);
1554 omx->SetDecalFunction(&ftotdecal,3);
1555 // Get calibration values
1556 peArea=(Float_t)st->GetDouble(4);
1557 twrT0=(Float_t)st->GetDouble(5);
1558 // Flag amplitude slots of bad OMs as dead and don't provide amplitude (de)calib functions
1559 if (peArea<=0 || omx->GetSignal("BINSIZE")<=0)
1560 {
1561 omx->SetDead(1);
1562 omx->SetCalFunction(0,1);
1563 omx->SetDecalFunction(0,1);
1564 }
1565 // Set amplitude calibration function parameters
1566 fcal=omx->GetCalFunction(1);
1567 fdecal=omx->GetDecalFunction(1);
1568 if (fcal)
1569 {
1570 // peArea as read from the DB is the factor that converts the integrated
1571 // area under the peak to the number of pe, that is, the sum over all bins
1572 // of ADC*binsize. In IcePack, we simply add up the bin contents of the
1573 // peak, without multiplying by binsize. Hence, the calibration factor is
1574 // peArea/binsize, rather than peArea.
1575 fcal->SetParameter(0,peArea/omx->GetSignal("BINSIZE"));
1576 }
1577 if (fdecal)
1578 {
1579 fdecal->SetParameter(0,peArea/omx->GetSignal("BINSIZE"));
1580 if (!peArea) fdecal->SetParameter(0,1);
1581 }
1582 // Flag LE slots of bad OMs as dead and don't provide time (de)calib functions
1583 if (twrT0<=0)
1584 {
1585 omx->SetDead(2);
1586 omx->SetCalFunction(0,2);
1587 omx->SetDecalFunction(0,2);
1588 }
1589 // Set time calibration function parameters
1590 fcal=omx->GetCalFunction(2);
1591 fdecal=omx->GetDecalFunction(2);
1592 if (fcal)
1593 {
1594 fcal->SetParameter(0,twrT0);
1595 }
1596 if (fdecal)
1597 {
1598 fdecal->SetParameter(0,twrT0);
1599 }
1600 }
1601 }
1602 }
1603
1604 // Get Xtalk probability constants
1605 for(omid=0; omid<=681; omid++) revision[omid]=0;
1606 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_talker_id, om_receiver_id, threshold, width, timelow, timehigh FROM AmandaXtalkOm INNER JOIN CalibrationDetail WHERE AmandaXtalkOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=807;");
1607 if (!st)
1608 {
1609 cout << " *IceDB2Root GetJEBTDaqData* Xtalk probability constants could not be read from DB" << endl;
1610 }
1611 else {
1612 st->Process();
1613 st->StoreResult();
1614 while(st->NextResultRow())
1615 {
1616 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1617 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1618 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1619 jtrans=st->GetInt(3);
1620 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1621 {
1622 revision[jtrans]=st->GetInt(2);
1623 jrec=st->GetInt(4);
1624 // Get transmitter OM, create a new one if necessary
1625 omx=(IceAOM*)fJEBTDaqdb->GetObject(jtrans,1);
1626 if (!omx)
1627 {
1628 omx=new IceAOM(om);
1629 omx->SetUniqueID(jtrans);
1630 fJEBTDaqdb->EnterObject(jtrans,1,omx);
1631 }
1632 // Get calibration values
1633 c=(Float_t)st->GetDouble(5);
1634 b=(Float_t)st->GetDouble(6);
1635 dlemin=(Float_t)st->GetDouble(7);
1636 dlemax=(Float_t)st->GetDouble(8);
1637 // Make Xtalk probability function and set parameters
1638 TF1* fx=new TF1(fxtalkp);
1639 fx->SetParameter(0,c);
1640 if (b) fx->SetParameter(1,b);
1641 else fx->SetParameter(1,1);
1642 fx->SetParameter(2,dlemin);
1643 fx->SetParameter(3,dlemax);
1644 fJEBTDaqdb->EnterObject(jtrans,jrec+1,fx);
1645 }
1646 }
1647 }
1648
1649 // Flag OMs in bad OM list as dead
1650 for(omid=0; omid<=681; omid++) revision[omid]=0;
1651 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, om_id FROM AmandaBadOm INNER JOIN CalibrationDetail WHERE AmandaBadOm.ca_id=CalibrationDetail.CaId AND CalibrationDetail.TypeId=803;");
1652 if (!st)
1653 {
1654 cout << " *IceDB2Root GetJEBTDaqData* Bad OM list could not be read from DB" << endl;
1655 }
1656 else {
1657 st->Process();
1658 st->StoreResult();
1659 while(st->NextResultRow())
1660 {
1661 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1662 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1663 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1664 omid=st->GetInt(3);
1665 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1666 {
1667 revision[omid]=st->GetInt(2);
1668 // Get OM, create a new one if necessary
1669 omx=(IceAOM*)fJEBTDaqdb->GetObject(omid,1);
1670 if (!omx)
1671 {
1672 omx=new IceAOM(om);
1673 omx->SetUniqueID(omid);
1674 fJEBTDaqdb->EnterObject(omid,1,omx);
1675 }
1676 // Flag OMs as dead
1677 omx->SetDead(1);
1678 omx->SetCalFunction(0,1);
1679 omx->SetDecalFunction(0,1);
1680 omx->SetDead(2);
1681 omx->SetCalFunction(0,2);
1682 omx->SetDecalFunction(0,2);
1683 omx->SetDead(3);
1684 omx->SetCalFunction(0,3);
1685 omx->SetDecalFunction(0,3);
1686 }
1687 }
1688 }
1689
1690}
1691
1693{
1699
1700 // Connect to the DB server
1701 TSQLServer* server=TSQLServer::Connect(fDBName.Data(),fUser.Data(),fPassword.Data());
1702 if (!server)
1703 {
1704 cout << " *IceDB2Root GetJEBADaqData* Database " << fDBName.Data() << " could not be accessed." << endl;
1705 return;
1706 }
1707
1708 // The JEBADaq OM database object
1709 if (fJEBADaqdb)
1710 {
1711 fJEBADaqdb->Reset();
1712 }
1713 else
1714 {
1715 fJEBADaqdb=new NcObjMatrix();
1716 fJEBADaqdb->SetNameTitle("JEBADaq-OMDBASE","The JEBADaq OM geometry, calib. etc... database");
1717 fJEBADaqdb->SetOwner();
1718 }
1719
1720 // Prescription of the various (de)calibration functions
1721 TF1 fadccal("fadccal","x*[0]");
1722 TF1 fadcdecal("fadcdecal","x/[0]");
1723 fadccal.SetParName(0,"ADC-SLOPE");
1724 fadcdecal.SetParName(0,"ADC-SLOPE");
1725
1726 TF1 ftdccal("ftdccal","x");
1727 TF1 ftdcdecal("ftdcdecal","x");
1728
1729 TF1 ftotcal("ftotcal","x");
1730 TF1 ftotdecal("ftotdecal","x");
1731
1732 // The basic OM contents
1733 IceDOM om;
1734
1735 // Slots to hold the various (de)calibration functions
1736 om.AddNamedSlot("ADC");
1737 om.AddNamedSlot("LE");
1738 om.AddNamedSlot("TOT");
1739 // Slots with hardware parameters
1740 om.AddNamedSlot("ORIENT");
1741
1742 // Default values
1743 Float_t costh=0;
1744 om.SetSignal(costh,"ORIENT");
1745
1746 // Variables needed
1747 TSQLStatement* st;
1748 IceDOM* omx=0;
1749 Int_t omid;
1750 Double_t pos[3]={0,0,0};
1751//@@@ TODO: declare these variables once amplitude calibration becomes available
1752// Float_t peArea;
1753// TF1* fcal=0;
1754// TF1* fdecal=0;
1755 NcTimestamp validitystart, validityend;
1756
1757 // Find maximum OM ID and initialise revision array
1758 Int_t maxomid=0;
1759 st=server->Statement("SELECT MAX(StringId), MAX(TubeId) FROM GeometryOm INNER JOIN CalibrationDetail WHERE StringId>0 AND GeometryOm.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=2;");
1760 if (!st)
1761 {
1762 cout << " *IceDB2Root2 GetJEBADaqData* Maximum string and tube numbers could not be read from DB" << endl;
1763 }
1764 else {
1765 st->Process();
1766 st->StoreResult();
1767 st->NextResultRow();
1768 maxomid=om.GetOMId(st->GetInt(0),st->GetInt(1));
1769 }
1770 if(!maxomid)
1771 {
1772 cout << " *IceDB2Root2 GetJEBADaqData* Maximum OM ID could not be read from DB" << endl;
1773 return;
1774 }
1775 Int_t* revision=new Int_t[maxomid+1];
1776
1777 // Get positions of IceCube DOMs in IceCube coordinates
1778 for(omid=0; omid<=maxomid; omid++) revision[omid]=0;
1779 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, StringId, TubeId, X, Y, Z, Orientation FROM GeometryOm INNER JOIN CalibrationDetail WHERE StringId>0 AND GeometryOm.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=2;");
1780 if (!st)
1781 {
1782 cout << " *IceDB2Root GetJEBADaqData* Positions could not be read from DB" << endl;
1783 }
1784 else {
1785 st->Process();
1786 st->StoreResult();
1787 while(st->NextResultRow())
1788 {
1789 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1790 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1791 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1792 omid=om.GetOMId(st->GetInt(3),st->GetInt(4));
1793 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1794 {
1795 revision[omid]=st->GetInt(2);
1796 // Get OM, create a new one if necessary
1797 omx=(IceDOM*)fJEBADaqdb->GetObject(omid,1);
1798 if (!omx)
1799 {
1800 omx=new IceDOM(om);
1801 omx->SetUniqueID(omid);
1802 fJEBADaqdb->EnterObject(omid,1,omx);
1803 }
1804 // Enter calibration values
1805 pos[0]=st->GetDouble(5);
1806 pos[1]=st->GetDouble(6);
1807 pos[2]=st->GetDouble(7);
1808 omx->SetPosition(pos,"car");
1809 costh=(Float_t)st->GetInt(8);
1810 omx->SetSignal(costh,"ORIENT");
1811 }
1812 }
1813 }
1814
1815 // Get JEBADaq amplitude calibration constants
1816 //@@@ TODO: Insert correct table and field names and use correct calibration type
1817 /*
1818 for(omid=0; omid<=maxomid; omid++) revision[omid]=0;
1819 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, StringId, TubeId, XXXpeArea FROM XXXampl INNER JOIN CalibrationDetail WHERE StringId>0 AND XXXampl.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=XXX;");
1820 if (!st)
1821 {
1822 cout << " *IceDB2Root GetJEBADaqData* Amplitude calibrations could not be read from DB" << endl;
1823 }
1824 else {
1825 st->Process();
1826 st->StoreResult();
1827 while(st->NextResultRow())
1828 {
1829 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1830 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1831 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1832 omid=om.GetOMId(st->GetInt(3),st->GetInt(4));
1833 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1834 {
1835 revision[omid]=st->GetInt(2);
1836 // Get OM, create a new one if necessary
1837 omx=(IceDOM*)fJEBADaqdb->GetObject(omid,1);
1838 if (!omx)
1839 {
1840 omx=new IceDOM(om);
1841 omx->SetUniqueID(omid);
1842 fJEBADaqdb->EnterObject(omid,1,omx);
1843 }
1844 // Set calibration functions
1845 omx->SetCalFunction(&fadccal,1);
1846 omx->SetDecalFunction(&fadcdecal,1);
1847 // Get calibration values
1848 peArea=(Float_t)st->GetDouble(5);
1849 // Flag amplitude slots of bad OMs as dead and don't provide amplitude (de)calib functions
1850 //@@@ TODO: Set correct conditions
1851 if (peArea<=0)
1852 {
1853 omx->SetDead(1);
1854 omx->SetCalFunction(0,1);
1855 omx->SetDecalFunction(0,1);
1856 }
1857 // Set calibration function parameters
1858 fcal=omx->GetCalFunction(1);
1859 fdecal=omx->GetDecalFunction(1);
1860 if (fcal)
1861 {
1862 fcal->SetParameter(0,peArea);
1863 }
1864 if (fdecal)
1865 {
1866 fdecal->SetParameter(0,peArea);
1867 if (!peArea) fdecal->SetParameter(0,1);
1868 }
1869 }
1870 }
1871 }
1872 */
1873
1874 /*
1875 // Flag OMs in bad OM list as dead
1876 //@@@ TODO: Insert correct table and field names and use correct calibration type
1877 for(omid=0; omid<=maxomid; omid++) revision[omid]=0;
1878 st=server->Statement("SELECT ValidityStartDate, ValidityEndDate, RevisionId, StringId, TubeId FROM XXXBadOm INNER JOIN CalibrationDetail WHERE StringId>0 AND XXXBadOm.CaId=CalibrationDetail.CaId AND CalibrationDetail.TypeId=XXX;");
1879 if (!st)
1880 {
1881 cout << " *IceDB2Root GetJEBADaqData* Bad OM list could not be read from DB" << endl;
1882 }
1883 else {
1884 st->Process();
1885 st->StoreResult();
1886 while(st->NextResultRow())
1887 {
1888 // Only get calibrations with correct validity range, and update with latest revision in case of several valid calibrations
1889 validitystart.SetUT(st->GetYear(0),st->GetMonth(0),st->GetDay(0),st->GetHour(0),st->GetMinute(0),st->GetSecond(0));
1890 validityend.SetUT(st->GetYear(1),st->GetMonth(1),st->GetDay(1),st->GetHour(1),st->GetMinute(1),st->GetSecond(1));
1891 omid=om.GetOMId(st->GetInt(3),st->GetInt(4));
1892 if(validitystart.GetDifference(fTime,"d",1)>0 && validityend.GetDifference(fTime,"d",1)<0 && st->GetInt(2) > revision[omid])
1893 {
1894 revision[omid]=st->GetInt(2);
1895 // Get OM, create a new one if necessary
1896 omx=(IceDOM*)fJEBADaqdb->GetObject(omid,1);
1897 if (!omx)
1898 {
1899 omx=new IceDOM(om);
1900 omx->SetUniqueID(omid);
1901 fJEBADaqdb->EnterObject(omid,1,omx);
1902 }
1903 // Flag OMs as dead
1904 omx->SetDead(1);
1905 omx->SetCalFunction(0,1);
1906 omx->SetDecalFunction(0,1);
1907 omx->SetDead(2);
1908 omx->SetCalFunction(0,2);
1909 omx->SetDecalFunction(0,2);
1910 omx->SetDead(3);
1911 omx->SetCalFunction(0,3);
1912 omx->SetDecalFunction(0,3);
1913 }
1914 }
1915 }
1916 */
1917
1918 if (revision) delete[] revision;
1919
1920}
1921
ClassImp(IceDB2Root)
Signal (Hit) handling of a generic Amanda Optical Module (AOM).
Definition IceAOM.h:12
Job for extracting calibration data from database and storing them into an NcObjMatrix OM dbase.
Definition IceDB2Root.h:22
NcObjMatrix * fJEBTDaqdb
Definition IceDB2Root.h:45
NcTimestamp fTime
Definition IceDB2Root.h:40
void GetMuDaqData()
NcObjMatrix * fTWRDaqdb
Definition IceDB2Root.h:44
void GetJEBTDaqData()
void GetTWRDaqData()
void SetOutputFile(TString name)
NcObjMatrix * fJEBADaqdb
Definition IceDB2Root.h:46
void GetJEBADaqData()
TDatabasePDG * GetPDG()
TString fRootFileName
Definition IceDB2Root.h:38
TDatabasePDG * fPdg
Definition IceDB2Root.h:42
void SetUT(Int_t y, Int_t m, Int_t d, Int_t hh=0, Int_t mm=0, Int_t ss=0)
virtual void Exec(Option_t *opt)
TString fDBName
Definition IceDB2Root.h:35
NcObjMatrix * GetOMdbase(TString name="MuDaq")
TString fPassword
Definition IceDB2Root.h:37
void SetDatabase(TString name, TString user, TString password="")
TFile * fOutfile
Definition IceDB2Root.h:39
IceDB2Root(const char *name="IceDB2Root", const char *title="")
NcTimestamp GetTime()
virtual ~IceDB2Root()
NcObjMatrix * fMuDaqdb
Definition IceDB2Root.h:43
TString fUser
Definition IceDB2Root.h:36
Signal (Hit) handling of a generic IceCube Digital Optical Module (DOM).
Definition IceDOM.h:12
Int_t GetOMId(Int_t string, Int_t level) const
Definition IceGOM.cxx:266
void SetCalFunction(TF1 *f, Int_t j=1)
void AddNamedSlot(TString s)
void SetDecalFunction(TF1 *f, Int_t j=1)
TF1 * GetCalFunction(Int_t j=1) const
void SetDead(Int_t j=1)
Definition NcAttrib.cxx:886
TF1 * GetDecalFunction(Int_t j=1) const
void AddObject(TObject *obj)
Definition NcJob.cxx:320
NcJob(const char *name="NcJob", const char *title="")
Definition NcJob.cxx:139
void ListEnvironment()
Definition NcJob.cxx:205
Handling of a matrix structure of objects.
Definition NcObjMatrix.h:13
void SetPosition(Double_t *r, TString f, TString u="rad")
virtual void SetSignal(Double_t sig, Int_t j=1)
Definition NcSignal.cxx:516
virtual Float_t GetSignal(Int_t j=1, Int_t mode=0) const
Definition NcSignal.cxx:651
Handling of timestamps for (astro)particle physics research.
Definition NcTimestamp.h:20
void SetUT(Int_t y, Int_t m, Int_t d, Int_t hh, Int_t mm, Int_t ss, Int_t ns=0, Int_t ps=0, TString utc="A", Int_t leap=0, Double_t dut=0)
Int_t GetDifference(NcTimestamp *t, Int_t &days, Int_t &sec, Int_t &ns, Int_t &ps, TString type="UT")