ATLAS Offline Software
Loading...
Searching...
No Matches
Calib Class Reference

#include <Calib.h>

Collaboration diagram for Calib:

Classes

class  funcDisp
class  funcTot

Public Member Functions

 Calib (int whichPart, bool saveFile, const std::string &moduleName="")
 ~Calib ()
bool fillThresholds (const pix::PixelMapping &pm, const std::string &inThrFile, std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo > > > &map_info)
bool fillTiming (const pix::PixelMapping &pm, const std::string &inTimFile, std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo > > > &map_info)
bool totFitting (const pix::PixelMapping &pm, const std::string &inTimFile, std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo > > > &map_info)

Private Member Functions

int chipId (int iphi, int ieta)
int pixelType (int iphi, int ieta, bool isForTOT=false)
TIter getRodIterator (const TFile &inputFile)
TIter getModuleIterator (TDirectoryFile *rodDir)
TH2F * get2DHistogramFromPath (TDirectoryFile *rodDir, const std::string &moduleName, const std::string &histName, int charge=-1)
bool moduleInPart (const std::string &modName)
std::vector< float > getParams (const TF1 *f, unsigned int params)
std::vector< float > getParams_quality (const TF1 *f)
bool reFit_normalPix (std::vector< float > &params, std::vector< float > &q, std::vector< float > &qerr, std::vector< float > &tot, std::vector< float > &toterr, std::vector< float > &sig, std::vector< float > &sigerr, const unsigned int fe)
void graphTitles (const std::unique_ptr< TGraphErrors > &graph, const std::string &name, const std::string &Yname)

Private Attributes

bool m_savefile = false
std::unique_ptr< TFile > m_wFile
bool m_runOneMOD = false
std::string m_testMOD = ""
int m_whichPart = -1
const std::array< std::string, 4 > m_MODprefixes {"L0", "L1", "L2", "D"}
const std::array< std::string, 4 > m_layers {"Blayer", "L1", "L2", "Disk"}

Static Private Attributes

