37 map<int, RunInfo>
ReadRunInfo(
const string& fileNames);
44 int main(
int argc,
char** argv) {
47 cout <<
" Please run: DrumCalib <input-files>\n" << endl;
55 ofstream calibXml(
"FSimulationCalibConfig.generated.xml.in");
56 calibXml <<
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n\n"
57 <<
"<FSimulationCalibConfig xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
58 <<
" xsi:noNamespaceSchemaLocation='@XMLSCHEMALOCATION@/FSimulationCalibConfig.xsd'>\n\n"
59 <<
" <!-- these are used for the flatfielding -->\n\n";
62 for (map<int, RunInfo>::const_iterator iRun = runs.begin();
63 iRun != runs.end(); ++iRun) {
65 const int index = iRun->first;
69 calibXml <<
" <!-- \n"
70 <<
" This set of calibration constants was generated using Offline revision "
72 <<
" with the following set of configuration parameters:\n";
74 <<
" The following Md5-hex-digest encodes this list:\n"
76 calibXml <<
" <EndToEnd signature=\"" << run.
md5 <<
"\"> \n"
77 <<
" <calibration>" << endl;
83 calibXml <<
"</FSimulationCalibConfig>\n";
86 cout <<
"-----------------------------------------------------------------------------" << endl;
87 cout <<
"Telescope(s) calibrated! Output in file \"FSimulationCalibConfig.generated.xml.in\"." << endl;
96 TChain* runInfo =
new TChain(
"runInfo");
97 runInfo->Add(fileNames.c_str());
100 unsigned int nPhotTotal;
102 char offline_rev[100];
103 char config[1000000];
104 runInfo->SetBranchAddress(
"index", &index);
105 runInfo->SetBranchAddress(
"nPhotonsTot", &nPhotTotal);
106 runInfo->SetBranchAddress(
"md5", md5);
107 runInfo->SetBranchAddress(
"offline_rev", offline_rev);
108 runInfo->SetBranchAddress(
"config", config);
110 map<int, RunInfo>
run;
111 for (
int i=0; i<runInfo->GetEntries(); ++i) {
113 runInfo->GetEntry(i);
115 if (run.count(index)) {
116 run[index].nTotalPhotons += nPhotTotal;
117 if (run[index].offlineRev !=
string(offline_rev) ||
118 run[index].configList != config ||
119 run[index].md5 != md5) {
120 cout <<
" ERROR: Input data mismatch ! " << endl;
126 run[index].nTotalPhotons = nPhotTotal;
127 run[index].offlineRev = offline_rev;
128 run[index].configList = config;
129 run[index].md5 = md5;
143 const bool writeErrorsToXml =
false;
145 cout <<
"Calibrate telescope, index = " << index << endl;
147 const int eyeId = index / 100;
148 const int telId = index % 100;
150 ostringstream dataName;
151 dataName <<
"drumData_" << index;
153 TChain* drumData =
new TChain(dataName.str().c_str());
169 double meanError = 0;
170 for (map<int, CalibResult>::const_iterator iCal = constants.begin();
171 iCal != constants.end(); ++iCal) {
173 const int pixelId = iCal->first;
176 const double calib = calData.
calib;
177 const double calibErr = calData.
calibErr;
180 cout <<
" pixel id=" << setw(4) << pixelId
181 <<
" s=" << setw(10) << fixed << calib
182 <<
" +- " << setw(10) << calibErr <<
" [ph/ADC]"
186 calibXml <<
" " << setprecision(16) << setw(18) << calib;
187 if (writeErrorsToXml)
188 calibXml <<
" <!-- +- " << setw(18) << calibErr <<
" -->";
191 meanError += calibErr;
195 if (constants.size())
196 meanError /= constants.size();
198 calibXml <<
" <!-- mean calib. uncertainty: " << setw(18) << meanError <<
" -->";
201 calibXml <<
" </calibration>\n"
213 double nGen, nPix, calib, calibErr, electronicsFactor;
214 drumData->SetBranchAddress(
"id", &pixelId);
215 drumData->SetBranchAddress(
"nGen", &nGen);
216 drumData->SetBranchAddress(
"nPix", &nPix);
217 drumData->SetBranchAddress(
"calib", &calib);
218 drumData->SetBranchAddress(
"calibErr", &calibErr);
219 drumData->SetBranchAddress(
"electronicsFactor", &electronicsFactor);
222 map<int, int> counter;
223 map<int, CalibResult> constants;
226 for (
int i=0; i<drumData->GetEntries(); ++i) {
228 drumData->GetEntry(i);
230 if (counter.count(pixelId)) {
232 constants[pixelId].nPhotGen += nGen;
233 constants[pixelId].nPhotPixel += nPix;
234 if (constants[pixelId].electronicsFactor != electronicsFactor) {
235 cout <<
"ERROR: incompatible pixel data found!" << endl;
239 counter[pixelId] = 1;
240 constants[pixelId].nPhotGen = nGen;
241 constants[pixelId].nPhotPixel = nPix;
242 constants[pixelId].electronicsFactor = electronicsFactor;
243 constants[pixelId].calib = 0;
244 constants[pixelId].calibErr = 0;
251 for (map<int, int>::const_iterator iPix = counter.begin();
252 iPix != counter.end(); ++iPix ) {
256 if (fact != iPix->second) {
257 cout <<
"ERROR: incompatible number of pixels found in input data " << endl;
264 for (map<int, CalibResult>::iterator iPix = constants.begin();
265 iPix != constants.end(); ++iPix ) {
270 const double epsilonErr =
sqrt((epsilon - epsilon*epsilon) / dat.
nPhotGen);
276 const double calibErr = epsilonErr / (epsilon * epsilon * dat.
electronicsFactor);
281 cout <<
"gen=" << dat.
nPhotGen <<
" pix=" << dat.
nPhotPixel <<
" eps=" << epsilon << endl;
int main(int argc, char *argv[])
struct Parameters gParameters
fwk::VModule::ResultFlag(fwk::VModule::* run)(evt::Event &)
void CalibrateTel(ostream &calibXml, const int index, const RunInfo runInfo)
unsigned int nTotalPhotons
map< int, CalibResult > CalibrateTelescope(TChain *data)
map< int, RunInfo > ReadRunInfo(const string &fileNames)