ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCalibrator.cxx File Reference

Go to the source code of this file.

Functions

bool TRTCalibrator::calibrate ATLAS_NOT_THREAD_SAFE ()
 Install fatal handler with default options.

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

bool TRTCalibrator::calibrate ATLAS_NOT_THREAD_SAFE ( void )
inline

Install fatal handler with default options.

This is meant to be easy to call from python via ctypes.

Install fatal handler with default options.

getLorentzAngle() Read LorentzAngle from HIST and write out into local DB

getBSErrors() Read BSErrors from Monitoring HIST and write out into local DB

getEfficiency() Read Efficiency from Monitoring HIST and write out into local DB

getRawOccupancy() Read RawOccupancy from Monitoring HIST and write out into local DB

getNoiseOccupancy() Read NoiseOccupancy from HIST and write out into local DB

getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats

Definition at line 309 of file TRTCalibrator.cxx.

309 {
310
311 float sid;
313 const InDetDD::TRT_BaseElement* strawelement;
314 const InDetDD::TRT_BarrelElement* barrelelement;
315 const InDetDD::TRT_EndcapElement* endcapelement;
316 int nTRThist=0, ndethist=0, nlayhist=0, nmodhist=0, nbrdhist=0, nchphist=0, nstwhist=0;
317 int nTRThistAr=0, ndethistAr=0, nlayhistAr=0, nmodhistAr=0, nbrdhistAr=0, nchphistAr=0, nstwhistAr=0;
318 databundle hitdata;
319
320 std::string infile=m_hittuple;
321 std::string outfile="calibout";
322
323 std::string detname="Detector";
324 std::string layname="Layer";
325 if (!m_SplitBarrel) {
326 detname="WholeBarrel";
327 layname="WholeBarrelLayer";
328 }
329
330 //create Calibrator objects for each sub-level
331 Calibrator TRT(0,"TRT",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
332 Calibrator Detector(1,detname.data(),m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
333 Calibrator Layer(2,layname.data(),m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
334 Calibrator Module(3,"Module",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
335 Calibrator Board(4,"Board",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
336 Calibrator Chip(5,"Chip",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
337 Calibrator Straw(6,"Straw",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
338
339
340 // make a map of calibrators (so that they can be looped over)
341 std::map<std::string,Calibrator*> calibrators;
342 calibrators["TRT"]=&TRT;
343 calibrators["Detector"]=&Detector;
344 calibrators["Layer"]=&Layer;
345 calibrators["Module"]=&Module;
346 calibrators["Board"]=&Board;
347 calibrators["Chip"]=&Chip;
348 calibrators["Straw"]=&Straw;
349
350 //use default configurations unless "user" option is used
351 if(m_calsub!="user"){
352 m_doRt=m_config[m_calsub].CalibrateRt;
353 m_doT0=m_config[m_calsub].CalibrateT0;
354 m_doRes=m_config[m_calsub].FitResidual;
355 m_beQuiet=m_config[m_calsub].NoHistograms;
356 m_doOutPrint=m_config[m_calsub].PrintT0Out;
357 m_doRtPrint=m_config[m_calsub].PrintRtOut;
358 m_doLogPrint=m_config[m_calsub].PrintLog;
359 }
360
361 //configure the calibrators
362 for (const std::string& s : m_doRt) calibrators[s]->dort=true;
363 for (const std::string& s : m_doT0) calibrators[s]->dot0=true;
364 for (const std::string& s : m_doRes) calibrators[s]->dores=true;
365 for (const std::string& s : m_beQuiet) calibrators[s]->bequiet=true;
366 for (const std::string& s : m_doOutPrint) calibrators[s]->printt0=true;
367 for (const std::string& s : m_doRtPrint) calibrators[s]->printrt=true;
368 for (const std::string& s : m_doLogPrint) calibrators[s]->printlog=true;
369 for (const std::string& s : m_useBoardRef) calibrators[s]->usebref=true;
370 for (std::pair<const std::string, Calibrator*>& p : calibrators) {
371 Calibrator* calib = p.second;
372 calib->usep0=m_useP0;
373 calib->floatp3=m_floatP3;
374 calib->useshortstraws=m_DoShortStrawCorrection;
375
376 if (m_doRt.size()==0) calib->nort=true;
377 if (m_doT0.size()==0) calib->not0=true;
378
379 std::set<int> selset;
380 GetSubLevels(m_selstring,calib->level+1,&selset); //get the set of selections for level "level+1" from the m_selstring ...
381 for (std::set<int>::iterator imod=selset.begin(); imod!=selset.end(); ++imod){
382 calib->selection = selset;//... and configure the calibrator with them
383 }
384 }
385
386 // FOR ARGON:
387 Calibrator TRT_Ar (0,"TRT_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
388 Calibrator Detector_Ar(1,"Detector_Ar",m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
389 Calibrator Layer_Ar (2,"Layer_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
390 Calibrator Module_Ar (3,"Module_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
391 Calibrator Board_Ar (4,"Board_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
392 Calibrator Chip_Ar (5,"Chip_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
393 Calibrator Straw_Ar (6,"Straw_Ar" ,m_mint0,m_minrt,m_rtrel,m_rtbinning,m_t0offset);
394
395 // make a map of calibrators (so that they can be looped over)
396 std::map<std::string,Calibrator*> calibratorsAr;
397 calibratorsAr["TRT"] =&TRT_Ar;
398 calibratorsAr["Detector"] =&Detector_Ar;
399 calibratorsAr["Layer"] =&Layer_Ar;
400 calibratorsAr["Module"] =&Module_Ar;
401 calibratorsAr["Board"] =&Board_Ar;
402 calibratorsAr["Chip"] =&Chip_Ar;
403 calibratorsAr["Straw"] =&Straw_Ar;
404
405 //configure the calibrators
406 for (const std::string& s : m_doRt) calibratorsAr[s]->dort=true;
407 for (const std::string& s : m_doT0) calibratorsAr[s]->dot0=true;
408 for (const std::string& s : m_doRes) calibratorsAr[s]->dores=true;
409 for (const std::string& s : m_beQuiet) calibratorsAr[s]->bequiet=true;
410 for (const std::string& s : m_doOutPrint) calibratorsAr[s]->printt0=true;
411 for (const std::string& s : m_doRtPrint) calibratorsAr[s]->printrt=true;
412 for (const std::string& s : m_doLogPrint) calibratorsAr[s]->printlog=true;
413 for (const std::string& s : m_useBoardRef) calibratorsAr[s]->usebref=true;
414 for (std::pair<const std::string, Calibrator*>& p : calibratorsAr) {
415 Calibrator* calib = p.second;
416 calib->usep0=m_useP0;
417 calib->floatp3=m_floatP3;
418 calib->useshortstraws=m_DoShortStrawCorrection;
419
420 if (m_doRt.size()==0) calib->nort=true;
421 if (m_doT0.size()==0) calib->not0=true;
422
423 std::set<int> selset;
424 GetSubLevels(m_selstring,calib->level+1,&selset); //get the set of selections for level "level+1" from the m_selstring ...
425 for (std::set<int>::iterator imod=selset.begin(); imod!=selset.end(); ++imod){
426 calib->selection = selset;//... and configure the calibrator with them
427 }
428 }
429
430
431
432 m_options = '_' + TRT.GetOptString() + '_' + Detector.GetOptString() + '_' + Layer.GetOptString() + '_' + Module.GetOptString() + '_' + Board.GetOptString() + '_' + Chip.GetOptString() + '_' + Straw.GetOptString();
433 if(m_calsub!="user") m_selstring = '_' + TRT.GetSelString() + '_' + Detector.GetSelString() + '_' + Layer.GetSelString() + '_' + Module.GetSelString() + '_' + Board.GetSelString() + '_' + Chip.GetSelString() + '_' + Straw.GetSelString();
434
435 //print some info
436 ATH_MSG_INFO(" ");
437 ATH_MSG_INFO( "INPUT FILE : " << infile );
438 ATH_MSG_INFO( "OUTPUT FILE : " << outfile );
439 ATH_MSG_INFO( "SELECTION STRING : " << m_selstring );
440 ATH_MSG_INFO( "OPTION STRING : " << m_options );
441 ATH_MSG_INFO( "RT RELATION : " << m_rtrel );
442 ATH_MSG_INFO( "MIN STATISTICS : RT=" << m_minrt << ", T0=" << m_mint0 );
443 ATH_MSG_INFO( "T0 OFFSET : " << m_t0offset );
444 ATH_MSG_INFO(" ");
445 ATH_MSG_INFO( TRT.PrintInfo() );
446 ATH_MSG_INFO( Detector.PrintInfo() );
447 ATH_MSG_INFO( Layer.PrintInfo() );
448 ATH_MSG_INFO( Module.PrintInfo() );
449 ATH_MSG_INFO( Board.PrintInfo() );
450 ATH_MSG_INFO( Chip.PrintInfo() );
451 ATH_MSG_INFO( Straw.PrintInfo() );
452 ATH_MSG_INFO(" ");
453
454 if (m_DoArXenonSep){
455 //print some info
456 ATH_MSG_INFO(" ");
457 ATH_MSG_INFO( "Setup for the ARGON Straws: " );
458 ATH_MSG_INFO( "INPUT FILE : " << infile );
459 ATH_MSG_INFO( "OUTPUT FILE : " << outfile );
460 ATH_MSG_INFO( "SELECTION STRING : " << m_selstring );
461 ATH_MSG_INFO( "OPTION STRING : " << m_options );
462 ATH_MSG_INFO( "RT RELATION : " << m_rtrel );
463 ATH_MSG_INFO( "MIN STATISTICS : RT=" << m_minrt << ", T0=" << m_mint0 );
464 ATH_MSG_INFO( "T0 OFFSET : " << m_t0offset );
465 ATH_MSG_INFO( " ");
466 ATH_MSG_INFO( TRT_Ar.PrintInfo() );
467 ATH_MSG_INFO( Detector_Ar.PrintInfo() );
468 ATH_MSG_INFO( Layer_Ar.PrintInfo() );
469 ATH_MSG_INFO( Module_Ar.PrintInfo() );
470 ATH_MSG_INFO( Board_Ar.PrintInfo() );
471 ATH_MSG_INFO( Chip_Ar.PrintInfo() );
472 ATH_MSG_INFO( Straw_Ar.PrintInfo() );
473 ATH_MSG_INFO(" ");
474 }
475 //read the chip reference t0 values from finedelays.txt
476 int rbrd, rchp, rdet, dum;
477 float rt0;
478 std::map<std::string,float> reft0map;
479 std::ifstream t0ref("finedelays.txt",std::ios::in);
480 if(t0ref.is_open()) ATH_MSG_INFO(" Opened finedelays.txt ");
481 for(int iref=0;iref<208;iref++){
482 t0ref >> rbrd >> rchp >> rdet >> dum >> rt0;
483 reft0map[std::string(Form("_%i_%i_%i",rdet,rbrd,rchp))]=rt0;
484 }
485
486 t0ref.close();
487
488
489 //set type of rt-relation
490 bool isdines = (m_rtrel.value()).find("dines")!=std::string::npos;
491 bool isbinned = (m_rtrel.value()).find("binned")!=std::string::npos;
492 int rtint;
493 if (isdines) rtint=2;
494 else if (isbinned) rtint=1;
495 else rtint=0;
496 ATH_MSG_INFO(" Rt relation is: " << rtint);
497
498 int npop,isid;
499 std::map<std::string,epdata> ephasemap;
500
501 // open the output histogram file
502 std::unique_ptr<TFile> histfile(TFile::Open("calibout.root","RECREATE"));
503
504 if(!histfile || histfile->IsZombie()) {
505 ATH_MSG_ERROR ("Failed to open calibout.root ");
506 return false;
507 } else {
508 ATH_MSG_INFO ("Opened calibout.root ");
509 }
510
511 std::ifstream myFile (infile.data(), std::ios::in | std::ios::binary);
512 ATH_MSG_INFO( " Opened " << infile << " as binary histogram file " );
513 int ihist=0;
514 int ihistAr=0;
515
516 while(true){
517
518 //read a binary histogram
519 //dangerous cast reproduces pre-existing c style cast
520 myFile.read (reinterpret_cast<char*>(&npop),sizeof(int)); //number of populated bins
521 if (myFile.eof()) break;
522 int* chist=new int[2*npop+2]; //the histogram
523 //dangerous cast reproduces pre-existing c style cast
524 if (npop>0) myFile.read (reinterpret_cast<char*>(chist+2), sizeof(int)*2*npop);
525 //dangerous cast reproduces pre-existing c style cast
526 myFile.read (reinterpret_cast<char*>(&isid),sizeof(int)); //the straw id
527 sid = (float)isid;
528 if(sid<0) continue;
529
530 chist[0]=npop;
531 chist[1]=isid;
532 //get the straw address (barrel/ec, layer, module, ...) based on the straw identifier
533 ident=(Identifier)(isid);
534 int chip=0,board=-1;
535 m_neighbourSvc->getChip(ident,chip);
536 if(abs(m_TRTID->barrel_ec(ident))<2){
537 board=m_neighbourSvc->chipToBoardBarrel(chip,m_TRTID->layer_or_wheel(ident));
538 }
539 else if (chip<12) {
540 board=0;
541 }
542 else {
543 chip=chip-20;
544 board=1;
545 }
546 if (m_SplitBarrel) hitdata.det=(int)m_TRTID->barrel_ec(ident);
547 else hitdata.det=abs((int)m_TRTID->barrel_ec(ident));
548 if(hitdata.det!=1 && hitdata.det!=-1 && hitdata.det!=2 && hitdata.det!=-2) {
549 ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " detector decoded to be : " << hitdata.det);
550 continue;
551 }
552 hitdata.lay=(int)m_TRTID->layer_or_wheel(ident);
553 if( (hitdata.det==1 || hitdata.det==-1) && (hitdata.lay<0 || hitdata.lay>2) ) {
554 ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " barrel layer decoded to be : " << hitdata.lay);
555 continue;
556 } else if( (hitdata.det==2 || hitdata.det==-2) && (hitdata.lay<0 || hitdata.lay>13) ) {
557 ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " endcap layer decoded to be : " << hitdata.lay);
558 continue;
559 }
560 hitdata.mod=(int)m_TRTID->phi_module(ident);
561 if( hitdata.mod < 0 || hitdata.mod > 31 ) {
562 ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " phi-module decoded to be : " << hitdata.lay);
563 continue;
564 }
565
566 hitdata.brd=board;
567 hitdata.chp=chip;
568 hitdata.stl=(int)m_TRTID->straw_layer(ident);
569 if( hitdata.stl < 0 || hitdata.stl > m_TRTID->straw_layer_max(ident) ) {
570 ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " straw-layer decoded to be : " << hitdata.stl);
571 continue;
572 }
573
574 hitdata.stw=(int)m_TRTID->straw(ident);
575 if( hitdata.stw < 0 || hitdata.stw > m_TRTID->straw_max(ident) ) {
576 ATH_MSG_WARNING( " Invalid Identifier read : " << ident << " straw decoded to be : " << hitdata.stw);
577 continue;
578 }
579
580 hitdata.sid=isid;
581
582 //get the old rt parameters based on straw identifier
583 const float* pcal ;
584 std::vector<float> rvalues ;
585 const float defaultpcal[] = {0,0,0,0} ;
586 if (isdines){
587 const TRTCond::DinesRtRelation* rtr = dynamic_cast<const TRTCond::DinesRtRelation*>(m_trtcaldbTool->getRtRelation(ident)) ;
588 pcal = rtr ? rtr->cal() : defaultpcal ;
589 }
590
591 else {
592 const TRTCond::BasicRtRelation* rtr = dynamic_cast<const TRTCond::BasicRtRelation*>(m_trtcaldbTool->getRtRelation(ident)) ;
593 pcal = rtr ? rtr->cal() : defaultpcal ;
594 }
595 hitdata.rtpar[0]=pcal[0];
596 hitdata.rtpar[1]=pcal[1];
597 hitdata.rtpar[2]=pcal[2];
598 hitdata.rtpar[3]=pcal[3];
599
600
601 //build map keys
602 MakeBDKeys(hitdata.det, hitdata.lay, hitdata.mod, hitdata.brd, hitdata.chp, hitdata.sid);
603
604 //make the level hierachy dictionaries
605 m_trt.t[m_Tkey].d[m_Dkey].l[m_Lkey].m[m_Mkey].b[m_Bkey].c[m_Ckey].s[m_Skey].z=0;
606 m_trt_acc.t[m_Tkey].d[m_Dkey_acc].l[m_Lkey_acc].m[m_Mkey].b[m_Bkey].c[m_Ckey].s[m_Skey].z=0;
607
608 //populate the hit data structure to be added
609
610
611 hitdata.ievt=0;
612 hitdata.tres=0;
613 hitdata.weight=1.0;
614 hitdata.res=0;
615 hitdata.t=0;
616 hitdata.r=0;
617 hitdata.t0=m_trtcaldbTool->getT0(ident);
618
619 strawelement = m_trtmanager->getElement(ident);
620 if(hitdata.det==1 || hitdata.det==-1) {
621 barrelelement=static_cast<const InDetDD::TRT_BarrelElement*>(strawelement);
622 hitdata.x=(barrelelement->center(ident)).x();
623 hitdata.y=(barrelelement->center(ident)).y();
624 hitdata.z=(barrelelement->center(ident)).z();
625 }else{
626 endcapelement=static_cast<const InDetDD::TRT_EndcapElement*>(strawelement);
627 hitdata.x=(endcapelement->center(ident)).x();
628 hitdata.y=(endcapelement->center(ident)).y();
629 hitdata.z=(endcapelement->center(ident)).z();
630 }
631
632 //in the short straws corrections, autodetect if it was applied on the previous step
633 if ( m_DoShortStrawCorrection && hitdata.lay==0 && hitdata.stl<9){
634 //If correction was done in ctes in db (readed), undo the correction: This fixes problem on t0 averaging....
635 double t0test1=m_trtcaldbTool->getT0((Identifier)301998432);
636 double t0test2=m_trtcaldbTool->getT0((Identifier)302001504);
637 if (t0test1 != t0test2) hitdata.t0+=0.75; //short straw compensation
638 }
639
640 //the reference t0 from finedelays
641 hitdata.rt0=reft0map[std::string(Form("_%i_%i_%i",hitdata.det,hitdata.brd,hitdata.chp))];
642
643 // Prepare for Xe-Ar mixed conditions:
644 int isArgonStraw = 0;
645 if (m_TRTStrawSummaryTool->getStatusHT(ident, Gaudi::Hive::currentContext()) != TRTCond::StrawStatus::Good) {
646 isArgonStraw = 1;
647 }
648
649
650 //add histogram to the Calibrators (A and C side separated)
651 if(!m_DoArXenonSep){
652
653 nTRThist += TRT.AddHit(m_Tkey,hitdata,chist,true);
654 if (Detector.CheckSelection(hitdata.det)) { //only add the histogram if it is in the selection
655 if (m_SplitBarrel) ndethist += Detector.AddHit(m_Dkey,hitdata,chist,true);
656 else ndethist += Detector.AddHit(m_Dkey_acc,hitdata,chist,true);
657 if (Layer.CheckSelection(hitdata.lay)) {
658 if (m_SplitBarrel) nlayhist += Layer.AddHit(m_Lkey,hitdata,chist,true);
659 else { nlayhist += Layer.AddHit(m_Lkey_acc,hitdata,chist,true); continue;}
660 if (Module.CheckSelection(hitdata.mod)) {
661 nmodhist += Module.AddHit(m_Mkey,hitdata,chist,true);
662 if (Board.CheckSelection(hitdata.brd)) {
663 nbrdhist += Board.AddHit(m_Bkey,hitdata,chist,true);
664 if (Chip.CheckSelection(hitdata.chp)) {
665 nchphist += Chip.AddHit(m_Ckey,hitdata,chist,true);
666 if (Straw.CheckSelection(hitdata.stw))
667 nstwhist += Straw.AddHit(m_Skey,hitdata,chist,true);
668 }
669 }
670 }
671 }
672 } // Here it closes
673 ihist++;
674 } else
675 if(isArgonStraw==0){ // Separate Ar and Xe in endcaps. Here Xe
676 nTRThist += TRT.AddHit(m_Tkey,hitdata,chist,true);
677 if (Detector.CheckSelection(hitdata.det)) { //only add the histogram if it is in the selection
678 if (m_SplitBarrel) ndethist += Detector.AddHit(m_Dkey,hitdata,chist,true);
679 else ndethist += Detector.AddHit(m_Dkey_acc,hitdata,chist,true);
680 if (Layer.CheckSelection(hitdata.lay)) {
681 if (m_SplitBarrel) nlayhist += Layer.AddHit(m_Lkey,hitdata,chist,true);
682 else { nlayhist += Layer.AddHit(m_Lkey_acc,hitdata,chist,true); continue;}
683 if (Module.CheckSelection(hitdata.mod)) {
684 nmodhist += Module.AddHit(m_Mkey,hitdata,chist,true);
685 if (Board.CheckSelection(hitdata.brd)) {
686 nbrdhist += Board.AddHit(m_Bkey,hitdata,chist,true);
687 if (Chip.CheckSelection(hitdata.chp)) {
688 nchphist += Chip.AddHit(m_Ckey,hitdata,chist,true);
689 if (Straw.CheckSelection(hitdata.stw)) {
690 nstwhist += Straw.AddHit(m_Skey,hitdata,chist,true);
691 }
692 }
693 }
694 }
695 }
696 } // Here it closes
697 ihist++;
698 } else { // ARGON HITS
699 nTRThistAr += TRT_Ar.AddHit(m_Tkey,hitdata,chist,true);
700 if (Detector_Ar.CheckSelection(hitdata.det)) { //only add the histogram if it is in the selection
701 if (m_SplitBarrel) ndethistAr += Detector_Ar.AddHit(m_Dkey,hitdata,chist,true);
702 else ndethistAr += Detector_Ar.AddHit(m_Dkey_acc,hitdata,chist,true);
703 if (Layer_Ar.CheckSelection(hitdata.lay)) {
704 if (m_SplitBarrel) nlayhistAr += Layer_Ar.AddHit(m_Lkey,hitdata,chist,true);
705 else { nlayhistAr += Layer_Ar.AddHit(m_Lkey_acc,hitdata,chist,true); continue;}
706 if (Module_Ar.CheckSelection(hitdata.mod)) {
707 nmodhistAr += Module_Ar.AddHit(m_Mkey,hitdata,chist,true);
708 if (Board_Ar.CheckSelection(hitdata.brd)) {
709 nbrdhistAr += Board_Ar.AddHit(m_Bkey,hitdata,chist,true);
710 if (Chip_Ar.CheckSelection(hitdata.chp)) {
711 nchphistAr += Chip_Ar.AddHit(m_Ckey,hitdata,chist,true);
712 if (Straw_Ar.CheckSelection(hitdata.stw)) {
713 nstwhistAr += Straw_Ar.AddHit(m_Skey,hitdata,chist,true);
714 }
715 }
716 }
717 }
718 }
719 } // Here it closes
720 ihistAr++;
721 } // END ARGON HITS
722
723
724 if ((ihist%10000==9999) | (ihist==m_nevents-1)){
725 ATH_MSG_INFO( Form("%7i HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihist+1,nTRThist, ndethist, nlayhist, nmodhist, nbrdhist, nchphist, nstwhist) );
726 if(m_DoArXenonSep) ATH_MSG_INFO( Form("%7i Ar HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihistAr+1,nTRThistAr, ndethistAr, nlayhistAr, nmodhistAr, nbrdhistAr, nchphistAr, nstwhistAr) );
727 }
728
729 ihist++;
730 delete [] chist;
731 } // Finish Straw Loop
732
733 ATH_MSG_INFO( Form("%7i HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihist+1,nTRThist, ndethist, nlayhist, nmodhist, nbrdhist, nchphist, nstwhist) );
734 if(m_DoArXenonSep) ATH_MSG_INFO( Form("%7i Ar HISTOGRAMS READ, UNITS ADDED: %i %i %2i %3i %3i %4i %6i",ihistAr+1,nTRThistAr, ndethistAr, nlayhistAr, nmodhistAr, nbrdhistAr, nchphistAr, nstwhistAr) );
735
736 TRT.UpdateOldConstants();
737 Detector.UpdateOldConstants();
738 Layer.UpdateOldConstants();
739 Module.UpdateOldConstants();
740 Board.UpdateOldConstants();
741 Chip.UpdateOldConstants();
742
743 if (ihistAr>0 ){
744 TRT_Ar.UpdateOldConstants();
745 Detector_Ar.UpdateOldConstants();
746 Layer_Ar.UpdateOldConstants();
747 Module_Ar.UpdateOldConstants();
748 Board_Ar.UpdateOldConstants();
749 Chip_Ar.UpdateOldConstants();
750 }
751
752 myFile.close();
753
754
755 ATH_MSG_INFO(" ");
756 ATH_MSG_INFO( TRT.PrintStat() );
757 ATH_MSG_INFO( Detector.PrintStat() );
758 ATH_MSG_INFO( Layer.PrintStat() );
759 ATH_MSG_INFO( Module.PrintStat() );
760 ATH_MSG_INFO( Board.PrintStat() );
761 ATH_MSG_INFO( Chip.PrintStat() );
762 ATH_MSG_INFO( Straw.PrintStat() );
763 ATH_MSG_INFO(" ");
764
765
766 if(m_DoArXenonSep){
767 ATH_MSG_INFO(" ");
768 ATH_MSG_INFO( TRT_Ar.PrintStat() );
769 ATH_MSG_INFO( Detector_Ar.PrintStat() );
770 ATH_MSG_INFO( Layer_Ar.PrintStat() );
771 ATH_MSG_INFO( Module_Ar.PrintStat() );
772 ATH_MSG_INFO( Board_Ar.PrintStat() );
773 ATH_MSG_INFO( Chip_Ar.PrintStat() );
774 ATH_MSG_INFO( Straw_Ar.PrintStat() );
775 ATH_MSG_INFO(" ");
776 }
777
778
779
780 //caldata startdata(true,tbins,rbins);
781 caldata startdata(true,55,100);
782 //caldata startdata(true,64,64);
783 startdata.t0=5.0;
784 std::map<std::string,TDirectory*> dirmap;
785 TDirectory* trtdir=gDirectory;
786 TDirectory* detdir=gDirectory;
787 TDirectory* laydir=gDirectory;
788 TDirectory* moddir=gDirectory;
789 TDirectory* brddir=gDirectory;
790 TDirectory* chpdir=gDirectory;
791
792 std::ofstream rtcalfile(Form("%s_rt.txt",outfile.data()),std::ios::out);
793 std::ofstream binrtcalfile(Form("%s_binrt.txt",outfile.data()),std::ios::out);
794 std::ofstream t0calfile(Form("%s_t0.txt",outfile.data()),std::ios::out);
795
796
797 //if (m_SplitBarrel){
798
799 for (std::pair<const std::string, BDdetector>& pt : m_trt.t) {
800
801 if (TRT.Skip()) break;
802 if (TRT.HasKey(pt.first)) {
803 trtdir = TRT.Calibrate(histfile.get(),pt.first,SubLev(m_options,1),&startdata);
804 if (TRT.printt0) t0calfile << Form("-3 -1 -1 -1 -1 : %e %e",TRT.data[pt.first].t0,TRT.data[pt.first].t0err) << std::endl;
805 if (TRT.printrt) rtcalfile << Form("-3 -1 -1 -1 -1 : %i %e %e %e %e",rtint,TRT.data[pt.first].rtpar[0],TRT.data[pt.first].rtpar[1],TRT.data[pt.first].rtpar[2],TRT.data[pt.first].rtpar[3]) << std::endl;
806 }
807 for (std::pair<const std::string, BDlayer>& pd : pt.second.d) {
808
809 if(Detector.Skip()) break;
810 if(Detector.HasKey(pd.first)){
811 detdir = Detector.Calibrate(trtdir,pd.first,SubLev(m_options,2),&TRT.data[pt.first]);
812 }
813 for (std::pair<const std::string, BDmodule>& pl : pd.second.l) {
814
815 if(Layer.Skip()) break;
816 if(Layer.HasKey(pl.first)){
817 laydir = Layer.Calibrate(detdir,pl.first,SubLev(m_options,3),&Detector.data[pd.first]);
818 if (Layer.printt0) t0calfile << Form("%i %i -1 -1 -1 : %e %e",Layer.data[pl.first].det,Layer.data[pl.first].lay,Layer.data[pl.first].t0,Layer.data[pl.first].t0err) << std::endl;
819 if (Layer.printrt) rtcalfile << Form("%i %i -1 -1 -1 : %i %e %e %e %e",Layer.data[pl.first].det,Layer.data[pl.first].lay,rtint,Layer.data[pl.first].rtpar[0],Layer.data[pl.first].rtpar[1],Layer.data[pl.first].rtpar[2],Layer.data[pl.first].rtpar[3]) << std::endl;
820 if (!m_SplitBarrel) {
821 if (Layer.printt0) t0calfile << Form("%i %i -1 -1 -1 : %e %e",-Layer.data[pl.first].det,Layer.data[pl.first].lay,Layer.data[pl.first].t0,Layer.data[pl.first].t0err) << std::endl;
822 if (Layer.printrt) rtcalfile << Form("%i %i -1 -1 -1 : %i %e %e %e %e",-Layer.data[pl.first].det,Layer.data[pl.first].lay,rtint,Layer.data[pl.first].rtpar[0],Layer.data[pl.first].rtpar[1],Layer.data[pl.first].rtpar[2],Layer.data[pl.first].rtpar[3]) << std::endl;
823 }
824 }
825 for (std::pair<const std::string, BDboard>& pm : pl.second.m) {
826
827 if(Module.Skip()) break;
828 if(Module.HasKey(pm.first)){
829 moddir = Module.Calibrate(laydir,pm.first,SubLev(m_options,4),&Layer.data[pl.first]);
830 if (Module.printt0) t0calfile << Form("%i %i %i -1 -1 : %e %e",Module.data[pm.first].det,Module.data[pm.first].lay,Module.data[pm.first].mod,Module.data[pm.first].t0,Module.data[pm.first].t0err) << std::endl;
831 if (Module.printrt) rtcalfile << Form("%i %i %i -1 -1 : %i %e %e %e %e",Module.data[pm.first].det,Module.data[pm.first].lay,Module.data[pm.first].mod,rtint,Module.data[pm.first].rtpar[0],Module.data[pm.first].rtpar[1],Module.data[pm.first].rtpar[2],Module.data[pm.first].rtpar[3]) << std::endl;
832 }
833 for (std::pair<const std::string, BDchip>& pb : pm.second.b) {
834
835 if(Board.Skip()) break;
836 if(Board.HasKey(pb.first)){
837 brddir = Board.Calibrate(moddir,pb.first,SubLev(m_options,5),&Module.data[pm.first]);
838 }
839 for (std::pair<const std::string, BDstraw>& pc : pb.second.c) {
840
841 if(Chip.Skip()) break;
842 if(Chip.HasKey(pc.first)){
843 chpdir = Chip.Calibrate(brddir,pc.first,SubLev(m_options,6),&Board.data[pb.first]);
844 }
845 for (std::pair<const std::string, BDzero>& ps : pc.second.s) {
846
847 if(Straw.Skip()) break;
848 if(Straw.HasKey(ps.first)){
849 Straw.Calibrate(chpdir,ps.first,SubLev(m_options,7),&Chip.data[pc.first]);
850 if (Straw.printt0) t0calfile << Form("%i %i %i %i %i : %e %e",Straw.data[ps.first].det,Straw.data[ps.first].lay,Straw.data[ps.first].mod,Straw.data[ps.first].stl,Straw.data[ps.first].stw,Straw.data[ps.first].t0,Straw.data[ps.first].t0err) << std::endl;
851 if (Straw.printrt) rtcalfile << Form("%i %i %i %i %i : %i %e %e %e %e",Straw.data[ps.first].det,Straw.data[ps.first].lay,Straw.data[ps.first].mod,Straw.data[ps.first].stl,Straw.data[ps.first].stw,rtint,Straw.data[ps.first].rtpar[0],Straw.data[ps.first].rtpar[1],Straw.data[ps.first].rtpar[2],Straw.data[ps.first].rtpar[3]) << std::endl;
852
853
854 }
855 }
856 }
857 }
858 }
859 }
860 }
861 }
862
863 std::map<std::string,TDirectory*> dirArmap;
864 TDirectory* trtdirAr=gDirectory;
865 TDirectory* detdirAr=gDirectory;
866 TDirectory* laydirAr=gDirectory;
867 TDirectory* moddirAr=gDirectory;
868 TDirectory* brddirAr=gDirectory;
869 TDirectory* chpdirAr=gDirectory;
870
871 if (m_DoArXenonSep){
872
873 for (std::pair<const std::string, BDdetector>& pt : m_trt.t) {
874
875 if (TRT_Ar.Skip()) break;
876 if (TRT_Ar.HasKey(pt.first)) {
877 trtdirAr = TRT_Ar.Calibrate(histfile.get(),pt.first,SubLev(m_options,1),&startdata);
878 }
879 for (std::pair<const std::string, BDlayer>& pd : pt.second.d) {
880
881 if(Detector_Ar.Skip()) break;
882 if(Detector_Ar.HasKey(pd.first)){
883 detdirAr = Detector_Ar.Calibrate(trtdirAr,pd.first,SubLev(m_options,2),&TRT_Ar.data[pt.first]);
884 }
885 for (std::pair<const std::string, BDmodule>& pl : pd.second.l) {
886
887 if(Layer_Ar.Skip()) break;
888 if(Layer_Ar.HasKey(pl.first)){
889 laydirAr = Layer_Ar.Calibrate(detdirAr,pl.first,SubLev(m_options,3),&Detector_Ar.data[pd.first]);
890
891 }
892 for (std::pair<const std::string, BDboard>& pm : pl.second.m) {
893
894 if(Module_Ar.Skip()) break;
895 if(Module_Ar.HasKey(pm.first)){
896 moddirAr = Module_Ar.Calibrate(laydirAr,pm.first,SubLev(m_options,4),&Layer_Ar.data[pl.first]);
897 if (Module_Ar.printt0) t0calfile << Form("%i %i %i -1 -1 : %e %e",Module_Ar.data[pm.first].det,Module_Ar.data[pm.first].lay,Module_Ar.data[pm.first].mod,Module_Ar.data[pm.first].t0,Module_Ar.data[pm.first].t0err) << std::endl;
898 if (Layer_Ar.printrt) rtcalfile << Form("%i %i %i -1 -1 : %i %e %e %e %e",Module_Ar.data[pm.first].det,Module_Ar.data[pm.first].lay,Module_Ar.data[pm.first].mod,rtint,Module_Ar.data[pm.first].rtpar[0],Module_Ar.data[pm.first].rtpar[1],Module_Ar.data[pm.first].rtpar[2],Module_Ar.data[pm.first].rtpar[3]) << std::endl;
899 }
900 for (std::pair<const std::string, BDchip>& pb : pm.second.b) {
901 if(Board_Ar.Skip()) break;
902 if(Board_Ar.HasKey(pb.first)){
903 brddirAr = Board_Ar.Calibrate(moddirAr,pb.first,SubLev(m_options,5),&Module_Ar.data[pm.first]);
904 }
905 for (std::pair<const std::string, BDstraw>& pc : pb.second.c) {
906
907 if(Chip_Ar.Skip()) break;
908 if(Chip_Ar.HasKey(pc.first)){
909 chpdirAr = Chip_Ar.Calibrate(brddirAr,pc.first,SubLev(m_options,6),&Board_Ar.data[pb.first]);
910 }
911 for (std::pair<const std::string, BDzero>& ps : pc.second.s) {
912
913 if(Straw_Ar.Skip()) break;
914 if(Straw_Ar.HasKey(ps.first)){
915 Straw_Ar.Calibrate(chpdirAr,ps.first,SubLev(m_options,7),&Chip_Ar.data[pc.first]);
916 if (Straw_Ar.printt0) t0calfile << Form("%i %i %i %i %i : %e %e",Straw_Ar.data[ps.first].det,Straw_Ar.data[ps.first].lay,Straw_Ar.data[ps.first].mod,Straw_Ar.data[ps.first].stl,Straw_Ar.data[ps.first].stw,Straw_Ar.data[ps.first].t0,Straw_Ar.data[ps.first].t0err) << std::endl;
917 if (Straw_Ar.printrt) rtcalfile << Form("%i %i %i %i %i : %i %e %e %e %e",Straw_Ar.data[ps.first].det,Straw_Ar.data[ps.first].lay,Straw_Ar.data[ps.first].mod,Straw_Ar.data[ps.first].stl,Straw_Ar.data[ps.first].stw,rtint,Straw_Ar.data[ps.first].rtpar[0],Straw_Ar.data[ps.first].rtpar[1],Straw_Ar.data[ps.first].rtpar[2],Straw_Ar.data[ps.first].rtpar[3]) << std::endl;
918 }
919 }
920 }
921 }
922 }
923 }
924 }
925 }
926
927}// Close for ARGON
928
929
930
931
932 //make ntuples for each calibrator
933 if (!TRT.bequiet) TRT.WriteStat(histfile.get());
934 if (!Detector.bequiet) Detector.WriteStat(histfile.get());
935 if (!Layer.bequiet) Layer.WriteStat(histfile.get());
936 if (!Module.bequiet) Module.WriteStat(histfile.get());
937 if (!Board.bequiet) Board.WriteStat(histfile.get());
938 Chip.WriteStat(histfile.get());
939 Straw.WriteStat(histfile.get());
940
941 TRT.DumpConstants();
942 Detector.DumpConstants();
943 Layer.DumpConstants();
944 Module.DumpConstants();
945 Board.DumpConstants();
946 Chip.DumpConstants();
947 Straw.DumpConstants();
948
949 rtcalfile.close();
950 binrtcalfile.close();
951 t0calfile.close();
952
953 //AR
954 //make ntuples for each calibrator
955 if(m_DoArXenonSep){
956 if (!TRT_Ar.bequiet) TRT_Ar.WriteStat(histfile.get());
957 if (!Detector_Ar.bequiet) Detector_Ar.WriteStat(histfile.get());
958 if (!Layer_Ar.bequiet) Layer_Ar.WriteStat(histfile.get());
959 if (!Module_Ar.bequiet) Module_Ar.WriteStat(histfile.get());
960 if (!Board_Ar.bequiet) Board_Ar.WriteStat(histfile.get());
961 Chip_Ar.WriteStat(histfile.get());
962 Straw_Ar.WriteStat(histfile.get());
963
964 TRT_Ar.DumpConstants();
965 Detector_Ar.DumpConstants();
966 Layer_Ar.DumpConstants();
967 Module_Ar.DumpConstants();
968 Board_Ar.DumpConstants();
969 Chip_Ar.DumpConstants();
970 Straw_Ar.DumpConstants();
971 }
972
973 histfile->ls();
974 ATH_MSG_INFO( "writing out calibout.root");
975 histfile->Write();
976
977 return true;
978
979}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
An instance of this class is created for each sub-level of the TRT by the TRTCalibrator.
Definition Calibrator.h:178
Extended TRT_BaseElement to describe a TRT readout element, this is a planar layer with n ( order of ...
Virtual base class of TRT readout elements.
virtual const Amg::Vector3D & center() const override final
Element Surface: center of a straw layer.
Extended class of a TRT_BaseElement to describe a readout elment in the endcap.
Default rt-relation class in the TRT: a 3rd degree polynomial.
const float * cal() const
return to calibration constants
Default rt-relation class in the TRT: a 3rd degree polynomial.
const float * cal() const
return to calibration constants
A structure to contain data associated with the calibration of a certain sub-module.
Definition Calibrator.h:104
A structure to contain hit data.
Definition Calibrator.h:77
float res
space residual
Definition Calibrator.h:90
int det
detector (barrel -1 or 1, or end-cap -2 or 2)
Definition Calibrator.h:79
float rt0
reference t0 (offset from board mean)
Definition Calibrator.h:94
int ievt
event number
Definition Calibrator.h:87
int chp
chip
Definition Calibrator.h:83
float t
raw time
Definition Calibrator.h:91
float r
drift radius from r(t) relation
Definition Calibrator.h:92
int brd
board
Definition Calibrator.h:82
float tres
time residual
Definition Calibrator.h:88
std::array< float, 4 > rtpar
rt-parameters used in the reconstruction
Definition Calibrator.h:95
float t0
t0 value used in reconstruction
Definition Calibrator.h:93
int stw
straw number (within the strawlayer)
Definition Calibrator.h:85
int stl
straw-layer
Definition Calibrator.h:84
float z
straw z position
Definition Calibrator.h:98
float x
straw x position
Definition Calibrator.h:96
int lay
layer
Definition Calibrator.h:80
float y
straw y position
Definition Calibrator.h:97
float weight
histogram weight (currently set to 1)
Definition Calibrator.h:89
int mod
phi module
Definition Calibrator.h:81
int sid
straw ID
Definition Calibrator.h:86
@ ident
Definition HitInfo.h:77
Definition HitInfo.h:33
str infile
Definition run.py:13