static constexpr float m_chi_error = 0.05
static constexpr int m_etaBins = 144
static constexpr int m_phiBins = 320
static constexpr int m_thrnbins = 200
static constexpr float m_thrLo = 0.
static constexpr float m_thrHi = 6000.
static constexpr float m_sigLo = 0.
static constexpr float m_sigHi = 500
static constexpr int m_timnbins = 300
static constexpr float m_timLo = 1000.
static constexpr float m_timHi = 7000.
static constexpr int m_totnbins = 255
static constexpr float m_totLo = 0.
static constexpr float m_totHi = 255.
static constexpr int m_totsigNBins = 100
static constexpr float m_totsigLo = 0.
static constexpr float m_totsigHi = 1.
static constexpr int m_nFE = 16
static constexpr int m_ncharge = 21
static constexpr std::array< float, m_nchargem_chargeArr { 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 12000, 14000, 16000, 18000, 20000, 25000}
static constexpr std::array< float, m_nchargem_chargeErrArr { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
static constexpr int m_qthresh = 5

Detailed Description

Definition at line 33 of file Calib.h.

Constructor & Destructor Documentation

◆ Calib()

Calib::Calib ( int whichPart,
bool saveFile,
const std::string & moduleName = "" )
inline

Definition at line 35 of file Calib.h.

35 {
36 m_whichPart = whichPart;
37
38 if(saveFile){
39 m_savefile = saveFile;
40 m_wFile = std::make_unique<TFile>((m_layers.at(whichPart)+".HIST.root").c_str(),"RECREATE");
41 }
42 if( not moduleName.empty() ){
43 m_runOneMOD = true;
44 m_testMOD = moduleName;
45 }
46 };
bool m_runOneMOD
Definition Calib.h:62
bool m_savefile
Definition Calib.h:59
const std::array< std::string, 4 > m_layers
Definition Calib.h:70
int m_whichPart
Definition Calib.h:68
std::unique_ptr< TFile > m_wFile
Definition Calib.h:60
std::string m_testMOD
Definition Calib.h:63

◆ ~Calib()

Calib::~Calib ( )
inline

Definition at line 47 of file Calib.h.

47 {
48 if(m_savefile){
49 m_wFile->Write(0,TObject::kOverwrite);
50 m_wFile->Close();
51 }
52 };

Member Function Documentation

◆ chipId()

int Calib::chipId ( int iphi,
int ieta )
private

Definition at line 733 of file Calib.cxx.

733 {
734 int circ = -1;
735 if (iphi < 160) {
736 circ = (int)(ieta / 18);
737 } else {
738 circ = 15 - (int)(ieta / 18);
739 } // FE15, FE14, ... FE8
740
741 if (circ>15){
742 printf("Error - FE id error: %d, setting it to -1",circ);
743 circ = -1;//error
744 }
745 return circ;
746}

◆ fillThresholds()

bool Calib::fillThresholds ( const pix::PixelMapping & pm,
const std::string & inThrFile,
std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo > > > & map_info )

Definition at line 549 of file Calib.cxx.

549 {
550
551 if (inThrFile.empty()) return false;
552
553 TFile riThrFile(inThrFile.c_str(),"READ");
554 if (not riThrFile.IsOpen()) {
555 printf("Error - File %s could not be opened.\n",inThrFile.c_str());
556 return false;
557 } else {
558 printf("File %s opened.\n",inThrFile.c_str());
559 printf("Running threshold calibration...\n");
560 }
561
562 // Creating here the histograms with this scope owner
563 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTHR;
564 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsSIG;
565 for(unsigned int FE = 0; FE < m_nFE; FE++){
566
567 histogramsTHR.push_back( std::vector< std::unique_ptr<TH1F> >() );
568 histogramsSIG.push_back( std::vector< std::unique_ptr<TH1F> >() );
569
570 for(unsigned int pixel=0; pixel<3; pixel++){
571 std::string title = "FE"+std::to_string(FE)+"_pixType"+std::to_string(pixel);
572 std::unique_ptr<TH1F> hthr = std::make_unique<TH1F>((title+"_thr").c_str(), (title+"_thr").c_str(), m_thrnbins, m_thrLo, m_thrHi);
573 hthr->SetDirectory(0);
574 std::unique_ptr<TH1F> hsig = std::make_unique<TH1F>((title+"_sig").c_str(), (title+"_sig").c_str(), m_thrnbins, m_sigLo, m_sigHi);
575 hsig->SetDirectory(0);
576 //cppcheck-suppress containerOutOfBounds
577 histogramsTHR.at(FE).push_back(std::move(hthr));
578 //cppcheck-suppress containerOutOfBounds
579 histogramsSIG.at(FE).push_back(std::move(hsig));
580 }
581 }
582
583 //Will start looping over the RODs
584 TIter rodItr = getRodIterator(riThrFile);
585 TKey* rodKey;
586 while ((rodKey=static_cast<TKey*>(rodItr()))) {
587 const std::string rodName(rodKey->GetName());
588 TDirectoryFile* rodDir = (TDirectoryFile*)rodKey->ReadObj();
589 TKey* modKey;
590 TIter modItr=getModuleIterator(rodDir);
591
592 // Looping over the MODs of each ROD
593 while ((modKey=static_cast<TKey*>(modItr()))) {
594 std::string modName(modKey->GetName());
595
596 if ( not moduleInPart(modName)){
597 continue;
598 }
599 if ( not pm.contains(modName)){
600 printf("Error - Module %s not found in the PixelMapping tool\n",modName.c_str());
601 continue;
602 }
603
604 if( m_runOneMOD and (modName == m_testMOD)){
605 continue;
606 }
607
608 // pixel discriminator threshold
609 std::unique_ptr<TH2F> h2dThr(get2DHistogramFromPath(rodDir,modName, "SCURVE_MEAN"));
610 h2dThr->SetDirectory(0);
611
612 // Getting histogram for noise
613 std::unique_ptr<TH2F>h2dSig(get2DHistogramFromPath(rodDir,modName, "SCURVE_SIGMA"));
614 h2dSig->SetDirectory(0);
615
616 for (unsigned int ieta = 0; ieta < m_etaBins; ieta++) {
617 for (unsigned int iphi = 0; iphi < m_phiBins; iphi++) {
618
619 float thr = h2dThr->GetBinContent(ieta + 1, iphi + 1);
620 float sig = h2dSig->GetBinContent(ieta + 1, iphi + 1);
621
622 if (thr == 0 || thr > 10000 || sig == 0 || sig > 1000) {
623 continue;
624 }
625
626 int FE = chipId(iphi, ieta);
627 int pixel= pixelType(iphi, ieta);
628
629 if(FE<0){
630 return false;
631 }
632
633 histogramsTHR.at(FE).at(pixel)->Fill(thr);
634 histogramsSIG.at(FE).at(pixel)->Fill(sig);
635
636 }
637 }
638
639 // Freeing memory of TH2F
640 h2dThr.reset();
641 h2dSig.reset();
642
643 int modID = pm.getID(modName);
644 auto itr = map_info.find( modID );
645
646 // Map should be empty and therefore we need to create the key - if the key is repeated then it will throw an error
647 if (itr == map_info.end()) {
648
649 map_info[modID] = std::vector<std::unique_ptr<CalibFrontEndInfo>> ();
650
651 for(unsigned int FE = 0; FE < m_nFE; FE++){
652 std::string subdir(((FE < 10) ? "FE0" : "FE") +std::to_string(FE));
653 map_info[modID].push_back( std::unique_ptr<CalibFrontEndInfo>() );
654 std::unique_ptr<CalibFrontEndInfo> p = std::make_unique<CalibFrontEndInfo>(modID,FE,modName,std::string(rodKey->GetName()));
655 map_info[modID].at(FE) = std::move(p);
656
657 for(unsigned int pixel=0; pixel<3; pixel++){
658
659 // Saving information for the calibration
660 int thr_mean = histogramsTHR.at(FE).at(pixel)->GetMean();
661 int thr_rms = histogramsTHR.at(FE).at(pixel)->GetRMS();
662 int sig_mean = histogramsSIG.at(FE).at(pixel)->GetMean();
663
664 if(m_savefile){
665
666 m_wFile->cd();
667 if( !m_wFile->Get((rodName+"/"+modName+"/Thresholds/"+subdir).c_str()) ){
668 m_wFile->mkdir((rodName+"/"+modName+"/Thresholds/"+subdir).c_str(),rodName.c_str());
669 }
670
671 m_wFile->cd((rodName+"/"+modName+"/Thresholds/"+subdir).c_str());
672
673 histogramsTHR.at(FE).at(pixel)->SetTitle("Threshold;Pixel threshold;Counts");
674 histogramsSIG.at(FE).at(pixel)->SetTitle("Sigma;Pixel sigma;Counts");
675
676 std::string type = "";
677 if(pixel == 0) type = "normal";
678 else if(pixel == 1) type = "long";
679 else if(pixel == 2) type = "ganged";
680
681 histogramsTHR.at(FE).at(pixel)->Write(std::string("thres_"+type).c_str(), TObject::kWriteDelete);
682 histogramsSIG.at(FE).at(pixel)->Write(std::string("sigma_"+type).c_str(), TObject::kWriteDelete);
683 }
684
685 // Reset histograms for next front end
686 histogramsTHR.at(FE).at(pixel)->Reset("ICESM");
687 histogramsSIG.at(FE).at(pixel)->Reset("ICESM");
688
689 if(pixel == 0){ // normal
690 map_info[modID].at(FE)->set_NormalThreshold(thr_mean);
691 map_info[modID].at(FE)->set_NormalRms(thr_rms);
692 map_info[modID].at(FE)->set_NormalNoise(sig_mean);
693 }
694 else if(pixel == 1){ // long
695 map_info[modID].at(FE)->set_LongThreshold(thr_mean);
696 map_info[modID].at(FE)->set_LongRms(thr_rms);
697 map_info[modID].at(FE)->set_LongNoise(sig_mean);
698 }
699 else if(pixel == 2){ // ganged
700 map_info[modID].at(FE)->set_GangedThreshold(thr_mean);
701 map_info[modID].at(FE)->set_GangedRms(thr_rms);
702 map_info[modID].at(FE)->set_GangedNoise(sig_mean);
703 }
704 else{
705 printf("Calib::fillThresholds: ERROR - Bad pixel in Calib::fillThresholds\n");
706 return false;
707 }
708 }
709 }
710
711 }
712 else{
713 printf("Calib::fillThresholds: ERROR - REPEATED MOD ID: %s! Contact Offline team\n",modName.c_str());
714 return false;
715 }
716 } // End of MOD loop
717 } // End of ROD loop
718
719 for(unsigned int FE = 0; FE < m_nFE; FE++) {
720 for(unsigned int pixel=0; pixel<3; pixel++) {
721 histogramsTHR.at(FE).at(pixel).reset();
722 histogramsSIG.at(FE).at(pixel).reset();
723 }
724 }
725
726 //Closing file - not needed anymore
727 riThrFile.Close();
728 printf("DONE with threshold calibration.\n");
729 return true;
730}
TH2F * get2DHistogramFromPath(TDirectoryFile *rodDir, const std::string &moduleName, const std::string &histName, int charge=-1)
Definition Calib.cxx:781
TIter getRodIterator(const TFile &inputFile)
Definition Calib.cxx:770
static constexpr int m_phiBins
Definition Calib.h:73
static constexpr float m_sigLo
Definition Calib.h:78
int chipId(int iphi, int ieta)
Definition Calib.cxx:733
static constexpr int m_etaBins
Definition Calib.h:72
int pixelType(int iphi, int ieta, bool isForTOT=false)
Definition Calib.cxx:749
static constexpr float m_thrLo
Definition Calib.h:76
TIter getModuleIterator(TDirectoryFile *rodDir)
Definition Calib.cxx:776
static constexpr float m_sigHi
Definition Calib.h:79
static constexpr int m_nFE
Definition Calib.h:93
bool moduleInPart(const std::string &modName)
Definition Calib.cxx:798
static constexpr int m_thrnbins
Definition Calib.h:75
static constexpr float m_thrHi
Definition Calib.h:77
bool contains(const std::string &geographicalID) const
int getID(const std::string &geographicalID) const

◆ fillTiming()

bool Calib::fillTiming ( const pix::PixelMapping & pm,
const std::string & inTimFile,
std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo > > > & map_info )

Definition at line 369 of file Calib.cxx.

369 {
370
371 if (inTimFile.empty()) return false;
372
373 TFile timFile(inTimFile.c_str(),"READ");
374 if (not timFile.IsOpen()) {
375 printf("Error - File %s could not be opened.\n",inTimFile.c_str());
376 return false;
377 } else {
378 printf("File %s opened.\n",inTimFile.c_str());
379 printf("Running timming calibration...\n");
380 }
381
382 // Creating here the histograms with this scope owner
383 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTIM;
384 for(unsigned int FE = 0; FE < m_nFE; FE++){
385
386 histogramsTIM.push_back( std::vector< std::unique_ptr<TH1F> >() );
387
388 for(unsigned int pixel=0; pixel<3; pixel++){
389 std::string title = "FE"+std::to_string(FE)+"_pixType"+std::to_string(pixel);
390 std::unique_ptr<TH1F> h = std::make_unique<TH1F>((title+"_thr").c_str(), (title+"_thr").c_str(), m_timnbins, m_timLo, m_timHi);
391 h->SetDirectory(0);
392 //cppcheck-suppress containerOutOfBounds
393 histogramsTIM.at(FE).push_back(std::move(h));
394 }
395 }
396
397 //Will strat looping over the RODs
398 TIter rodItr = getRodIterator(timFile);
399 TKey* rodKey;
400 while ((rodKey=static_cast<TKey*>(rodItr()))) {
401 const std::string rodName(rodKey->GetName());
402 TDirectoryFile* rodDir = static_cast<TDirectoryFile*>(rodKey->ReadObj());
403 TKey* modKey;
404 TIter modItr=getModuleIterator(rodDir);
405
406 // Looping over the MODs of each ROD
407 while ((modKey=static_cast<TKey*>(modItr()))) {
408 std::string modName(modKey->GetName());
409
410 if ( not moduleInPart(modName)){
411 continue;
412 }
413 if ( not pm.contains(modName)){
414 printf("Error - Module %s not found in the PixelMapping tool\n",modName.c_str());
415 continue;
416 }
417
418 if( m_runOneMOD and (modName == m_testMOD)){
419 continue;
420 }
421
422 std::unique_ptr<TH2F> h2dTim(get2DHistogramFromPath(rodDir,modName, "SCURVE_MEAN"));
423 h2dTim->SetDirectory(0);
424
425 for (unsigned int ieta = 0; ieta < m_etaBins; ieta++) {
426 for (unsigned int iphi = 0; iphi < m_phiBins; iphi++) {
427
428 float tim = h2dTim->GetBinContent(ieta + 1, iphi + 1);
429
430 if (tim<0.5) {
431 continue;
432 }
433
434 int FE = chipId(iphi, ieta);
435 int pixel= pixelType(iphi, ieta);
436
437 if(FE<0){
438 return false;
439 }
440
441 histogramsTIM.at(FE).at(pixel)->Fill(tim);
442 }
443 }
444
445 // Freeing memory of TH2F
446 h2dTim.reset();
447
448 int modID = pm.getID(modName);
449 auto itr = map_info.find( modID );
450 if (itr == map_info.end()) {
451 printf("Calib::fillTiming: ERROR - Mod ID= %16s not found. Creating it -----> Inform Pixel Offline Software Experts... \n",modName.c_str());
452
453 map_info[modID] = std::vector<std::unique_ptr<CalibFrontEndInfo>> ();
454
455 for(unsigned int FE = 0; FE < m_nFE; FE++){
456
457 map_info[modID].push_back( std::unique_ptr<CalibFrontEndInfo>() );
458 std::unique_ptr<CalibFrontEndInfo> p = std::make_unique<CalibFrontEndInfo>(modID,FE,modName,std::string(rodKey->GetName()));
459 map_info[modID].at(FE) = std::move(p);
460
461 for(unsigned int pixel=0; pixel<3; pixel++){
462
463 // Saving information for the calibration
464 int tim_mean = histogramsTIM.at(FE).at(pixel)->GetMean();
465
466 // Reset histograms for next front end
467 histogramsTIM.at(FE).at(pixel)->Reset("ICESM");
468
469 if(pixel == 0){ // normal
470 map_info[modID].at(FE)->set_NormalIntime(tim_mean);
471 }
472 else if(pixel == 1){ // long
473 map_info[modID].at(FE)->set_LongIntime(tim_mean);
474 }
475 else if(pixel == 2){ // ganged
476 map_info[modID].at(FE)->set_GangedIntime(tim_mean);
477 }
478 else{
479 printf("Error - Bad pixel in Calib::fillTiming\n");
480 return false;
481 }
482 }
483 }
484
485 }
486 else{
487 for(unsigned int FE = 0; FE < m_nFE; FE++){
488 std::string subdir(((FE < 10) ? "FE0" : "FE") +std::to_string(FE));
489 for(unsigned int pixel=0; pixel<3; pixel++){
490
491 // Saving information for the calibration
492 int tim_mean = histogramsTIM.at(FE).at(pixel)->GetMean();
493
494 if(m_savefile){
495
496 m_wFile->cd();
497 if( !m_wFile->Get((rodName+"/"+modName+"/Thresholds/"+subdir).c_str()) ){
498 m_wFile->mkdir((rodName+"/"+modName+"/Thresholds/"+subdir).c_str(),rodName.c_str());
499 }
500
501 m_wFile->cd((rodName+"/"+modName+"/Thresholds/"+subdir).c_str());
502
503 histogramsTIM.at(FE).at(pixel)->SetTitle("Intime;Pixel intime;Counts");
504
505 std::string type = "";
506 if(pixel == 0) type = "normal";
507 else if(pixel == 1) type = "long";
508 else if(pixel == 2) type = "ganged";
509
510 histogramsTIM.at(FE).at(pixel)->Write(std::string("intime_"+type).c_str(), TObject::kWriteDelete);
511 }
512
513 // Reset histograms for next front end
514 histogramsTIM.at(FE).at(pixel)->Reset("ICESM");
515
516 if(pixel == 0){ // normal
517 (itr->second).at(FE)->set_NormalIntime(tim_mean);
518 }
519 else if(pixel == 1){ // long
520 (itr->second).at(FE)->set_LongIntime(tim_mean);
521 }
522 else if(pixel == 2){ // ganged
523 (itr->second).at(FE)->set_GangedIntime(tim_mean);
524 }
525 else{
526 printf("Error - Bad pixel in Calib::fillTiming\n");
527 return false;
528 }
529 } // End of pixel type loop
530 } // End of FE loop
531 }
532 } // End of MOD loop
533 }// End of ROD loop
534
535 for(unsigned int FE = 0; FE < m_nFE; FE++) {
536 for(unsigned int pixel=0; pixel<3; pixel++) {
537 histogramsTIM.at(FE).at(pixel).reset();
538 }
539 }
540
541 //Closing file - not needed anymore
542 timFile.Close();
543 printf("DONE with threshold calibration.\n");
544 return true;
545}
static constexpr float m_timHi
Definition Calib.h:83
static constexpr int m_timnbins
Definition Calib.h:81
static constexpr float m_timLo
Definition Calib.h:82

◆ get2DHistogramFromPath()

TH2F * Calib::get2DHistogramFromPath ( TDirectoryFile * rodDir,
const std::string & moduleName,
const std::string & histName,
int charge = -1 )
private

Definition at line 781 of file Calib.cxx.

781 {
782 std::string suffix;
783 if (charge >= 0)
784 suffix = std::format ("/C{}", charge);
785 std::string fullHistoPath = moduleName + "/" + histName + "/A0/B0" + suffix;
786 TDirectoryFile *histDir = static_cast<TDirectoryFile *>(rodDir->GetDirectory(fullHistoPath.c_str()));
787
788 if(!histDir){
789 printf("Error - Directory \"%s\" not found. Exiting..\n",fullHistoPath.c_str());
790 return nullptr;
791 }
792 TH2F *pTH2 = static_cast<TH2F*>((static_cast<TKey*>(histDir->GetListOfKeys()->First()))->ReadObj());
793 pTH2->SetDirectory(0);
794
795 return pTH2;
796}
double charge(const T &p)
Definition AtlasPID.h:997
TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)

