ATLAS Offline Software
PixelCalibration.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //***********************************************************************************************
6 // PixelCalibration - Program to execute the pixel charge calibration (not IBL)
7 // ---------------------------------------
8 // begin : 01 11 2023
9 // email : sergi.rodriguez@cern.ch
10 //***********************************************************************************************
11 
16 
17 #include "TFile.h"
18 
19 #include <iostream>
20 #include <fstream>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include <memory>
26 
27 using pix::PixelMapping;
28 
29 void printError(){
30  printf("ERROR - Argument not expected or wrongly set:\n\n");
31  printf("Valid format is: ./PixelCalib.exe [Blayer, L1, L2, disk] THR=SCAN_Sxxxxxxxxx THRintime=SCAN_Sxxxxxxxxx TOT=SCAN_Sxxxxxxxxx directory_path=path/to/file/ [saveInfo]\n");
32  printf("\n\t i.e: ./PixelCalib.exe Blayer THR=SCAN_S000087719 THR_intime=SCAN_S000087717 TOT=SCAN_S000087710 directory_path=/eos/user/x/xxxx/\n");
33  printf("\nThe example will run Blayer calibration using the scans: SCAN_S000087719.root, SCAN_S000087717.root and SCAN_S000087710.root stored in /eos/user/x/xxxx/\n");
34  printf("\nNOTE: If you type as an argument another layer or file at the same time\n\t e.i: './PixelCalib.exe Blayer L1 THR=SCAN_S000087719 THR_intime=SCAN_S000087717 TOT=SCAN_S000087710 directory_path=/eos/user/x/xxxx/' - Blayer and L1 are in the arguments\n");
35  printf("It will run the last valid layer in the arguments (in the example above will be \"L1\" layer) \n");
36 }
37 
38 
39 int main(int argc, char *argv[]) {
40 
41  int whichPart = -1;
42  bool saveInfo = false;
43  std::string THR = "THR";
44  std::string THRintime = "THRintime";
45  std::string TOT = "TOT";
46  std::string dpath = "directory_path";
47  std::vector<std::string> sWhichPart = {"Blayer","L1","L2","disk"};
48 
49  for(int i=1; i<argc; i++){
50  std::string aux(argv[i]);
51  //0=BLayer, 1=L1, 2=L2, 3=disk
52  if(aux.compare("Blayer") == 0) whichPart = 0;
53  else if(aux.compare("L1") == 0) whichPart = 1;
54  else if(aux.compare("L2") == 0) whichPart = 2;
55  else if(aux.compare("disk") == 0) whichPart = 3;
56  else if(aux.compare("saveInfo") == 0) saveInfo = true;
57  else if(THRintime.compare(aux.substr(0,aux.find("="))) == 0) THRintime = aux.substr(aux.find("=")+1);
58  else if(THR.compare(aux.substr(0,aux.find("="))) == 0) THR = aux.substr(aux.find("=")+1);
59  else if(TOT.compare(aux.substr(0,aux.find("="))) == 0) TOT = aux.substr(aux.find("=")+1);
60  else if(dpath.compare(aux.substr(0,aux.find("="))) == 0) dpath = aux.substr(aux.find("=")+1);
61  else{
62  printError();
63  return 1;
64  }
65 
66  }
67 
68  printf("%-14s = %s\n","Directory path",dpath.c_str());
69  printf("%-14s = %d - %s\n","Pixel part",whichPart, (whichPart < 0 or whichPart > 3) ? "-1" : sWhichPart.at(whichPart).c_str());
70  printf("%-14s = %s.root\n","THR",THR.c_str());
71  printf("%-14s = %s.root\n","THRintime",THRintime.c_str());
72  printf("%-14s = %s.root\n","TOT",TOT.c_str());
73  printf("%-14s = %s\n\n\n","Save root file",saveInfo ? "True" : "False" );
74 
75 
76  bool correctArgc = (whichPart < 0 or whichPart > 3) or (THR.compare("THR") == 0) or (THRintime.compare("THRintime") == 0) or (TOT.compare("TOT") == 0) or (dpath.compare("directory_path") == 0);
77 
78  if(correctArgc){
79  printf("Cannot continue, one arguments is incorrect or not filled correctly...\n");
80  printf("Helper below:\n**********************\n\n");
81  printError();
82  return 1;
83  }
84 
85  std::string thres_f = dpath+THR+".root";
86  std::string timin_f = dpath+THRintime+".root";
87  std::string totin_f = dpath+TOT+".root";
88 
89 
90  // creating the object for the pixel mapping
91  PixelMapping pixmap(PathResolver::find_file("PixelCalibAlgs/mapping.csv", "DATAPATH"));
92 
93  // object to store all the necessary calibration information
94  std::map<unsigned int , std::vector<std::unique_ptr<CalibFrontEndInfo>> > map_values;
95 
96  std::unique_ptr<TFile> wFile = std::make_unique<TFile>();
97 
98  time_t start, end;
99 
100  time(&start);
101  //Setting up the Calibration functions.
102  printf("Time to calculate threshold calibration\n");
103  std::string moduleName = "";
104  Calib Calibration(whichPart,saveInfo, moduleName);
105  if(!(Calibration.fillThresholds(pixmap ,thres_f ,map_values )) ){
106  printf("Error - The threshold calibration was not properly finished.\n");
107  return 1;
108  }
109  time(&end);
110  printf("Time taken for threshold calibration:%7.1f seconds\n",double(end - start));
111 
112  if(map_values.size() == 0){
113 
114  // If we are running over just one module, and it is not created already in the map means that this is not the correct layer
115  if( std::strcmp(moduleName.c_str(), "") != 0 ){
116  printf("main::main: Running only one module: %s - It does not belong to %s\n",moduleName.c_str(), sWhichPart.at(whichPart).c_str());
117  return 0;
118  }
119  printf("main::main: ERROR - Size of filled map is 0. Does the %s exist in the %s file?\n",sWhichPart.at(whichPart).c_str(),thres_f.c_str());
120  return 1;
121  }
122 
123  time(&start);
124  //Setting up the Timing functions.
125  printf("Time to take timing calibration\n");
126  if(!(Calibration.fillTiming(pixmap ,timin_f ,map_values )) ){
127  printf("Error - The timing calibration was not properly finished.\n");
128  return 1;
129  }
130  time(&end);
131  printf("Time taken for timing calibration:%7.1f seconds\n",double(end - start));
132 
133  time(&start);
134  //Setting up the tot functions.
135  printf("Time to take TOT calibration\n");
136  if(!(Calibration.totFitting(pixmap ,totin_f ,map_values )) ){
137  printf("Error - The TOT calibration was not properly finished.\n");
138  return 1;
139  }
140  time(&end);
141  printf("Time taken for TOT calibration:%7.1f seconds\n",double(end - start));
142 
143  std::ofstream myFile("calibration_"+sWhichPart.at(whichPart)+".txt");
144  //cppcheck-suppress invalidPrintfArgType_uint
145  printf("Total MODs:%4lu\n",map_values.size());
146  for(const auto & [key, MOD] : map_values){
147 
148  for(const auto& FE : MOD){
149  std::stringstream sstr = FE->printDBformat();
150  printf("%s\n",sstr.str().c_str());
151  myFile << sstr.str() << "\n";
152  }
153  }
154 
155  myFile.close();
156 
157  printf("********** JOB finished **********\n");
158  return 0;
159 }
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
PixelMapping.h
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
CalibFrontEndInfo.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
Calib
Definition: Calib.h:34
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
pix::PixelMapping
Definition: PixelMapping.h:18
Calib.h
PathResolver.h
printError
void printError()
Definition: PixelCalibration.cxx:29
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
main
int main(int argc, char *argv[])
Definition: PixelCalibration.cxx:39
Calib::fillThresholds
bool fillThresholds(const pix::PixelMapping &pm, const std::string &inThrFile, std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo >> > &map_info)
Definition: Calib.cxx:532
Calib::totFitting
bool totFitting(const pix::PixelMapping &pm, const std::string &inTimFile, std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo >> > &map_info)
Definition: Calib.cxx:15
Calib::fillTiming
bool fillTiming(const pix::PixelMapping &pm, const std::string &inTimFile, std::map< unsigned int, std::vector< std::unique_ptr< CalibFrontEndInfo >> > &map_info)
Definition: Calib.cxx:352
extractSporadic.myFile
myFile
Definition: extractSporadic.py:87
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37