NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
IceCal2Root.cxx
Go to the documentation of this file.
1
17
19
172
173#include "IceCal2Root.h"
174#include "Rstrstream.h"
175
176ClassImp(IceCal2Root); // Class implementation to enable ROOT I/O
177
178IceCal2Root::IceCal2Root(const char* name,const char* title) : NcJob(name,title)
179{
187 fRootFileName="";
188 fOutfile=0;
189
190 fPdg=0;
191 fMuDaqdb=0;
192 fTWRDaqdb=0;
193}
194
196{
202
203 if (fPdg)
204 {
205 delete fPdg;
206 fPdg=0;
207 }
208
209 if (fMuDaqdb)
210 {
211 delete fMuDaqdb;
212 fMuDaqdb=0;
213 }
214
215 if (fTWRDaqdb)
216 {
217 delete fTWRDaqdb;
218 fTWRDaqdb=0;
219 }
220}
221
223{
229 fAmacalFileName=name;
230}
231
233{
239 fTWRDaqFileName=name;
240}
241
243{
249 fRootFileName=name;
250}
251
252TDatabasePDG* IceCal2Root::GetPDG()
253{
259 return fPdg;
260}
261
263{
271
272 if (name=="MuDaq") return fMuDaqdb;
273 if (name=="TWRDaq") return fTWRDaqdb;
274 return 0;
275}
276
277void IceCal2Root::Exec(Option_t* opt)
278{
297
298 if (fOutfile)
299 {
300 delete fOutfile;
301 fOutfile=0;
302 }
303 if (fRootFileName != "")
304 {
305 fOutfile=new TFile(fRootFileName.Data(),"RECREATE","Calibration data in IcePack structure");
306 }
307
308 // Create the particle database and extend it with some F2000 specific definitions
309 if (fPdg) delete fPdg;
310 fPdg=new TDatabasePDG();
311 fPdg->SetNameTitle("PDG-DBASE","The extended PDG particle database");
312 Double_t me=fPdg->GetParticle(11)->Mass();
313 fPdg->AddParticle("brems" ,"brems" ,0,1,0,0,"none",10001001,0,0);
314 fPdg->AddParticle("deltae" ,"deltae" ,me,1,0,-3,"Lepton",10001002,0,0);
315 fPdg->AddParticle("pairprod","pairprod",0,1,0,0,"none",10001003,0,0);
316 fPdg->AddParticle("nucl_int","nucl_Int",0,1,0,0,"none",10001004,0,0);
317 fPdg->AddParticle("mu_pair" ,"mu_pair" ,0,1,0,0,"none",10001005,0,0);
318 fPdg->AddParticle("hadrons" ,"hadrons" ,0,1,0,0,"none",10001006,0,0);
319 fPdg->AddParticle("fiberlaser","fiberlaser",0,1,0,0,"none",10002100,0,0);
320 fPdg->AddParticle("n2laser" ,"n2laser" ,0,1,0,0,"none",10002101,0,0);
321 fPdg->AddParticle("yaglaser" ,"yaglaser" ,0,1,0,0,"none",10002201,0,0);
322 fPdg->AddParticle("z_primary","z_primary",0,1,0,0,"none",10003000,0,0);
323 fPdg->AddParticle("a_primary","a_primary",0,1,0,0,"none",10003500,0,0);
324
325 // Initialise the job working environment
328
329 cout << " ***" << endl;
330 cout << " *** Start processing of job " << GetName() << " ***" << endl;
331 cout << " ***" << endl;
332 cout << " Amacalib MuDaq input file : " << fAmacalFileName.Data() << endl;
333 cout << " TWRDaq input file : " << fTWRDaqFileName.Data() << endl;
334 if (fOutfile) cout << " ROOT output file : " << fOutfile->GetName() << endl;
335
336 GetMuDaqData();
338
341
343
344 // Invoke all available sub-tasks (if any)
345 CleanTasks();
346 ExecuteTasks(opt);
347
348 // Write the datastructures to the output file
349 if (fOutfile)
350 {
351 fOutfile->cd();
352 if (fMuDaqdb) fMuDaqdb->Write();
353 if (fTWRDaqdb) fTWRDaqdb->Write();
354 if (fPdg) fPdg->Write();
355 }
356
357 // Flush remaining memory resident data to the output file
358 if (fOutfile) fOutfile->Write();
359}
360
362{
368
369 if (fAmacalFileName=="")
370 {
371 cout << " *IceCal2Root GetMuDaqData* No amacalib input file specified." << endl;
372 return;
373 }
374
375 fInput.clear();
376 fInput.open(fAmacalFileName.Data());
377
378 if (!fInput.good())
379 {
380 cout << " *IceCal2Root GetMuDaqData* Bad input file : " << fAmacalFileName.Data() << endl;
381 return;
382 }
383
384 // The MuDaq OM database object
385 if (fMuDaqdb)
386 {
387 fMuDaqdb->Reset();
388 }
389 else
390 {
391 fMuDaqdb=new NcObjMatrix();
392 fMuDaqdb->SetNameTitle("MuDaq-OMDBASE","The MuDaq OM geometry, calib. etc... database");
393 fMuDaqdb->SetOwner();
394 }
395
396 // Prescription of the various (de)calibration functions
397 TF1 fadccal("fadccal","(x-[1])*[0]");
398 TF1 fadcdecal("fadcdecal","(x/[0])+[1]");
399 fadccal.SetParName(0,"BETA-ADC");
400 fadccal.SetParName(1,"PED-ADC");
401 fadcdecal.SetParName(0,"BETA-ADC");
402 fadcdecal.SetParName(1,"PED-ADC");
403
404 TF1 ftdccal("ftdccal","(x*[0])-[1]-([0]-1.)*32767.-[2]/sqrt([3])");
405 TF1 ftdcdecal("ftdcdecal","(x+([0]-1.)*32767.+[1]+[2]/sqrt([3]))/[0]");
406 ftdccal.SetParName(0,"BETA-TDC");
407 ftdccal.SetParName(1,"T0");
408 ftdccal.SetParName(2,"ALPHA-TDC");
409 ftdccal.SetParName(3,"ADC-SLEW");
410 ftdcdecal.SetParName(0,"BETA-TDC");
411 ftdcdecal.SetParName(1,"T0");
412 ftdcdecal.SetParName(2,"ALPHA-TDC");
413 ftdcdecal.SetParName(3,"ADC-SLEW");
414
415 TF1 ftotcal("ftotcal","x*[0]");
416 TF1 ftotdecal("ftotdecal","x/[0]");
417 ftotcal.SetParName(0,"BETA-TOT");
418 ftotdecal.SetParName(0,"BETA-TOT");
419
420 // The cross talk probability function
421 TF1 fxtalkp("fxtalkp","(1.+[2]-[2]+[3]-[3])/(1.+exp(([0]-x)/[1]))");
422 fxtalkp.SetParName(0,"C");
423 fxtalkp.SetParName(1,"B");
424 fxtalkp.SetParName(2,"dLE-min");
425 fxtalkp.SetParName(3,"dLE-max");
426
427 // The basic OM contents
428 IceAOM om;
429
430 // Slots to hold the various (de)calibration functions
431 om.AddNamedSlot("ADC");
432 om.AddNamedSlot("LE");
433 om.AddNamedSlot("TOT");
434 // Slots with hardware parameters
435 om.AddNamedSlot("TYPE");
436 om.AddNamedSlot("ORIENT");
437//@@@ om.AddNamedSlot("THRESH");
438//@@@ om.AddNamedSlot("SENSIT");
439//@@@ om.AddNamedSlot("READOUT"); // 0=unknown 1=electrical 2=optical 3=digital
440
441 fInput.seekg(0); // Position at beginning of file
442 fInput >> dec; // Make sure all integers starting with 0 are taken in decimal format
443
444 TString s;
445 Int_t jmod,type,serial,string,ix,iy,iz,ori;
446 Float_t costh=0;
447//@@@ Float_t thresh=0;
448//@@@ Float_t sensit=1;
449//@@@ Float_t readout=0;
450 Double_t pos[3]={0,0,0};
451 Float_t ped,beta,alpha;
452 Int_t pol;
453 Float_t totped;
454 Int_t jtrans,jrec;
455 Float_t c,b,dlemin,dlemax;
456 IceAOM* omx=0;
457 TF1* fcal=0;
458 TF1* fdecal=0;
459 while (fInput >> s)
460 {
461 if (s == "P") // Read the Geom data
462 {
463 fInput >> jmod >> type >> serial >> string >> ix >> iy >> iz >> ori;
464 omx=(IceAOM*)fMuDaqdb->GetObject(jmod,1);
465 if (!omx)
466 {
467 omx=new IceAOM(om);
468 omx->SetUniqueID(jmod);
469 fMuDaqdb->EnterObject(jmod,1,omx);
470 }
471 pos[0]=double(ix)/1000.;
472 pos[1]=double(iy)/1000.;
473 pos[2]=double(iz)/1000.;
474 omx->SetPosition(pos,"car");
475 costh=1;
476 if (ori==2) costh=-1;
477 omx->SetSignal(type,"TYPE");
478 omx->SetSignal(costh,"ORIENT");
479//@@@ omx->SetSignal(thresh,"THRESH");
480//@@@ omx->SetSignal(sensit,"SENSIT");
481//@@@ omx->SetSignal(readout,"READOUT");
482 }
483 else if (s == "T") // Read the Time calibration constants
484 {
485 fInput >> jmod >> ped >> beta >> alpha >> pol;
486 omx=(IceAOM*)fMuDaqdb->GetObject(jmod,1);
487 if (!omx)
488 {
489 omx=new IceAOM(om);
490 omx->SetUniqueID(jmod);
491 fMuDaqdb->EnterObject(jmod,1,omx);
492 }
493
494 omx->SetCalFunction(&ftdccal,"LE");
495 omx->SetDecalFunction(&ftdcdecal,"LE");
496 omx->SetCalFunction(&ftotcal,"TOT");
497 omx->SetDecalFunction(&ftotdecal,"TOT");
498
499 // Flag time slots of bad OMs as dead and don't provide time (de)calib functions
500 if (ped<-1e5 || beta<=0 || alpha<0)
501 {
502 omx->SetDead("LE");
503 omx->SetDead("TOT");
504 omx->SetCalFunction(0,"LE");
505 omx->SetDecalFunction(0,"LE");
506 omx->SetCalFunction(0,"TOT");
507 omx->SetDecalFunction(0,"TOT");
508 }
509
510 fcal=omx->GetCalFunction("LE");
511 fdecal=omx->GetDecalFunction("LE");
512 if (fcal)
513 {
514 fcal->SetParameter(0,beta);
515 fcal->SetParameter(1,ped);
516 fcal->SetParameter(2,alpha);
517 fcal->SetParameter(3,1.e20);
518 }
519 if (fdecal)
520 {
521 fdecal->SetParameter(0,beta);
522 if (!beta) fdecal->SetParameter(0,1);
523 fdecal->SetParameter(1,ped);
524 fdecal->SetParameter(2,alpha);
525 fdecal->SetParameter(3,1.e20);
526 }
527
528 fcal=omx->GetCalFunction("TOT");
529 fdecal=omx->GetDecalFunction("TOT");
530 if (fcal)
531 {
532 fcal->SetParameter(0,beta);
533 }
534 if (fdecal)
535 {
536 fdecal->SetParameter(0,beta);
537 }
538 }
539 else if (s == "A") // Read the Amplitude calibration constants
540 {
541 fInput >> jmod >> ped >> beta >> totped >> pol;
542 omx=(IceAOM*)fMuDaqdb->GetObject(jmod,1);
543 if (!omx)
544 {
545 omx=new IceAOM(om);
546 omx->SetUniqueID(jmod);
547 fMuDaqdb->EnterObject(jmod,1,omx);
548 }
549
550 omx->SetCalFunction(&fadccal,"ADC");
551 omx->SetDecalFunction(&fadcdecal,"ADC");
552
553 // Flag amplitude slots of bad OMs as dead and don't provide amplitude (de)calib functions
554 if (ped<-1e5 || beta<=0)
555 {
556 omx->SetDead("ADC");
557 omx->SetCalFunction(0,"ADC");
558 omx->SetDecalFunction(0,"ADC");
559 }
560 if (totped<-1e5)
561 {
562 omx->SetDead("TOT");
563 omx->SetCalFunction(0,"TOT");
564 omx->SetDecalFunction(0,"TOT");
565 }
566
567 fcal=omx->GetCalFunction("ADC");
568 fdecal=omx->GetDecalFunction("ADC");
569 if (fcal)
570 {
571 fcal->SetParameter(0,beta);
572 fcal->SetParameter(1,ped);
573 }
574 if (fdecal)
575 {
576 fdecal->SetParameter(0,beta);
577 if (!beta) fdecal->SetParameter(0,1);
578 fdecal->SetParameter(1,ped);
579 }
580 }
581 else if (s == "K") // Read the cross talk probability constants
582 {
583 fInput >> jtrans >> jrec >> c >> b >> dlemin >> dlemax;
584 omx=(IceAOM*)fMuDaqdb->GetObject(jtrans,1);
585 if (!omx)
586 {
587 omx=new IceAOM(om);
588 omx->SetUniqueID(jtrans);
589 fMuDaqdb->EnterObject(jtrans,1,omx);
590 }
591
592 TF1* fx=new TF1(fxtalkp);
593 fx->SetParameter(0,c);
594 if (b)
595 {
596 fx->SetParameter(1,b);
597 }
598 else
599 {
600 fx->SetParameter(1,1);
601 }
602 fx->SetParameter(2,dlemin);
603 fx->SetParameter(3,dlemax);
604 fMuDaqdb->EnterObject(jtrans,jrec+1,fx);
605 }
606 else // Skip this line
607 {
608 fInput.ignore(99999,'\n');
609 }
610 }
611
612 fInput.close();
613}
614
616{
622
623 if (fTWRDaqFileName=="")
624 {
625 cout << " *IceCal2Root GetTWRDaqData* No TWRDaq calibration data will be produced." << endl;
626 return;
627 }
628
629 fInput.clear();
630 fInput.open(fTWRDaqFileName.Data());
631
632 if (!fInput.good())
633 {
634 cout << " *IceCal2Root GetTWRDaqData* Bad input file : " << fTWRDaqFileName.Data() << endl;
635 return;
636 }
637
638 // The geometry info will be obtained from the MuDaq OM database
639 if (!fMuDaqdb)
640 {
641 cout << " *IceCal2Root GetTWRDaqData* MuDaq OM geometry database is missing." << endl;
642 return;
643 }
644
645 // The TWRDaq OM database object
646 if (fTWRDaqdb)
647 {
648 fTWRDaqdb->Reset();
649 }
650 else
651 {
653 fTWRDaqdb->SetNameTitle("TWRDaq-OMDBASE","The TWRDaq OM geometry, calib. etc... database");
654 fTWRDaqdb->SetOwner();
655 }
656
657 // Prescription of the various (de)calibration functions
658 TF1 fadccal("fadccal","x*(5./4096.)/(50.*[0])");
659 TF1 fadcdecal("fadcdecal","x*(50.*[0])/(5./4096.)");
660 fadccal.SetParName(0,"nC/PE");
661 fadcdecal.SetParName(0,"nC/PE");
662
663 TF1 ftdccal("ftdccal","x-[0]");
664 TF1 ftdcdecal("ftdcdecal","x+[0]");
665 ftdccal.SetParName(0,"T0");
666 ftdcdecal.SetParName(0,"T0");
667
668 TF1 ftotcal("ftotcal","x*[0]");
669 TF1 ftotdecal("ftotdecal","x/[0]");
670 ftotcal.SetParName(0,"TOT-FACT");
671 ftotdecal.SetParName(0,"TOT-FACT");
672
673 fInput.seekg(0); // Position at beginning of file
674 fInput >> dec; // Make sure all integers starting with 0 are taken in decimal format
675
676 Int_t jmod;
677 Float_t t0;
678 Float_t ncpe;
679 IceAOM* omx=0;
680 TF1* fcal=0;
681 TF1* fdecal=0;
682 while (fInput >> jmod >> t0 >> ncpe)
683 {
684 // Copy the Geom data from the MuDaq OM database
685 IceAOM* omg=(IceAOM*)fMuDaqdb->GetObject(jmod,1);
686 if (!omg) continue;
687
688 omx=new IceAOM(*omg);
689
690 // Reset all previous "dead" flags
691 omx->SetAlive("ADC");
692 omx->SetAlive("LE");
693 omx->SetAlive("TOT");
694
695 // Enter the TWRDaq (de)calibration functions
696 omx->SetCalFunction(&fadccal,"ADC");
697 omx->SetDecalFunction(&fadcdecal,"ADC");
698 omx->SetCalFunction(&ftdccal,"LE");
699 omx->SetDecalFunction(&ftdcdecal,"LE");
700 omx->SetCalFunction(&ftotcal,"TOT");
701 omx->SetDecalFunction(&ftotdecal,"TOT");
702
703 // Flag slots of bad OMs as dead and don't provide time (de)calib functions
704 if (ncpe<=0)
705 {
706 omx->SetDead("ADC");
707 omx->SetCalFunction(0,"ADC");
708 omx->SetDecalFunction(0,"ADC");
709 }
710 if (t0<-999)
711 {
712 omx->SetDead("LE");
713 omx->SetDead("TOT");
714 omx->SetCalFunction(0,"LE");
715 omx->SetDecalFunction(0,"LE");
716 omx->SetCalFunction(0,"TOT");
717 omx->SetDecalFunction(0,"TOT");
718 }
719
720 // Set the TWRDaq (de)calibration function parameters for the good OMs
721 fcal=omx->GetCalFunction("ADC");
722 fdecal=omx->GetDecalFunction("ADC");
723 if (fcal)
724 {
725 fcal->SetParameter(0,ncpe);
726 }
727 if (fdecal)
728 {
729 fdecal->SetParameter(0,ncpe);
730 }
731
732 fcal=omx->GetCalFunction("LE");
733 fdecal=omx->GetDecalFunction("LE");
734 if (fcal)
735 {
736 fcal->SetParameter(0,t0);
737 }
738 if (fdecal)
739 {
740 fdecal->SetParameter(0,t0);
741 }
742
743 fcal=omx->GetCalFunction("TOT");
744 fdecal=omx->GetDecalFunction("TOT");
745 if (fcal)
746 {
747 fcal->SetParameter(0,1);
748 }
749 if (fdecal)
750 {
751 fdecal->SetParameter(0,1);
752 }
753
754 fTWRDaqdb->EnterObject(jmod,1,omx);
755
756 } // End of reading loop
757
758 fInput.close();
759}
760
ClassImp(IceCal2Root)
Signal (Hit) handling of a generic Amanda Optical Module (AOM).
Definition IceAOM.h:12
Job for conversion of (ascii) calibration data into an NcObjMatrix OM dbase.
Definition IceCal2Root.h:21
void GetTWRDaqData()
void SetAmacalibFile(TString name)
NcObjMatrix * fTWRDaqdb
Definition IceCal2Root.h:42
TString fTWRDaqFileName
Definition IceCal2Root.h:36
void SetOutputFile(TString name)
NcObjMatrix * fMuDaqdb
Definition IceCal2Root.h:41
IceCal2Root(const char *name="IceCal2Root", const char *title="")
void GetMuDaqData()
TString fAmacalFileName
Definition IceCal2Root.h:35
TDatabasePDG * GetPDG()
TString fRootFileName
Definition IceCal2Root.h:37
NcObjMatrix * GetOMdbase(TString name="MuDaq")
TFile * fOutfile
Definition IceCal2Root.h:38
virtual ~IceCal2Root()
void SetTWRDaqFile(TString name)
TDatabasePDG * fPdg
Definition IceCal2Root.h:40
virtual void Exec(Option_t *opt)
ifstream fInput
Definition IceCal2Root.h:33
void SetCalFunction(TF1 *f, Int_t j=1)
void SetAlive(Int_t j=1)
Definition NcAttrib.cxx:946
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