◆ getModuleIterator()

TIter Calib::getModuleIterator ( TDirectoryFile * rodDir)
private

Definition at line 776 of file Calib.cxx.

776 {
777 TList* modKeyList = static_cast<TList*>(rodDir->GetListOfKeys());
778 return TIter(modKeyList);
779}

◆ getParams()

std::vector< float > Calib::getParams ( const TF1 * f,
unsigned int params )
private

Definition at line 806 of file Calib.cxx.

806 {
807 std::vector<float> v;
808 for(unsigned int i = 0; i<params; i++){
809 v.push_back(f->GetParameter(i));
810 }
811
812 return v;
813}

◆ getParams_quality()

std::vector< float > Calib::getParams_quality ( const TF1 * f)
private

Definition at line 815 of file Calib.cxx.

815 {
816 std::vector<float> v;
817
818 v.push_back(f->GetChisquare());
819 v.push_back(f->GetNDF());
820
821 return v;
822}

◆ getRodIterator()

TIter Calib::getRodIterator ( const TFile & inputFile)
private

Definition at line 770 of file Calib.cxx.

770 {
771 TDirectoryFile* scanDir = static_cast<TDirectoryFile*>((static_cast<TKey*>(inputFile.GetListOfKeys()->First()))->ReadObj());
772 TList* rodKeyList = static_cast<TList*>(scanDir->GetListOfKeys());
773 return TIter(rodKeyList);
774}
void scanDir(SampleHandler &sh, DiskList &list, const std::string &pattern, const std::string &samplePattern, const std::string &samplePostfix)
effects: scan the given directory and add all subdirectories as samples that contain root files.

◆ graphTitles()

void Calib::graphTitles ( const std::unique_ptr< TGraphErrors > & graph,
const std::string & name,
const std::string & Yname )
private

Definition at line 824 of file Calib.cxx.

824 {
825 graph->SetTitle((std::string(name)+";Charge;"+std::string(Yname)).c_str());
826 graph->SetMarkerStyle(20);
827}

◆ moduleInPart()

bool Calib::moduleInPart ( const std::string & modName)
private

Definition at line 798 of file Calib.cxx.

798 {
799 if (modName == "DSP_ERRORS") {
800 return false;
801 }
802 return modName.starts_with(m_MODprefixes[m_whichPart]);
803}
const std::array< std::string, 4 > m_MODprefixes
Definition Calib.h:69

◆ pixelType()

int Calib::pixelType ( int iphi,
int ieta,
bool isForTOT = false )
private

Definition at line 749 of file Calib.cxx.

749 {
750
751 // normal pixels ( by default )
752 int pixtype = 0;
753
754 // define long pixels
755 if (ieta % 18 == 0 || ieta % 18 == 17) {
756 pixtype = 1;
757 }
758 // define ganged pixels
759 if (iphi > 152 && iphi < 160 && iphi % 2 == 1) {
760 pixtype = 2;
761 }
762 if (iphi > 159 && iphi < 167 && iphi % 2 == 0) {
763 pixtype = 2;
764 }
765
766 if(isForTOT and pixtype == 2 ) pixtype=1;
767 return pixtype;
768}

◆ reFit_normalPix()

bool Calib::reFit_normalPix ( std::vector< float > & params,
std::vector< float > & q,
std::vector< float > & qerr,
std::vector< float > & tot,
std::vector< float > & toterr,
std::vector< float > & sig,
std::vector< float > & sigerr,
const unsigned int fe )
private

Definition at line 315 of file Calib.cxx.

315 {
316
317 float vecFit_size = q.size()+1;
318 // float vecFit_size = q.size() - m_qthresh;
319 float stopFit = m_ncharge/2.0;
320 // float stopFit = (m_ncharge - m_qthresh)/2.0;
321 if(vecFit_size < stopFit) {
322
323 // Default values for the fit
324 params.at(0) = 0;
325 params.at(1) = -28284.3;
326 params.at(2) = 0;
327
328 printf("reFit_normalPix: Refitting skipped. Not enough points to fit.\n");
329
330 return false;
331 }
332
333 float parAI0 = params.at(0);
334 float parEI0 = params.at(1);
335 float parCI0 = params.at(2);
336
337 std::vector<float> v_discrepancy;
338
339 for(unsigned int i = 0; i < q.size(); i++){
340 float discrepancy = std::abs( 1 - ( (parAI0 * parEI0 - parCI0 * tot.at(i)) / (tot.at(i) - parAI0) ) / q.at(i) );
341
342 if( i < m_qthresh ){
343 discrepancy = 0.0;
344 }
345 v_discrepancy.push_back(discrepancy);
346 }
347
348 auto itr_max = std::max_element(v_discrepancy.begin(),v_discrepancy.end());
349
350 if(*itr_max > m_chi_error){
351
352 size_t n_max = std::distance(v_discrepancy.begin(), itr_max);
353 printf("FE %02u Refitted, removing charge %5.0f with chi_error %7.5f\n", fe ,q.at(n_max),*itr_max);
354 q.erase(q.begin()+n_max);
355 qerr.erase(qerr.begin()+n_max);
356 tot.erase(tot.begin()+n_max);
357 toterr.erase(toterr.begin()+n_max);
358 sig.erase(sig.begin()+n_max);
359 sigerr.erase(sigerr.begin()+n_max);
360
361 return true;
362 }
363
364 return false;
365
366}
static constexpr int m_qthresh
Definition Calib.h:99
static constexpr float m_chi_error
Definition Calib.h:65
static constexpr int m_ncharge
Definition Calib.h:94

◆ totFitting()

bool Calib::totFitting ( const pix::PixelMapping & pm,
const std::string & inTimFile,
std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo > > > & map_info )

Definition at line 16 of file Calib.cxx.

16 {
17
18 if (inTotFile.empty()) return false;
19
20 TFile totFile(inTotFile.c_str(),"READ");
21 if (not totFile.IsOpen()) {
22 printf("Error - File %s could not be opened.\n",inTotFile.c_str());
23 totFile.Close();
24 return false;
25 } else {
26 printf("File %s opened.\n",inTotFile.c_str());
27 printf("Running TOT calibration...\n");
28 }
29
30 // Creating here the histograms with this scope ownership
31 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTOT;
32 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTOTsig;
33 for(unsigned int FE = 0; FE < m_nFE; FE++){
34
35 histogramsTOT.push_back( std::vector< std::unique_ptr<TH1F> >() );
36 histogramsTOTsig.push_back( std::vector< std::unique_ptr<TH1F> >() );
37
38 //Here we combine long and ganged pixels
39 for(unsigned int pixel=0; pixel<2; pixel++){
40 std::string title = "FE"+std::to_string(FE)+"_pixType"+std::to_string(pixel);
41 std::unique_ptr<TH1F> htot = std::make_unique<TH1F>((title+"_tot").c_str(), (title+"_tot").c_str(), m_totnbins, m_totLo, m_totHi);
42 htot->SetDirectory(0);
43 std::unique_ptr<TH1F> htotsig = std::make_unique<TH1F>((title+"_totsig").c_str(), (title+"_totsig").c_str(), m_totsigNBins, m_totsigLo, m_totsigHi);
44 htotsig->SetDirectory(0);
45 //cppcheck-suppress containerOutOfBounds
46 histogramsTOT.at(FE).push_back(std::move(htot));
47 //cppcheck-suppress containerOutOfBounds
48 histogramsTOTsig.at(FE).push_back(std::move(htotsig));
49 }
50 }
51
52 // Start looping over the ROD, MOD and charges
53 TIter rodItr=getRodIterator(totFile);
54 TKey* rodKey;
55
56 while ((rodKey=static_cast<TKey*>(rodItr()))) {
57 TDirectoryFile* rodDir = static_cast<TDirectoryFile*>(rodKey->ReadObj());
58 TIter modItr = getModuleIterator(rodDir);
59 const std::string rodName(rodKey->GetName());
60 printf("%s\n",rodName.c_str());
61 TKey* modKey;
62 while ((modKey=static_cast<TKey*>(modItr()))) {
63 const std::string modName(modKey->GetName());
64
65 if (not moduleInPart(modName)) continue;
66 if (not pm.contains(modName)) continue;
67
68 if( m_runOneMOD and (modName == m_testMOD)){
69 continue;
70 }
71
72 printf(" -> %s\n",modName.c_str());
73
74 //creates arrays for the Tgraph
75 std::array<std::array<float, m_ncharge>, m_nFE> totArrI{};
76 std::array<std::array<float, m_ncharge>, m_nFE> totErrArrI{};
77 std::array<std::array<float, m_ncharge>, m_nFE> totSigArrI{};
78 std::array<std::array<float, m_ncharge>, m_nFE> totSigErrArrI{};
79 std::array<std::array<float, m_ncharge>, m_nFE> totLongArrI{};
80 std::array<std::array<float, m_ncharge>, m_nFE> totErrLongArrI{};
81
82 // loop over charges
83 for (int c=0; c<m_ncharge; ++c) {
84
85 // Get TH2 for a given charge
86 std::unique_ptr<TH2F> h2dTOTmean(get2DHistogramFromPath(rodDir,modName, "TOT_MEAN", c));
87 std::unique_ptr<TH2F> h2dTOTsig(get2DHistogramFromPath(rodDir,modName, "TOT_SIGMA", c));
88 if(!h2dTOTmean or !h2dTOTsig) {
89 return false;
90 }
91 h2dTOTmean->SetDirectory(0);
92 h2dTOTsig->SetDirectory(0);
93 // loop over pixels
94 for (unsigned int ieta = 0; ieta < m_etaBins; ieta++) {
95 for (unsigned int iphi = 0; iphi < m_phiBins; iphi++) {
96 float totmean = h2dTOTmean->GetBinContent(ieta + 1, iphi + 1);
97 float totsig = h2dTOTsig ->GetBinContent(ieta + 1, iphi + 1);
98
99 if (totmean<0.1) {
100 continue;
101 }
102
103 int FE = chipId(iphi, ieta);
104 int pixel= pixelType(iphi, ieta, true);
105
106 if(FE<0){
107 return false;
108 }
109
110 histogramsTOT.at(FE).at(pixel)->Fill(totmean);
111 histogramsTOTsig.at(FE).at(pixel)->Fill(totsig);
112
113 }
114 }
115
116 // free memory
117 h2dTOTmean.reset();
118 h2dTOTsig.reset();
119
120 //filling arrays
121 for(unsigned int FE = 0; FE < m_nFE; FE++){
122 for(unsigned int pixel = 0; pixel <2; pixel++){
123
124 if(pixel == 0){
125 totArrI.at(FE).at(c) = histogramsTOT.at(FE).at(pixel)->GetMean();
126 totErrArrI.at(FE).at(c) = histogramsTOT.at(FE).at(pixel)->GetMeanError();
127 totSigArrI.at(FE).at(c) = std::sqrt(std::pow(histogramsTOTsig.at(FE).at(pixel)->GetMean() ,2)+std::pow(histogramsTOT.at(FE).at(pixel)->GetRMS() ,2));
128 totSigErrArrI.at(FE).at(c) = std::sqrt(std::pow(histogramsTOTsig.at(FE).at(pixel)->GetMeanError(),2)+std::pow(histogramsTOT.at(FE).at(pixel)->GetRMSError(),2));
129
130 if(totSigErrArrI.at(FE).at(c) > 1.0){
131 totArrI.at(FE).at(c) = 0.0;
132 }
133
134 }
135 else{
136 totLongArrI.at(FE).at(c) = histogramsTOT.at(FE).at(pixel)->GetMean();
137 totErrLongArrI.at(FE).at(c) = histogramsTOT.at(FE).at(pixel)->GetMeanError();
138
139 if(totErrLongArrI.at(FE).at(c) > 1.0){
140 totLongArrI.at(FE).at(c) = 0.0;
141 }
142
143 }
144
145 //reset histogram for next iteration
146 histogramsTOT.at(FE).at(pixel)->Reset("ICESM");
147 histogramsTOTsig.at(FE).at(pixel)->Reset("ICESM");
148 }
149 }
150 } // End of charge.
151
152 // loop over FE and create a graph for fitting
153 for(unsigned int FE = 0; FE < m_nFE; FE++) {
154
155 std::string subdir(((FE < 10) ? "FE0" : "FE") +std::to_string(FE));
156
157 std::vector<float> v_Q;
158 std::vector<float> v_Qerr;
159 std::vector<float> v_TOT;
160 std::vector<float> v_TOTerr;
161 std::vector<float> v_TOTsig;
162 std::vector<float> v_TOTsigerr;
163 std::vector<float> v_TOTlong;
164 std::vector<float> v_TOTlongerr;
165
166 std::copy(std::begin(m_chargeArr) , std::end(m_chargeArr) , std::back_inserter(v_Q) );
167 std::copy(std::begin(m_chargeErrArr) , std::end(m_chargeErrArr) , std::back_inserter(v_Qerr) );
168 std::copy(std::begin(totArrI[FE]) , std::end(totArrI[FE]) , std::back_inserter(v_TOT) );
169 std::copy(std::begin(totErrArrI[FE]) , std::end(totErrArrI[FE]) , std::back_inserter(v_TOTerr) );
170 std::copy(std::begin(totSigArrI[FE]) , std::end(totSigArrI[FE]) , std::back_inserter(v_TOTsig) );
171 std::copy(std::begin(totSigErrArrI[FE]) , std::end(totSigErrArrI[FE]) , std::back_inserter(v_TOTsigerr) );
172 std::copy(std::begin(totLongArrI[FE]) , std::end(totLongArrI[FE]) , std::back_inserter(v_TOTlong) );
173 std::copy(std::begin(totErrLongArrI[FE]) , std::end(totErrLongArrI[FE]) , std::back_inserter(v_TOTlongerr) );
174
175 std::vector<float> pixNormalParams;
176 std::vector<float> pixNormalParamsQuality;
177 std::vector<float> pixSigParams;
178 std::vector<float> pixSigParamsQuality;
179 std::vector<float> pixLongParams;
180 std::vector<float> pixLongParamsQuality;
181
182 //For normal pixels and sig
183 uint8_t n_fit = 0;
184 do{
185 int vecsize = v_Q.size();
186
187 std::unique_ptr<TGraphErrors> graphnormal = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOT.at(0) , &v_Qerr.at(0), &v_TOTerr.at(0) );
188 std::unique_ptr<TGraphErrors> graphsig = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOTsig.at(0) , &v_Qerr.at(0), &v_TOTsigerr.at(0) );
189
190 std::unique_ptr<TF1> functnormal = std::make_unique<TF1>("normal" ,new funcTot , m_chargeArr[m_qthresh]-100, m_chargeArr[m_ncharge-1]+100, 3);
191 std::unique_ptr<TF1> functnormalsig = std::make_unique<TF1>("normal_sig",new funcDisp, m_chargeArr[m_qthresh]-100, m_chargeArr[m_ncharge-1]+100, 2);
192
193 graphnormal->Fit(functnormal.get() ,"MRQ");
194 graphsig ->Fit(functnormalsig.get(),"MRQ");
195
196 pixNormalParams = getParams(functnormal.get() ,3 );
197 pixSigParams = getParams(functnormalsig.get(),2 );
198
199 pixNormalParamsQuality = getParams_quality(functnormal.get() );
200 pixSigParamsQuality = getParams_quality(functnormalsig.get());
201
202 if(m_savefile){
203
204 m_wFile->cd();
205 if( !m_wFile->Get((rodName+"/"+modName+"/TOTfits/"+subdir).c_str()) ){
206 m_wFile->mkdir((rodName+"/"+modName+"/TOTfits/"+subdir).c_str(),rodName.c_str());
207 }
208
209 m_wFile->cd((rodName+"/"+modName+"/TOTfits/"+subdir).c_str());
210
211 graphTitles(graphnormal, std::string(modName+" - "+subdir+" - normal pixels: Fit: "+std::to_string(n_fit)).c_str(), "TOT");
212 graphTitles(graphsig , std::string(modName+" - "+subdir+" - normal pixels: Fit: "+std::to_string(n_fit)).c_str(), "Charge smearing");
213
214 graphnormal->Write(std::string("normal_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
215 graphsig->Write(std::string("smearing_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
216 n_fit++;
217 }
218
219 functnormal.reset();
220 functnormalsig.reset();
221
222 graphnormal.reset();
223 graphsig.reset();
224
225 }while(reFit_normalPix(pixNormalParams, v_Q, v_Qerr, v_TOT, v_TOTerr, v_TOTsig, v_TOTsigerr, FE ) );
226
227
228 // Since we have modified the vector size we need to clear it and refill it for the long and gange pixels
229 v_Q.clear();
230 v_Qerr.clear();
231
232 std::copy(std::begin(m_chargeArr) , std::end(m_chargeArr) , std::back_inserter(v_Q) );
233 std::copy(std::begin(m_chargeErrArr) , std::end(m_chargeErrArr) , std::back_inserter(v_Qerr) );
234
235
236 //For long and ganged pixels (combined)
237 n_fit = 0;
238 do{
239
240 //size will be modified in the condition..
241 int vecsize = v_Q.size();
242
243 std::unique_ptr<TGraphErrors> graflong = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOTlong.at(0), &v_Qerr.at(0), &v_TOTlongerr.at(0) );
244
245 std::unique_ptr<TF1> functlong = std::make_unique<TF1>("long" ,new funcTot , m_chargeArr[m_qthresh]-100, m_chargeArr[m_ncharge-1]+100, 3);
246
247 graflong ->Fit(functlong.get() ,"MRQ");
248
249 pixLongParams = getParams(functlong.get() ,3 );
250 pixLongParamsQuality = getParams_quality(functlong.get() );
251
252 if(m_savefile){
253
254 m_wFile->cd();
255 if( !m_wFile->Get((rodName+"/"+modName+"/TOTfits/"+subdir).c_str()) ){
256 m_wFile->mkdir((rodName+"/"+modName+"/TOTfits/"+subdir).c_str(),rodName.c_str());
257 }
258
259 m_wFile->cd((rodName+"/"+modName+"/TOTfits/"+subdir).c_str());
260
261 graphTitles(graflong, std::string(modName+" - "+subdir+" - long+ganged pixels: Fit: "+std::to_string(n_fit)).c_str(), "TOT");
262
263 graflong->Write(std::string("long_ganged_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
264 n_fit++;
265 }
266
267 //delete the TF1
268 functlong.reset();
269
270 //delete the graphs
271 graflong.reset();
272
273 // no need to loop here.. leaving to improve it in the future - might need refitting
274 }while( false);
275
276
277 // Find the module it belong to
278 int modID = pm.getID(modName);
279 auto itr = map_info.find( modID );
280
281 if (itr != map_info.end()) {
282 (itr->second).at(FE)->set_NormalParams( pixNormalParams);
283 (itr->second).at(FE)->set_LongParams ( pixLongParams );
284 (itr->second).at(FE)->set_SigParams ( pixSigParams );
285
286 (itr->second).at(FE)->set_times_fitted ( n_fit );
287
288 (itr->second).at(FE)->set_NormalParamsQuality( pixNormalParamsQuality);
289 (itr->second).at(FE)->set_LongParamsQuality ( pixLongParamsQuality );
290 (itr->second).at(FE)->set_SigParamsQuality ( pixSigParamsQuality );
291 }
292 else{
293 printf("Error - Module not found in fitting step... Skipping.\n");
294 return false;
295 }
296
297 } // End of FE loop
298 } // End of MOD
299 } // End of ROD
300
301 // remove from memory
302 for(unsigned int FE = 0; FE < m_nFE; FE++) {
303 for(unsigned int pixel=0; pixel<2; pixel++) {
304 histogramsTOT.at(FE).at(pixel).reset();
305 histogramsTOTsig.at(FE).at(pixel).reset();
306 }
307 }
308
309 totFile.Close();
310 return true;
311}
static constexpr std::array< float, m_ncharge > m_chargeArr
Definition Calib.h:95
static constexpr int m_totnbins
Definition Calib.h:85
std::vector< float > getParams(const TF1 *f, unsigned int params)
Definition Calib.cxx:806
std::vector< float > getParams_quality(const TF1 *f)
Definition Calib.cxx:815
bool reFit_normalPix(std::vector< float > &params, std::vector< float > &q, std::vector< float > &qerr, std::vector< float > &tot, std::vector< float > &toterr, std::vector< float > &sig, std::vector< float > &sigerr, const unsigned int fe)
Definition Calib.cxx:315
static constexpr float m_totLo
Definition Calib.h:86
static constexpr float m_totsigHi
Definition Calib.h:90
static constexpr float m_totsigLo
Definition Calib.h:89
static constexpr int m_totsigNBins
Definition Calib.h:88
static constexpr std::array< float, m_ncharge > m_chargeErrArr
Definition Calib.h:96
void graphTitles(const std::unique_ptr< TGraphErrors > &graph, const std::string &name, const std::string &Yname)
Definition Calib.cxx:824
static constexpr float m_totHi
Definition Calib.h:87

Member Data Documentation

◆ m_chargeArr

std::array<float, m_ncharge> Calib::m_chargeArr { 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 12000, 14000, 16000, 18000, 20000, 25000}
staticconstexprprivate

Definition at line 95 of file Calib.h.

95{ 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 12000, 14000, 16000, 18000, 20000, 25000};

◆ m_chargeErrArr

std::array<float, m_ncharge> Calib::m_chargeErrArr { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
staticconstexprprivate

Definition at line 96 of file Calib.h.

96{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

◆ m_chi_error

float Calib::m_chi_error = 0.05
staticconstexprprivate

Definition at line 65 of file Calib.h.

◆ m_etaBins

int Calib::m_etaBins = 144
staticconstexprprivate

Definition at line 72 of file Calib.h.

◆ m_layers

const std::array<std::string, 4> Calib::m_layers {"Blayer", "L1", "L2", "Disk"}
private

Definition at line 70 of file Calib.h.

70{"Blayer", "L1", "L2", "Disk"};

◆ m_MODprefixes

const std::array<std::string, 4> Calib::m_MODprefixes {"L0", "L1", "L2", "D"}
private

Definition at line 69 of file Calib.h.

69{"L0", "L1", "L2", "D"};

◆ m_ncharge

int Calib::m_ncharge = 21
staticconstexprprivate

Definition at line 94 of file Calib.h.

◆ m_nFE

int Calib::m_nFE = 16
staticconstexprprivate

Definition at line 93 of file Calib.h.

◆ m_phiBins

int Calib::m_phiBins = 320
staticconstexprprivate

Definition at line 73 of file Calib.h.

◆ m_qthresh

int Calib::m_qthresh = 5
staticconstexprprivate

Definition at line 99 of file Calib.h.

◆ m_runOneMOD

bool Calib::m_runOneMOD = false
private

Definition at line 62 of file Calib.h.

◆ m_savefile

bool Calib::m_savefile = false
private

Definition at line 59 of file Calib.h.

◆ m_sigHi

float Calib::m_sigHi = 500
staticconstexprprivate

Definition at line 79 of file Calib.h.

◆ m_sigLo

float Calib::m_sigLo = 0.
staticconstexprprivate

Definition at line 78 of file Calib.h.

◆ m_testMOD

std::string Calib::m_testMOD = ""
private

Definition at line 63 of file Calib.h.

◆ m_thrHi

float Calib::m_thrHi = 6000.
staticconstexprprivate

Definition at line 77 of file Calib.h.

◆ m_thrLo

float Calib::m_thrLo = 0.
staticconstexprprivate

Definition at line 76 of file Calib.h.

◆ m_thrnbins

int Calib::m_thrnbins = 200
staticconstexprprivate

Definition at line 75 of file Calib.h.

◆ m_timHi

float Calib::m_timHi = 7000.
staticconstexprprivate

Definition at line 83 of file Calib.h.

◆ m_timLo

float Calib::m_timLo = 1000.
staticconstexprprivate

Definition at line 82 of file Calib.h.

◆ m_timnbins

int Calib::m_timnbins = 300
staticconstexprprivate

Definition at line 81 of file Calib.h.

◆ m_totHi

float Calib::m_totHi = 255.
staticconstexprprivate

Definition at line 87 of file Calib.h.

◆ m_totLo

float Calib::m_totLo = 0.
staticconstexprprivate

Definition at line 86 of file Calib.h.

◆ m_totnbins

int Calib::m_totnbins = 255
staticconstexprprivate

Definition at line 85 of file Calib.h.

◆ m_totsigHi

float Calib::m_totsigHi = 1.
staticconstexprprivate

Definition at line 90 of file Calib.h.

◆ m_totsigLo

float Calib::m_totsigLo = 0.
staticconstexprprivate

Definition at line 89 of file Calib.h.

◆ m_totsigNBins

int Calib::m_totsigNBins = 100
staticconstexprprivate

Definition at line 88 of file Calib.h.

◆ m_wFile

std::unique_ptr<TFile> Calib::m_wFile
private

Definition at line 60 of file Calib.h.

◆ m_whichPart

int Calib::m_whichPart = -1
private

Definition at line 68 of file Calib.h.


The documentation for this class was generated from the following files: