ATLAS Offline Software
Loading...
Searching...
No Matches
TileRawChNoiseCalibAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ****** **************************************************************
6//
7// NAME: TileRawChNoiseCalib.cxx
8// PACKAGE: TileCalib
9//
10// AUTHOR: Luca Fiorini (Luca.Fiorini@cern.ch)
11//
12// April 2008
13// ********************************************************************
14
15
16
17#include "GaudiKernel/ISvcLocator.h"
18
19//Event info
23
24// Tile includes
33#include "CxxUtils/FPControl.h"
34
35
36#include "TFile.h"
37#include "TTree.h"
38#include "TH1F.h"
39#include "TF1.h"
40#include "TFitResult.h"
41#include "TFitResultPtr.h"
42#include "TMatrixDSym.h"
43#include "TGraphErrors.h"
44#include "TClonesArray.h"
45
46#include <cmath>
47#include <ctime>
48#include <iostream>
49
50
51TileRawChNoiseCalibAlg::TileRawChNoiseCalibAlg(const std::string& name, ISvcLocator* pSvcLocator)
52 : AthAlgorithm(name,pSvcLocator)
53 , m_beamCnv(nullptr)
54 , m_cabling(nullptr)
55 , m_tileID(nullptr)
56 , m_tileHWID(nullptr)
57 , m_cispar(nullptr)
58 //, m_nDrawers(0)
59 , m_time(0)
60 , m_year(0)
61 , m_month(0)
62 , m_day(0)
63 , m_yday(0)
64 , m_hour(0)
65 , m_min(0)
66 , m_run(0)
67 , m_trigType(0)
68{
69
70 declareProperty("TileDigitsContainer", m_digitsContainer = "TileDigitsCnt");
71 declareProperty("TileBeamElemContainer", m_beamElemContainer = "TileBeamElemCnt");
72 declareProperty("doFit" , m_doFit = true);
73 declareProperty("doFixed", m_doFixed = true);
74 declareProperty("doOpt" , m_doOpt = true);
75 declareProperty("doDsp" , m_doDsp = true);
76 declareProperty("doOF1" , m_doOF1 = true);
77 declareProperty("doMF" , m_doMF = true);
78 declareProperty("SaveHist", m_saveHist = false); // write all histograms to output file
79 declareProperty("InvertChanRatio", m_invertChanRatio = true); // swap two sigmas and invert ratio if it is above 1.0 (channel fit only)
80 declareProperty("MaskBadChannels",m_maskBadChannels = true);
81 declareProperty("UseforCells" , m_UseforCells = 2); // Fit=0, Fixed=1, Opt=2, Dsp=3, OF1=4, MF=5
82 declareProperty("CalibMode", m_calibMode = true);
83 declareProperty("UsePMT", m_usePMT = false);
84 declareProperty("RunNumber", m_run=0);
85 declareProperty("FileNamePrefix", m_file="RawCh_NoiseCalib");
86 declareProperty("NtupleID", m_ntupleID="RawCh_NoiseCalib");
87 declareProperty("TreeSize", m_treeSize = 16000000000LL);
88 declareProperty("TileDQstatus", m_dqStatusKey = "TileDQstatus");
89
90 m_evtNr=-1;
91
92 m_fillidx=false;
93
121
130
142}
143
145{
146 delete[] m_histAmp;
147 delete[] m_histCellAmp;
148 delete[] m_evt;
149 delete[] m_ros;
150 delete[] m_drawer;
151 delete[] m_channel;
152 delete[] m_gain;
153 delete[] m_rc_mean;
154 delete[] m_rc_sigma;
155 delete[] m_rc_av;
156 delete[] m_rc_rms;
157 delete[] m_rc_skewness;
158 delete[] m_rc_kurtosis;
159 delete[] m_rc_mean_err;
160 delete[] m_rc_sigma_err;
161 delete[] m_rc_chi2;
162 delete[] m_rc_ndf;
163 delete[] m_rc_probC2;
164 delete[] m_rc_ggpar;
165 delete[] m_rc_gsigma1;
166 delete[] m_rc_gsigma2;
167 delete[] m_rc_gnorm;
168 delete[] m_rc_gchi2;
169 delete[] m_rc_gerrsigma1;
170 delete[] m_rc_gerrsigma2;
171 delete[] m_rc_gerrnorm;
172 delete[] m_rc_gcorrsigma1sigma2;
173
174 delete[] m_side;
175 delete[] m_phi;
176 delete[] m_sample;
177 delete[] m_tower;
178 delete[] m_gg;
179 delete[] m_ecell_av;
180 delete[] m_ecell_rms;
181 delete[] m_ecell_hash;
182
183 delete[] m_cell_nch;
184 delete[] m_ecell_ene;
185 delete[] m_ggpar;
186 delete[] m_gsigma1;
187 delete[] m_gsigma2;
188 delete[] m_gnorm;
189 delete[] m_gchi2;
190 delete[] m_gerrsigma1;
191 delete[] m_gerrsigma2;
192 delete[] m_gerrnorm;
193 delete[] m_gcorrsigma1sigma2;
194}
195
199
200 int nbin = 151;
201 float binwidth[2] = { 0.125, 0.25 }; // in ADC
202 float xmax[2] = { (float) nbin * binwidth[0] / 2.F, (float) nbin * binwidth[1] / 2.F }; // in ADC
203
204 std::ostringstream sStr;
205 std::string nam;
206
207 for (int rc = 0; rc < RCnum; ++rc) {
208 for (unsigned int ros = 1; ros < TileCalibUtils::MAX_ROS; ++ros) {
209 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
210 for (unsigned int ch = 0; ch < TileCalibUtils::MAX_CHAN; ++ch) {
211 for (unsigned int g = 0; g < TileCalibUtils::MAX_GAIN; ++g) {
212 sStr.str("");
213 sStr << "Amplitudes_RC_" << rc << "_Part_" << ros << "_Drawer_" << drawer << "_Ch_" << ch << "_Gain_" << g;
214 nam = sStr.str();
215 m_histAmp[rc][ros][drawer][ch][g] = new TH1F(nam.c_str(), nam.c_str(), nbin, -xmax[g], xmax[g]);
216 m_histAmp[rc][ros][drawer][ch][g]->SetCanExtend(TH1::kAllAxes); //in case some entries are outside the initial limits
217 m_histAmp[rc][ros][drawer][ch][g]->SetDirectory(nullptr);
218 }
219 }
220 }
221 }
222 }
223
224 nbin = 301;
225 float cellbin[2] = { 80., 2.5 }; //in MeV
226 float xcellmax[2] = { (float) nbin * cellbin[0] / 2.F, (float) nbin * cellbin[1] / 2.F }; //in MeV
227
228 for (int side = 0; side < NSIDES; side++) {
229 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
230 for (int sample = 0; sample < NSAMPLES; sample++) {
231 for (int tower = 0; tower < NTOWERS; tower++) {
232 for (int gg = 0; gg < NCELLGAINS; gg++) {
233 sStr.str("");
234 sStr << "CellAmplitude_Side_" << side << "_Drawer_" << drawer << "_Sample_" << sample << "_Tower_" << tower << "_Gains_" << gg;
235 nam = sStr.str();
236 m_histCellAmp[side][drawer][sample][tower][gg] = new TH1F(nam.c_str(), nam.c_str(), nbin, -xcellmax[gg / 3], xcellmax[gg / 3]); // cell limits should be at least sqrt(2)*channel limits
237 m_histCellAmp[side][drawer][sample][tower][gg]->SetCanExtend(TH1::kAllAxes); //in case some entries are outside the initial limits
238 m_histCellAmp[side][drawer][sample][tower][gg]->SetDirectory(nullptr);
239 }
240 }
241 }
242 }
243 }
244
245
246 //=== get TileCondToolEmscale
247 CHECK( m_tileToolEmscale.retrieve() );
248
249 //=== get TileBadChanTool
250 CHECK( m_tileBadChanTool.retrieve() );
251
252 //=== get TileCondIdTransforms
253 CHECK( m_tileIdTrans.retrieve() );
254
255 CHECK( m_dqStatusKey.initialize() );
256
263
264 if (!m_eventInfoKey.key().empty()) {
265 ATH_CHECK( m_eventInfoKey.initialize() );
266 }
267
268 return StatusCode::SUCCESS;
269}
270
274
275
276 // find TileCablingService
278
279 // retrieve TileID helper from det store
280 CHECK( detStore()->retrieve(m_tileID) );
281
282 CHECK( detStore()->retrieve(m_tileHWID) );
283
284 ATH_MSG_INFO( "calibMode " << m_calibMode );
285
286
287 // set event number to 0 before first event
288
289 if ( m_evtNr < 0 ) {
290 m_evtNr = 0;
291 if (m_beamElemContainer.length() > 0) {
292 ServiceHandle<IConversionSvc> cnvSvc("ByteStreamCnvSvc","");
293 if (cnvSvc.retrieve().isFailure()) {
294 ATH_MSG_ERROR( " Can't get ByteStreamCnvSvc " );
295 m_beamCnv = nullptr;
296
297 } else {
298
299 m_beamCnv = dynamic_cast<TileBeamElemContByteStreamCnv *> ( cnvSvc->converter( ClassID_traits<TileBeamElemContainer>::ID() ) );
300
301 if ( m_beamCnv == nullptr ) {
302 ATH_MSG_ERROR( " Can't get TileBeamElemContByteStreamCnv " );
303 }
304 }
305 } else {
306 m_beamCnv = nullptr;
307 }
308 }
309
310 ATH_MSG_INFO( "initialization completed" );
311
312 return StatusCode::SUCCESS;
313
314}
315
318
319 const EventContext& ctx = Gaudi::Hive::currentContext();
320 const TileDQstatus* dqStatus = SG::makeHandle (m_dqStatusKey, ctx).get();
321
322 bool empty(false); // to add all StatusCodes
323
324 if (m_evtNr < 0) {
325
326 if (FirstEvt_initialize().isFailure()) { ATH_MSG_ERROR( "FirstEvt_initialize failed" ); }
327
328 bool calibMode = (dqStatus->calibMode() == 1);
329 if ( calibMode != m_calibMode ) {
330 ATH_MSG_INFO( "Overwriting calib mode [" << m_calibMode << "] by one from data: " << calibMode );
331 m_calibMode = calibMode;
332 }
333
334 m_cispar = dqStatus->cispar();
335 StoreRunInfo(dqStatus); // done only once
336 }
337
338 memset(m_ecell_ene ,0, 2 * sizeof( *m_ecell_ene ));
339 memset(m_cell_nch ,0, 2 * sizeof( *m_cell_nch ));
340
341 m_cispar = dqStatus->cispar();
342 if (m_evtNr % 1000 == 0) ATH_MSG_INFO( " events processed so far " << m_evtNr );
343
344
345 if (m_doFit) {empty &= (fillRawChannels(dqStatus, m_rawChannelContainerFitKey, Fit).isFailure());}
346 if (m_doFixed) {empty &= (fillRawChannels(dqStatus, m_rawChannelContainerFixedKey, Fixed).isFailure());}
347 if (m_doOpt) {empty &= (fillRawChannels(dqStatus, m_rawChannelContainerOptKey, Opt).isFailure());}
348 if (m_doDsp) {empty &= (fillRawChannels(dqStatus, m_rawChannelContainerDspKey, Dsp).isFailure());}
349 if (m_doOF1) {empty &= (fillRawChannels(dqStatus, m_rawChannelContainerOF1Key, OF1).isFailure());}
350 if (m_doMF) {empty &= (fillRawChannels(dqStatus, m_rawChannelContainerMFKey, MF).isFailure());}
351
352
353 if (empty) {ATH_MSG_ERROR( "Error in execute " ); }
354 ++m_evtNr;
355
356 return StatusCode::SUCCESS;
357}
358
359
362
363 ATH_MSG_INFO( "Finalizing TileRawChNoiseCalibAlg" );
364
365 if (m_doFit) finalRawCh(Fit);
367 if (m_doOpt) finalRawCh(Opt);
368 if (m_doDsp) finalRawCh(Dsp);
369 if (m_doOF1) finalRawCh(OF1);
370 if (m_doMF) finalRawCh(MF);
371
372 if (m_UseforCells == 0) {
373 if (m_doFit) finalCell();
374 } else if (m_UseforCells == 1) {
375 if (m_doFixed) finalCell();
376 } else if (m_UseforCells == 2) {
377 if (m_doOpt) finalCell();
378 } else if (m_UseforCells == 3) {
379 if (m_doDsp) finalCell();
380 } else if (m_UseforCells == 4) {
381 if (m_doOF1) finalCell();
382 } else if (m_UseforCells == 5) {
383 if (m_doMF) finalCell();
384 } else {
385 ATH_MSG_WARNING( "unknown rawchannel type used for cells" << m_UseforCells );
386 }
387
388 std::ostringstream sStr;
389 std::string trig_str;
390
391 if (m_trigType == Phys) trig_str = "Phys";
392 else if (m_trigType == Las) trig_str = "Las";
393 else if (m_trigType == Ped) trig_str = "Ped";
394 else if (m_trigType == Cis) trig_str = "Cis";
395 else {
396 ATH_MSG_WARNING( "Unknown trigger type " << m_trigType );
397 trig_str = "Unk";
398 }
399
400 sStr << m_file << "_" << m_run << "_" << trig_str << ".root";
401 m_file = sStr.str();
402 ATH_MSG_INFO( "Writing calibrations to file " << m_file );
403
404 // Create output file: for now creating file for just this
405 // algorithm; want to add to ntuple file eventually??
406 TFile* fout = new TFile(m_file.c_str(), "recreate");
407
408 // Create tree with branches
409 TTree* t = new TTree(m_ntupleID.c_str(), "Tile_RC_NoiseCalib-Ntuple");
410
411 t->Branch("RunNumber", &m_run, "RunNumber/I");
412 t->Branch("TrigType", &m_trigType, "TrigType/I");
413 t->Branch("Time", &m_time, "Time/I");
414 t->Branch("Year", &m_year, "Year/I");
415 t->Branch("Month", &m_month, "Month/I");
416 t->Branch("Day", &m_day, "Day/I");
417 t->Branch("YDay", &m_yday, "YDay/I");
418 t->Branch("Hour", &m_hour, "Hour/I");
419 t->Branch("Min", &m_min, "Min/I");
420 t->Branch("nEvt", &m_evtNr, "nEvt/I"); // events processed
421 t->Branch("EvtNr", &m_evtNr, "EvtNr/I");
422 t->Branch("EvtGood", *m_evt, "Evt[5][64][48][2]/I"); // events used in the noise calculation for every channel
423
424
425 t->Branch("ros", *m_ros, "ros[5][64][48][2]/b");
426 t->Branch("drawer", *m_drawer, "drawer[5][64][48][2]/b");
427 t->Branch("channel", *m_channel, "channel[5][64][48][2]/b");
428 t->Branch("gain", *m_gain, "gain[5][64][48][2]/O");
429
430 t->Branch("efit_mean",*(m_rc_mean[Fit]),"efit_mean[5][64][48][2]/F");
431 t->Branch("efit_av",*(m_rc_av[Fit]),"efit_av[5][64][48][2]/F");
432 t->Branch("efit_rms",*(m_rc_rms[Fit]),"efit_rms[5][64][48][2]/F");
433 t->Branch("efit_sigma",*(m_rc_sigma[Fit]),"efit_sigma[5][64][48][2]/F");
434 t->Branch("efit_mean_err",*(m_rc_mean_err[Fit]),"efit_mean_err[5][64][48][2]/F");
435 t->Branch("efit_sigma_err",*(m_rc_sigma_err[Fit]),"efit_sigma_err[5][64][48][2]/F");
436 t->Branch("efit_kurtosis",*(m_rc_kurtosis[Fit]),"efit_kurtosis[5][64][48][2]/F");
437 t->Branch("efit_skewness",*(m_rc_skewness[Fit]),"efit_skewness[5][64][48][2]/F");
438 t->Branch("efit_chi2",*(m_rc_chi2[Fit]),"efit_chi2[5][64][48][2]/F");
439 t->Branch("efit_ndf",*(m_rc_ndf[Fit]),"efit_ndf[5][64][48][2]/F");
440 t->Branch("efit_probC2",*(m_rc_probC2[Fit]),"efit_probC2[5][64][48][2]/F");
441
442 t->Branch("efit_gsigma1",*(m_rc_gsigma1[Fit]),"efit_gsigma1[5][64][48][2]/F");
443 t->Branch("efit_gsigma2",*(m_rc_gsigma2[Fit]),"efit_gsigma2[5][64][48][2]/F");
444 t->Branch("efit_gnorm",*(m_rc_gnorm[Fit]),"efit_gnorm[5][64][48][2]/F");
445 t->Branch("efit_gchi2",*(m_rc_gchi2[Fit]),"efit_gchi2[5][64][48][2]/F");
446 t->Branch("efit_gerrsigma1",*(m_rc_gerrsigma1[Fit]),"efit_gerrsigma1[5][64][48][2]/F");
447 t->Branch("efit_gerrnorm",*(m_rc_gerrnorm[Fit]),"efit_gerrnorm[5][64][48][2]/F");
448 t->Branch("efit_gerrsigma2",*(m_rc_gerrsigma2[Fit]),"efit_gerrsigma2[5][64][48][2]/F");
449 t->Branch("efit_gcorrsigma1sigma2",*(m_rc_gcorrsigma1sigma2[Fit]),"efit_gcorrsigma1sigma2[5][64][48][2]/F");
450
451
452 t->Branch("efixed_mean",*(m_rc_mean[Fixed]),"efixed_mean[5][64][48][2]/F");
453 t->Branch("efixed_av",*(m_rc_av[Fixed]),"efixed_av[5][64][48][2]/F");
454 t->Branch("efixed_rms",*(m_rc_rms[Fixed]),"efixed_rms[5][64][48][2]/F");
455 t->Branch("efixed_sigma",*(m_rc_sigma[Fixed]),"efixed_sigma[5][64][48][2]/F");
456 t->Branch("efixed_mean_err",*(m_rc_mean_err[Fixed]),"efixed_mean_err[5][64][48][2]/F");
457 t->Branch("efixed_sigma_err",*(m_rc_sigma_err[Fixed]),"efixed_sigma_err[5][64][48][2]/F");
458 t->Branch("efixed_kurtosis",*(m_rc_kurtosis[Fixed]),"efixed_kurtosis[5][64][48][2]/F");
459 t->Branch("efixed_skewness",*(m_rc_skewness[Fixed]),"efixed_skewness[5][64][48][2]/F");
460 t->Branch("efixed_chi2",*(m_rc_chi2[Fixed]),"efixed_chi2[5][64][48][2]/F");
461 t->Branch("efixed_ndf",*(m_rc_ndf[Fixed]),"efixed_ndf[5][64][48][2]/F");
462 t->Branch("efixed_probC2",*(m_rc_probC2[Fixed]),"efixed_probC2[5][64][48][2]/F");
463
464 t->Branch("efixed_gsigma1",*(m_rc_gsigma1[Fixed]),"efixed_gsigma1[5][64][48][2]/F");
465 t->Branch("efixed_gsigma2",*(m_rc_gsigma2[Fixed]),"efixed_gsigma2[5][64][48][2]/F");
466 t->Branch("efixed_gnorm",*(m_rc_gnorm[Fixed]),"efixed_gnorm[5][64][48][2]/F");
467 t->Branch("efixed_gchi2",*(m_rc_gchi2[Fixed]),"efixed_gchi2[5][64][48][2]/F");
468 t->Branch("efixed_gerrsigma1",*(m_rc_gerrsigma1[Fixed]),"efixed_gerrsigma1[5][64][48][2]/F");
469 t->Branch("efixed_gerrnorm",*(m_rc_gerrnorm[Fixed]),"efixed_gerrnorm[5][64][48][2]/F");
470 t->Branch("efixed_gerrsigma2",*(m_rc_gerrsigma2[Fixed]),"efixed_gerrsigma2[5][64][48][2]/F");
471 t->Branch("efixed_gcorrsigma1sigma2",*(m_rc_gcorrsigma1sigma2[Fixed]),"efixed_gcorrsigma1sigma2[5][64][48][2]/F");
472
473
474 t->Branch("eopt_mean",*(m_rc_mean[Opt]),"eopt_mean[5][64][48][2]/F");
475 t->Branch("eopt_av",*(m_rc_av[Opt]),"eopt_av[5][64][48][2]/F");
476 t->Branch("eopt_rms",*(m_rc_rms[Opt]),"eopt_rms[5][64][48][2]/F");
477 t->Branch("eopt_sigma",*(m_rc_sigma[Opt]),"eopt_sigma[5][64][48][2]/F");
478 t->Branch("eopt_mean_err",*(m_rc_mean_err[Opt]),"eopt_mean_err[5][64][48][2]/F");
479 t->Branch("eopt_sigma_err",*(m_rc_sigma_err[Opt]),"eopt_sigma_err[5][64][48][2]/F");
480 t->Branch("eopt_kurtosis",*(m_rc_kurtosis[Opt]),"eopt_kurtosis[5][64][48][2]/F");
481 t->Branch("eopt_skewness",*(m_rc_skewness[Opt]),"eopt_skewness[5][64][48][2]/F");
482 t->Branch("eopt_chi2",*(m_rc_chi2[Opt]),"eopt_chi2[5][64][48][2]/F");
483 t->Branch("eopt_ndf",*(m_rc_ndf[Opt]),"eopt_ndf[5][64][48][2]/F");
484 t->Branch("eopt_probC2",*(m_rc_probC2[Opt]),"eopt_probC2[5][64][48][2]/F");
485
486 t->Branch("eopt_gsigma1",*(m_rc_gsigma1[Opt]),"eopt_gsigma1[5][64][48][2]/F");
487 t->Branch("eopt_gsigma2",*(m_rc_gsigma2[Opt]),"eopt_gsigma2[5][64][48][2]/F");
488 t->Branch("eopt_gnorm",*(m_rc_gnorm[Opt]),"eopt_gnorm[5][64][48][2]/F");
489 t->Branch("eopt_gchi2",*(m_rc_gchi2[Opt]),"eopt_gchi2[5][64][48][2]/F");
490 t->Branch("eopt_gerrsigma1",*(m_rc_gerrsigma1[Opt]),"eopt_gerrsigma1[5][64][48][2]/F");
491 t->Branch("eopt_gerrnorm",*(m_rc_gerrnorm[Opt]),"eopt_gerrnorm[5][64][48][2]/F");
492 t->Branch("eopt_gerrsigma2",*(m_rc_gerrsigma2[Opt]),"eopt_gerrsigma2[5][64][48][2]/F");
493 t->Branch("eopt_gcorrsigma1sigma2",*(m_rc_gcorrsigma1sigma2[Opt]),"eopt_gcorrsigma1sigma2[5][64][48][2]/F");
494
495
496 t->Branch("edsp_mean",*(m_rc_mean[Dsp]),"edsp_mean[5][64][48][2]/F");
497 t->Branch("edsp_av",*(m_rc_av[Dsp]),"edsp_av[5][64][48][2]/F");
498 t->Branch("edsp_rms",*(m_rc_rms[Dsp]),"edsp_rms[5][64][48][2]/F");
499 t->Branch("edsp_sigma",*(m_rc_sigma[Dsp]),"edsp_sigma[5][64][48][2]/F");
500 t->Branch("edsp_mean_err",*(m_rc_mean_err[Dsp]),"edsp_mean_err[5][64][48][2]/F");
501 t->Branch("edsp_sigma_err",*(m_rc_sigma_err[Dsp]),"edsp_sigma_err[5][64][48][2]/F");
502 t->Branch("edsp_kurtosis",*(m_rc_kurtosis[Dsp]),"edsp_kurtosis[5][64][48][2]/F");
503 t->Branch("edsp_skewness",*(m_rc_skewness[Dsp]),"edsp_skewness[5][64][48][2]/F");
504 t->Branch("edsp_chi2",*(m_rc_chi2[Dsp]),"edsp_chi2[5][64][48][2]/F");
505 t->Branch("edsp_ndf",*(m_rc_ndf[Dsp]),"edsp_ndf[5][64][48][2]/F");
506 t->Branch("edsp_probC2",*(m_rc_probC2[Dsp]),"edsp_probC2[5][64][48][2]/F");
507
508 t->Branch("edsp_gsigma1",*(m_rc_gsigma1[Dsp]),"edsp_gsigma1[5][64][48][2]/F");
509 t->Branch("edsp_gsigma2",*(m_rc_gsigma2[Dsp]),"edsp_gsigma2[5][64][48][2]/F");
510 t->Branch("edsp_gnorm",*(m_rc_gnorm[Dsp]),"edsp_gnorm[5][64][48][2]/F");
511 t->Branch("edsp_gchi2",*(m_rc_gchi2[Dsp]),"edsp_gchi2[5][64][48][2]/F");
512 t->Branch("edsp_gerrsigma1",*(m_rc_gerrsigma1[Dsp]),"edsp_gerrsigma1[5][64][48][2]/F");
513 t->Branch("edsp_gerrnorm",*(m_rc_gerrnorm[Dsp]),"edsp_gerrnorm[5][64][48][2]/F");
514 t->Branch("edsp_gerrsigma2",*(m_rc_gerrsigma2[Dsp]),"edsp_gerrsigma2[5][64][48][2]/F");
515 t->Branch("edsp_gcorrsigma1sigma2",*(m_rc_gcorrsigma1sigma2[Dsp]),"edsp_gcorrsigma1sigma2[5][64][48][2]/F");
516
517
518 t->Branch("eOF1_mean",*(m_rc_mean[OF1]),"eOF1_mean[5][64][48][2]/F");
519 t->Branch("eOF1_av",*(m_rc_av[OF1]),"eOF1_av[5][64][48][2]/F");
520 t->Branch("eOF1_rms",*(m_rc_rms[OF1]),"eOF1_rms[5][64][48][2]/F");
521 t->Branch("eOF1_sigma",*(m_rc_sigma[OF1]),"eOF1_sigma[5][64][48][2]/F");
522 t->Branch("eOF1_mean_err",*(m_rc_mean_err[OF1]),"eOF1_mean_err[5][64][48][2]/F");
523 t->Branch("eOF1_sigma_err",*(m_rc_sigma_err[OF1]),"eOF1_sigma_err[5][64][48][2]/F");
524 t->Branch("eOF1_kurtosis",*(m_rc_kurtosis[OF1]),"eOF1_kurtosis[5][64][48][2]/F");
525 t->Branch("eOF1_skewness",*(m_rc_skewness[OF1]),"eOF1_skewness[5][64][48][2]/F");
526 t->Branch("eOF1_chi2",*(m_rc_chi2[OF1]),"eOF1_chi2[5][64][48][2]/F");
527 t->Branch("eOF1_ndf",*(m_rc_ndf[OF1]),"eOF1_ndf[5][64][48][2]/F");
528 t->Branch("eOF1_probC2",*(m_rc_probC2[OF1]),"eOF1_probC2[5][64][48][2]/F");
529
530 t->Branch("eOF1_gsigma1",*(m_rc_gsigma1[OF1]),"eOF1_gsigma1[5][64][48][2]/F");
531 t->Branch("eOF1_gsigma2",*(m_rc_gsigma2[OF1]),"eOF1_gsigma2[5][64][48][2]/F");
532 t->Branch("eOF1_gnorm",*(m_rc_gnorm[OF1]),"eOF1_gnorm[5][64][48][2]/F");
533 t->Branch("eOF1_gchi2",*(m_rc_gchi2[OF1]),"eOF1_gchi2[5][64][48][2]/F");
534 t->Branch("eOF1_gerrsigma1",*(m_rc_gerrsigma1[OF1]),"eOF1_gerrsigma1[5][64][48][2]/F");
535 t->Branch("eOF1_gerrnorm",*(m_rc_gerrnorm[OF1]),"eOF1_gerrnorm[5][64][48][2]/F");
536 t->Branch("eOF1_gerrsigma2",*(m_rc_gerrsigma2[OF1]),"eOF1_gerrsigma2[5][64][48][2]/F");
537 t->Branch("eOF1_gcorrsigma1sigma2",*(m_rc_gcorrsigma1sigma2[OF1]),"eOF1_gcorrsigma1sigma2[5][64][48][2]/F");
538
539
540 t->Branch("eMF_mean",*(m_rc_mean[MF]),"eMF_mean[5][64][48][2]/F");
541 t->Branch("eMF_av",*(m_rc_av[MF]),"eMF_av[5][64][48][2]/F");
542 t->Branch("eMF_rms",*(m_rc_rms[MF]),"eMF_rms[5][64][48][2]/F");
543 t->Branch("eMF_sigma",*(m_rc_sigma[MF]),"eMF_sigma[5][64][48][2]/F");
544 t->Branch("eMF_mean_err",*(m_rc_mean_err[MF]),"eMF_mean_err[5][64][48][2]/F");
545 t->Branch("eMF_sigma_err",*(m_rc_sigma_err[MF]),"eMF_sigma_err[5][64][48][2]/F");
546 t->Branch("eMF_kurtosis",*(m_rc_kurtosis[MF]),"eMF_kurtosis[5][64][48][2]/F");
547 t->Branch("eMF_skewness",*(m_rc_skewness[MF]),"eMF_skewness[5][64][48][2]/F");
548 t->Branch("eMF_chi2",*(m_rc_chi2[MF]),"eMF_chi2[5][64][48][2]/F");
549 t->Branch("eMF_ndf",*(m_rc_ndf[MF]),"eMF_ndf[5][64][48][2]/F");
550 t->Branch("eMF_probC2",*(m_rc_probC2[MF]),"eMF_probC2[5][64][48][2]/F");
551
552 t->Branch("eMF_gsigma1",*(m_rc_gsigma1[MF]),"eMF_gsigma1[5][64][48][2]/F");
553 t->Branch("eMF_gsigma2",*(m_rc_gsigma2[MF]),"eMF_gsigma2[5][64][48][2]/F");
554 t->Branch("eMF_gnorm",*(m_rc_gnorm[MF]),"eMF_gnorm[5][64][48][2]/F");
555 t->Branch("eMF_gchi2",*(m_rc_gchi2[MF]),"eMF_gchi2[5][64][48][2]/F");
556 t->Branch("eMF_gerrsigma1",*(m_rc_gerrsigma1[MF]),"eMF_gerrsigma1[5][64][48][2]/F");
557 t->Branch("eMF_gerrnorm",*(m_rc_gerrnorm[MF]),"eMF_gerrnorm[5][64][48][2]/F");
558 t->Branch("eMF_gerrsigma2",*(m_rc_gerrsigma2[MF]),"eMF_gerrsigma2[5][64][48][2]/F");
559 t->Branch("eMF_gcorrsigma1sigma2",*(m_rc_gcorrsigma1sigma2[MF]),"eMF_gcorrsigma1sigma2[5][64][48][2]/F");
560
561
562 t->Branch("ecell_av",*(m_ecell_av),"ecell_av[2][64][4][17][6]/F");
563 t->Branch("ecell_rms",*(m_ecell_rms),"ecell_rms[2][64][4][17][6]/F");
564 t->Branch("ecell_hash",*(m_ecell_hash),"ecell_hash[2][64][4][17]/i");
565 t->Branch("ecell_gsigma1",*(m_gsigma1),"ecell_gsigma1[2][64][4][17][6]/F");
566 t->Branch("ecell_gsigma2",*(m_gsigma2),"ecell_gsigma2[2][64][4][17][6]/F");
567 t->Branch("ecell_gnorm",*(m_gnorm),"ecell_gnorm[2][64][4][17][6]/F");
568 t->Branch("ecell_gchi2",*(m_gchi2),"ecell_gchi2[2][64][4][17][6]/F");
569 t->Branch("ecell_gerrsigma1",*(m_gerrsigma1),"ecell_gerrsigma1[2][64][4][17][6]/F");
570 t->Branch("ecell_gerrnorm",*(m_gerrnorm),"ecell_gerrnorm[2][64][4][17][6]/F");
571 t->Branch("ecell_gerrsigma2",*(m_gerrsigma2),"ecell_gerrsigma2[2][64][4][17][6]/F");
572 t->Branch("ecell_gcorrsigma1sigma2",*(m_gcorrsigma1sigma2),"ecell_gcorrsigma1sigma2[2][64][4][17][6]/F");
573// t->Branch("ecell_gcorrsigma1norm",*(gcorrsigma1norm),"ecell_gcorrsigma1norm[2][64][4][17][6]/F");
574// t->Branch("ecell_gcorrsigma2norm",*(gcorrsigma2norm),"ecell_gcorrsigma2norm[2][64][4][17][6]/F");
575 t->Branch("side", *m_side, "side[2][64][4][17][6]/O");
576 t->Branch("phi", *m_phi, "phi[2][64][4][17][6]/b");
577 t->Branch("sample", *m_sample, "sample[2][64][4][17][6]/b");
578 t->Branch("tower", *m_tower, "tower[2][64][4][17][6]/b");
579 t->Branch("gaingain", *m_gg, "gaingain[2][64][4][17][6]/b");
580
581 // Fill with current values (i.e. tree will have only one entry for this whole run)
582
583 t->Fill();
584 t->Write();
585
586 if (m_saveHist) {
587
588 for (int rc = 0; rc < RCnum; ++rc) {
589
590 if ((m_doFit && rc == Fit)
591 || (m_doFixed && rc == Fixed)
592 || (m_doOpt && rc == Opt)
593 || (m_doDsp && rc == Dsp)
594 || (m_doOF1 && rc == OF1)
595 || (m_doMF && rc == MF)) {
596
597 for (unsigned int ros = 1; ros < TileCalibUtils::MAX_ROS; ++ros) {
598 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
599 for (unsigned int ch = 0; ch < TileCalibUtils::MAX_CHAN; ++ch) {
600 for (unsigned int g = 0; g < TileCalibUtils::MAX_GAIN; ++g) {
601 m_histAmp[rc][ros][drawer][ch][g]->Write();
602 }
603 }
604 }
605 }
606 }
607 }
608
609 for (int side = 0; side < NSIDES; side++) {
610 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
611 for (int sample = 0; sample < NSAMPLES; ++sample) {
612 for (int tower = 0; tower < NTOWERS; ++tower) {
613 for (int gg = 0; gg < NCELLGAINS; ++gg) {
614 m_histCellAmp[side][drawer][sample][tower][gg]->Write();
615 }
616 }
617 }
618 }
619 }
620 }
621
622 fout->Close();
623
624
625 deleteHist();
626
627 return StatusCode::SUCCESS;
628}
629
632 if (not dqStatus){
633 m_time = 0;
634 m_year = 0;
635 m_month = 0;
636 m_day = 0;
637 m_yday = 0;
638 m_hour = 0;
639 m_min = 0;
640 m_trigType = 0;
641 ATH_MSG_WARNING("TileRawChNoiseCalibAlg::StoreRunInfo : dqStatus pointer is null");
642 return;
643 }
644 MsgStream log(msgSvc(), name());
645
646 if (dqStatus->calibMode() == 1 && m_beamElemContainer.length() > 0) {// Bigain can use cispar
647
648 if (m_beamCnv) {
649
650 if (m_beamCnv->validBeamFrag()) {
651 m_run = m_beamCnv->robFragment()->rod_run_no(); // take it from beam ROD header
652 } else {
653 m_run = 0;
654 }
655 } else
656 m_run = 0;
657
658 if (m_cispar) {
659 m_time = m_cispar[10]; //time in sc from 1970
660 m_trigType = m_cispar[12];
661 } else {
662 m_time = 0;
663 m_year = 0;
664 m_month = 0;
665 m_day = 0;
666 m_yday = 0;
667 m_hour = 0;
668 m_min = 0;
669 m_trigType = 0;
670 }
671 } else { // monogain can use eventinfo
672
674 if ( !eventInfo.isValid() ) {
675 ATH_MSG_ERROR( "No EventInfo object found! Can't read run number!" );
676 m_run = 0;
677 m_time = 0;
678 m_trigType = 0;
679 } else {
680 m_run = eventInfo->runNumber();
681 m_time = eventInfo->timeStamp();
682 if (!(eventInfo->eventType(xAOD::EventInfo::IS_CALIBRATION))) // if not calibration, physics
683 m_trigType = 1;
684 else
685 m_trigType = 0;
686 }
687 }
688
689 if (m_time != 0) {
690 struct tm t;
691 time_t t_time = m_time;
692 localtime_r(&t_time, &t);
693 m_year = t.tm_year + 1900;
694 m_month = t.tm_mon + 1;
695 m_day = t.tm_mday;
696 m_yday = t.tm_yday + 1;
697 m_hour = t.tm_hour;
698 m_min = t.tm_min;
699 } else {
700 m_year = 0;
701 m_month = 0;
702 m_day = 0;
703 m_yday = 0;
704 m_hour = 0;
705 m_min = 0;
706 }
707}
708
709// fillRawChannels is called at every events.
710// Statistics is summed for Average, RMS calculations
711/*---------------------------------------------------------*/
713 const SG::ReadHandleKey<TileRawChannelContainer>& rawChannelContainerKey,
714 RCtype rctype) {
715/*---------------------------------------------------------*/
716
717 SG::ReadHandle<TileRawChannelContainer> rawChannelContainer(rawChannelContainerKey);
718 ATH_CHECK( rawChannelContainer.isValid() );
719
720 if ((rctype == Dsp) && (m_trigType != Phys)) {
721 ATH_MSG_ERROR( "Removing DSP RawChannelContainer for non Phys run. TrigType is: " << m_trigType );
722 return StatusCode::FAILURE;
723 }
724
725 TileRawChannelUnit::UNIT RChUnit = rawChannelContainer->get_unit();
726
727 TileRawChannelContainer::const_iterator collItr = rawChannelContainer->begin();
728 TileRawChannelContainer::const_iterator lastColl = rawChannelContainer->end();
729
730 for (; collItr != lastColl; ++collItr) {
731
732 TileRawChannelCollection::const_iterator chItr = (*collItr)->begin();
733 TileRawChannelCollection::const_iterator lastCh = (*collItr)->end();
734
735 for (; chItr != lastCh; ++chItr) {
736
737 const TileRawChannel* rch = (*chItr);
738
739 HWIdentifier adc_id = (*chItr)->adc_HWID();
740 unsigned int ros(0), drawer(0), channel(0), gain(0);
741 m_tileIdTrans->getIndices(adc_id, ros, drawer, channel, gain);
742 unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
743
744 if (dqStatus->isChEmpty(ros, drawer, channel)) continue;
745
746 // If DQ problem, do not fill calib ntuple
747 if (m_calibMode == 1) { // Bigain: check indivual adc's
748
749 if (!(dqStatus->isAdcDQgood(ros, drawer, channel, gain))) {
750 ATH_MSG_VERBOSE( "Skipping Module: " << TileCalibUtils::getDrawerString(ros, drawer)
751 << " channel: " << channel
752 << " ADC: " << gain << " due to DQ error found." );
753
754 continue;
755 }
756 } else { // monogain, just check channel
757
758 if (!(dqStatus->isChanDQgood(ros, drawer, channel))) {
759 ATH_MSG_VERBOSE( "Skipping Module: " << TileCalibUtils::getDrawerString(ros, drawer)
760 << " channel: " << channel << " due to DQ error found." );
761
762 continue;
763 }
764 }
765
766 // we fill the cell information now for selected method
767 // note that fillCell is called only for good channels
768 if (rctype == m_UseforCells) fillCell(RChUnit, rch);
769
770 double amp = rch->amplitude();
772 // go from online units to ADC counts
773 amp = m_tileToolEmscale->undoOnlCalib(drawerIdx, channel, gain, amp, RChUnit);
774 } else if (RChUnit == TileRawChannelUnit::OnlineADCcounts) {
775 // nothing to do
776 } else if (RChUnit > TileRawChannelUnit::ADCcounts) {
777 // go from offline units to ADC counts
778 amp /= m_tileToolEmscale->channelCalib(drawerIdx, channel, gain, 1.0, TileRawChannelUnit::ADCcounts, RChUnit);
779 }
780
781 // PMT-1 or channel index depending on jobOptions
782 unsigned int chan = (m_usePMT) ? digiChannel2PMT(ros, channel) : channel;
783
784 m_evt[ros][drawer][chan][gain]++;
785 m_histAmp[rctype][ros][drawer][chan][gain]->Fill(amp);
786 }
787 }
788
789 if (rctype == m_UseforCells) fillCellHist(); //we fill the cell histograms only at the end of the loop over the channels,
790 //when all the cells have been built
791
792 return StatusCode::SUCCESS;
793}
794
797/*---------------------------------------------------------*/
799 /*---------------------------------------------------------*/
800
801 // Some of the ROOT histogram/fitting code is not protected against FPEs.
802 // Just disable the detection of FPEs for this function.
803 CxxUtils::FPControl ctl;
804 ctl.disable (CxxUtils::FPControl::Exc::divbyzero |
805 CxxUtils::FPControl::Exc::invalid);
806
807 TF1 * fit_gaus = new TF1("g", "gaus");
808
809 for (unsigned int ros = 1; ros < TileCalibUtils::MAX_ROS; ++ros) {
810 ATH_MSG_INFO( "Fitting RCh container " << rctype << " ROS " << ros );
811
812 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
813 for (unsigned int gain = 0; gain < TileCalibUtils::MAX_GAIN; ++gain) {
814 for (unsigned int chan = 0; chan < TileCalibUtils::MAX_CHAN; ++chan) {
815
816 if (!m_fillidx) {
817 m_fillidx = true;
818 m_ros[ros][drawer][chan][gain] = ros;
819 m_drawer[ros][drawer][chan][gain] = drawer;
820 m_channel[ros][drawer][chan][gain] = chan;
821 m_gain[ros][drawer][chan][gain] = gain;
822 }
823
824 if (m_evt[ros][drawer][chan][gain] > 0) {
825
826 TH1F& histAmp = *m_histAmp[rctype][ros][drawer][chan][gain];
827 histAmp.Fit("g", "NQ");
828
829 m_rc_av[rctype][ros][drawer][chan][gain] = histAmp.GetMean();
830 m_rc_rms[rctype][ros][drawer][chan][gain] = histAmp.GetRMS();
831
832 if (TMath::Abs(histAmp.GetSkewness()) < 1000.)
833 m_rc_skewness[rctype][ros][drawer][chan][gain] = histAmp.GetSkewness();
834 if (TMath::Abs(histAmp.GetKurtosis()) < 1000.)
835 m_rc_kurtosis[rctype][ros][drawer][chan][gain] = histAmp.GetKurtosis();
836
837 m_rc_mean[rctype][ros][drawer][chan][gain] = fit_gaus->GetParameter(1);
838 m_rc_mean_err[rctype][ros][drawer][chan][gain] = fit_gaus->GetParError(1);
839 m_rc_sigma[rctype][ros][drawer][chan][gain] = fit_gaus->GetParameter(2);
840 m_rc_sigma_err[rctype][ros][drawer][chan][gain] = fit_gaus->GetParError(2);
841 m_rc_chi2[rctype][ros][drawer][chan][gain] = fit_gaus->GetChisquare();
842 m_rc_ndf[rctype][ros][drawer][chan][gain] = fit_gaus->GetNDF();
843 m_rc_probC2[rctype][ros][drawer][chan][gain] = fit_gaus->GetProb();
844
845 doFit(&histAmp, m_rc_ggpar[rctype][ros][drawer][chan][gain], m_invertChanRatio);
846
847 m_rc_gsigma1[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][0];
848 m_rc_gsigma2[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][2];
849 m_rc_gnorm[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][1];
850 m_rc_gchi2[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][3];
851 m_rc_gerrsigma1[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][4];
852 m_rc_gerrnorm[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][5];
853 m_rc_gerrsigma2[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][6];
854 m_rc_gcorrsigma1sigma2[rctype][ros][drawer][chan][gain] = m_rc_ggpar[rctype][ros][drawer][chan][gain][7];
855
856 } // end if evt>0
857
858 }
859 }
860 }
861 } // end if ros
862
863 delete fit_gaus;
864
865}
866
867
868// fillCell is called at every events.
869// Statistics is summed for Average, RMS calculations
870/*---------------------------------------------------------*/
872 /*---------------------------------------------------------*/
873
874 int index, pmt;
875 Identifier cell_id = rch->cell_ID_index(index, pmt);
876 if (index > -1) { //disconnect channel index is -1/ MBTS cell index is -2 and they don't have an idhash
877 unsigned int ros(0), drawer(0), channel(0), gain(0);
878 m_tileIdTrans->getIndices(rch->adc_HWID(), ros, drawer, channel, gain);
879 unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
880
881 if (m_maskBadChannels && m_tileBadChanTool->getAdcStatus(drawerIdx, channel, gain).isBad()) {
882 ATH_MSG_VERBOSE( "Skipping Module: " << TileCalibUtils::getDrawerString(ros, drawer)
883 << " channel: " << channel
884 << " ADC: " << gain
885 << " in fillCell() because channel is bad in DB." );
886 return;
887 }
888
889 int sample = m_tileID->sample(cell_id);
890 int tower = m_tileID->tower(cell_id);
891 int side = m_tileID->side(cell_id);
892
893 if (side == 1) side = 0; //A side
894 else if (side == -1) side = 1; //C side
895 else side = 0; //D0 cell? we put it in LBA
896
897 if (m_evtNr < 1) { //first event
898 m_ecell_hash[side][drawer][sample][tower] = m_tileID->cell_hash(cell_id);
899 }
900
901 int g, gg;
902 if (gain == 0) {
903 gg = 0;
904 if (pmt == 0) g = 1; //in most cases even channels on side A AND odd channels on side C
905 else g = 2; //are the first channels of the cells
906 } else {
907 gg = 3;
908 if (pmt == 0) g = 4; //pmt tells us which is the first and second channel of the cells!!
909 else g = 5;
910 }
911
912 //not needed anymore if (channel==0 && ros==2) g++; //D0 second channel is special : move from first to second channel
913
914 double amp = rch->amplitude();
915 amp = m_tileToolEmscale->channelCalib(drawerIdx, channel, gain, amp, RChUnit, TileRawChannelUnit::MegaElectronVolts);
916 int nch = 1;
917
918 if (m_cabling->isRun2PlusCabling() && (ros > 2)) { // Ext.barrel modules
919
920 if (channel == E1_CHANNEL) { // Raw channel -> E1 cell.
921 int drawer2 = m_cabling->E1_merged_with_run2plus(ros, drawer);
922 if (drawer2 != 0) { // Raw channel splitted into two E1 cells for Run 2.
923 amp /= 2.0F;
924 m_ecell_ene[side][drawer2][sample][tower][gg / 3] += amp;
925 ++m_cell_nch[side][drawer2][sample][tower][gg / 3];
926
927 if (TMath::Abs(amp) > 1.e-5) {
928 m_histCellAmp[side][drawer2][sample][tower][g]->Fill(amp);
929 }
930 }
931
932 } else if (!TileCablingService::C10_connected(drawer)) { // modules with special C10
933 if (channel == OUTER_MBTS_CHANNEL) {
934 amp = 0.0; // ignore MBTS completely
935 nch = 0;
936 } else if (channel == SPECIAL_C10_CHANNEL) {
937 nch = 2; // count this channel twice - needed for correct bad-channel masking
938 }
939 }
940 }
941
942 m_ecell_ene[side][drawer][sample][tower][gg / 3] += amp;
943 m_cell_nch[side][drawer][sample][tower][gg / 3] += nch;
944
945 if (TMath::Abs(amp) > 1.e-5) {
946 m_histCellAmp[side][drawer][sample][tower][g]->Fill(amp);
947 }
948
949 } // is a connected channel
950}
951
952
955/*---------------------------------------------------------*/
957 /*---------------------------------------------------------*/
958
959 for (int side = 0; side < 2; ++side) {
960 ATH_MSG_INFO( "Fitting cells side " << side );
961 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
962 for (int sample = 0; sample < 4; ++sample) {
963 for (int tower = 0; tower < 17; ++tower) {
964 for (int gg = 0; gg < 6; ++gg) {
965
966 m_side[side][drawer][sample][tower][gg] = side;
967 m_phi[side][drawer][sample][tower][gg] = drawer;
968 m_sample[side][drawer][sample][tower][gg] = sample;
969 m_tower[side][drawer][sample][tower][gg] = tower;
970 m_gg[side][drawer][sample][tower][gg] = gg;
971
972 if (m_histCellAmp[side][drawer][sample][tower][gg]->GetEntries() > 0) {
973
974 m_ecell_av[side][drawer][sample][tower][gg] = m_histCellAmp[side][drawer][sample][tower][gg]->GetMean();
975 m_ecell_rms[side][drawer][sample][tower][gg] = m_histCellAmp[side][drawer][sample][tower][gg]->GetRMS();
976 doFit(m_histCellAmp[side][drawer][sample][tower][gg], m_ggpar[side][drawer][sample][tower][gg]);
977 m_gsigma1[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][0];
978 m_gsigma2[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][2];
979 m_gnorm[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][1];
980 m_gchi2[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][3];
981 m_gerrsigma1[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][4];
982 m_gerrnorm[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][5];
983 m_gerrsigma2[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][6];
984 m_gcorrsigma1sigma2[side][drawer][sample][tower][gg] = m_ggpar[side][drawer][sample][tower][gg][7];
985// gcorrsigma1norm[side][drawer][sample][tower][gg]=m_ggpar[side][drawer][sample][tower][gg][8];
986// gcorrsigma2norm[side][drawer][sample][tower][gg]=m_ggpar[side][drawer][sample][tower][gg][9];
987
988 }
989
990 }
991 }
992 }
993 }
994 }
995
996}
997
999/*---------------------------------------------------------*/
1000void TileRawChNoiseCalibAlg::doFit(TH1F* h, float* gp, bool invert) {
1001/*---------------------------------------------------------*/
1002 Double_t par[6];
1003
1004 float xmin = h->GetBinCenter(1);
1005 float xmax = h->GetBinCenter(h->GetNbinsX());
1006 TF1 total("total", "gaus(0)+gaus(3)", xmin, xmax);
1007 total.SetLineColor(2);
1008
1009 float nentries = h->GetEntries();
1010
1011 if (nentries == 0) {
1012 // Protect against empty histogram.
1013 std::fill (gp, gp+8, 0);
1014 return;
1015 }
1016
1017 float rms = h->GetRMS();
1018 float bin = h->GetBinWidth(0);
1019
1020 par[0] = 0.1 * nentries;
1021 par[1] = 0.;
1022 par[2] = 0.7 * std::max(rms, bin);
1023
1024 par[3] = 0.15 * par[0];
1025 par[4] = 0.;
1026 par[5] = 5. * par[2];
1027
1028 total.SetParameters(par);
1029
1030 float lim1 = bin / 2.;
1031 float lim2 = std::max(rms * 1.05, bin * 2.0);
1032 float lim3 = std::max(rms * 10.0, bin * 20.);
1033
1034 float limN1 = nentries;
1035 if (lim1 < 0.5) limN1 /= (2. * lim1); // a bit more than Nentries / ( sqrt(2*pi) * sigma1 )
1036 float limN2 = nentries;
1037 if (lim2 < 0.5) limN2 /= (2. * lim2); // a bit more than Nentries / ( sqrt(2*pi) * sigma2 )
1038
1039 total.SetParLimits(0, 0., limN1);
1040 total.FixParameter(1, 0.);
1041 total.SetParLimits(2, lim1, lim2);
1042 total.SetParLimits(3, 0., limN2);
1043 total.FixParameter(4, 0.);
1044 total.SetParLimits(5, lim2, lim3);
1045
1046 TFitResultPtr resfit = h->Fit(&total, "BLQRS");
1047
1048 float par0 = total.GetParameter(0);
1049 float par3 = total.GetParameter(3);
1050
1051 float sigma1 = total.GetParameter(2); //sigma gauss1
1052 float sigma2 = total.GetParameter(5); //sigma gauss1
1053
1054 //Get errors
1055 float errpar0 = total.GetParError(0);
1056 float errpar3 = total.GetParError(3);
1057
1058 float errsigma1 = total.GetParError(2);
1059 float errsigma2 = total.GetParError(5);
1060
1061 float norm = par0 != 0 ? par3 / par0 : 0; //rel normalization of the gaussians
1062
1063 if (invert && norm > 1.) { //invert the 2 gaussians if normalization is greater than 1
1064
1065 gp[0] = sigma2;
1066 gp[1] = 1. / norm;
1067 gp[2] = sigma1;
1068
1069 gp[4] = errsigma2;
1070 gp[5] = sqrt((errpar0 * errpar0) + (errpar3 * errpar3) * (par0 * par0) / (par3 * par3)) / par3;
1071 gp[6] = errsigma1;
1072
1073 } else {
1074
1075 gp[0] = sigma1;
1076 gp[1] = norm;
1077 gp[2] = sigma2;
1078
1079 gp[4] = errsigma1;
1080 gp[5] = par0 != 0 ? sqrt((errpar3 * errpar3) + (errpar0 * errpar0) * (par3 * par3) / (par0 * par0)) / par0 : 0;
1081 gp[6] = errsigma2;
1082
1083 }
1084
1085 if (total.GetNDF() > 0) {
1086 gp[3] = total.GetChisquare() / total.GetNDF(); //chi2/ndf
1087 } else {
1088 gp[3] = 0.;
1089 }
1090
1091 // Get correlation sigma1, sigma2
1092 if (resfit->CovMatrixStatus()) {
1093 TMatrixDSym corr = resfit->GetCorrelationMatrix();
1094 gp[7] = corr(2, 5);
1095 }
1096 else {
1097 // May happen if the input histogram is empty.
1098 gp[7] = 0;
1099 }
1100}
1101
1102
1105/*---------------------------------------------------------*/
1107/*---------------------------------------------------------*/
1108
1109 for (int side = 0; side < 2; ++side) {
1110 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
1111 for (int sample = 0; sample < 4; ++sample) {
1112 for (int tower = 0; tower < 17; ++tower) {
1113 for (unsigned int gg = 0; gg < TileCalibUtils::MAX_GAIN; ++gg) {
1114
1115 float ene = m_ecell_ene[side][drawer][sample][tower][gg];
1116 if (m_cell_nch[side][drawer][sample][tower][gg] == 1 && sample != 3) ene *= 2; // one good channel in normal cell - multiply energy by 2
1117
1118 if (TMath::Abs(ene) > 1.e-5) {
1119 m_histCellAmp[side][drawer][sample][tower][gg * 3]->Fill(ene);
1120 }
1121
1122 }
1123 }
1124 }
1125 }
1126 }
1127
1128}
1129
1130
1131
1135/*---------------------------------------------------------*/
1137/*---------------------------------------------------------*/
1138
1139 for (int rc = 0; rc < RCnum; ++rc) {
1140 for (unsigned int ros = 1; ros < TileCalibUtils::MAX_ROS; ++ros) {
1141 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
1142
1143 for (unsigned int ch = 0; ch < TileCalibUtils::MAX_CHAN; ++ch) {
1144 for (unsigned int g = 0; g < TileCalibUtils::MAX_GAIN; ++g) {
1145 delete m_histAmp[rc][ros][drawer][ch][g];
1146 }
1147 }
1148 }
1149 }
1150 }
1151
1152 for (int side = 0; side < 2; side++) {
1153 for (unsigned int drawer = 0; drawer < TileCalibUtils::MAX_DRAWER; ++drawer) {
1154 for (int sample = 0; sample < 4; ++sample) {
1155 for (int tower = 0; tower < 17; ++tower) {
1156 for (int gg = 0; gg < 6; gg++) {
1157 delete m_histCellAmp[side][drawer][sample][tower][gg];
1158 }
1159 }
1160 }
1161 }
1162 }
1163
1164}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Helper to control FP exceptions.
static Double_t rc
Handle class for reading from StoreGate.
TGraphErrors * GetEntries(TH2F *histo)
static const Attributes_t empty
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Header file for AthHistogramAlgorithm.
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
This AthConstConverter class provides conversion from ByteStream to TileBeamElemContainer.
static bool C10_connected(int module)
static const TileCablingService * getInstance()
get pointer to service instance
static const unsigned int MAX_ROS
Number of ROSs.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static const unsigned int MAX_GAIN
Number of gains per channel.
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
static const unsigned int MAX_CHAN
Number of channels in drawer.
Class that holds Data Quality fragment information and provides functions to extract the data quality...
bool isAdcDQgood(int partition, int drawer, int ch, int gain) const
returns status of single ADC returns False if there are any errors
bool isChanDQgood(int partition, int drawer, int ch) const
returns status of single channel (if bigain, returns AND of ADCs' status
uint32_t calibMode() const
Calibration mode.
static int isChEmpty(int partition, int drawer, int ch)
True if channel is not fully implemented.
const uint32_t * cispar() const
CIS parameters.
float(* m_rc_mean_err)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_rc_av)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
uint8_t(* m_ros)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
uint32_t(* m_ecell_hash)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS]
float(* m_rc_probC2)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerMFKey
bool(* m_side)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
float(* m_rc_kurtosis)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_rc_sigma_err)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_rc_gsigma2)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_rc_mean)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
uint8_t(* m_drawer)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_gerrsigma1)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
void finalRawCh(int rctype)
finalDigits is called during finalize Here the average Ped, lfn, hfn and covariance are calculated.
uint8_t(* m_gg)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
TileBeamElemContByteStreamCnv * m_beamCnv
float(* m_rc_gerrsigma1)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
static constexpr int NSIDES
uint8_t(* m_sample)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
static void doFit(TH1F *h, float *gp, bool invert=true)
doFit performs the double gaussian fit of the amplitude
SG::ReadHandleKey< TileDQstatus > m_dqStatusKey
uint8_t(* m_tower)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
void fillCellHist()
fillCellHist is called during execute It fill the HGHG and LGLG combination of the cell energies
uint8_t(* m_phi)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
virtual StatusCode execute() override
Main method.
float(* m_gerrnorm)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
bool(* m_gain)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
StatusCode fillRawChannels(const TileDQstatus *dqStatus, const SG::ReadHandleKey< TileRawChannelContainer > &rawChannelContainerKey, RCtype rctype)
float(* m_rc_chi2)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_ecell_ene)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][Tile::MAX_GAIN]
float(* m_rc_rms)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_rc_gerrnorm)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_rc_gchi2)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerFixedKey
float(* m_rc_sigma)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_rc_gsigma1)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerDspKey
TH1F *(* m_histAmp)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
ToolHandle< ITileBadChanTool > m_tileBadChanTool
float(* m_rc_ndf)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
ToolHandle< TileCondToolEmscale > m_tileToolEmscale
float(* m_rc_skewness)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_gcorrsigma1sigma2)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
float(* m_ecell_av)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
float(* m_gsigma1)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
float(* m_gnorm)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
const TileCablingService * m_cabling
void fillCell(TileRawChannelUnit::UNIT RChUnit, const TileRawChannel *rch)
float(* m_ggpar)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS][NPARS]
float(* m_rc_gnorm)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerOptKey
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerOF1Key
StatusCode FirstEvt_initialize()
Initialization done at the first event.
void StoreRunInfo(const TileDQstatus *dqStatus)
StoreRunInfo is called only during the first event.
float(* m_gsigma2)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
static constexpr int NTOWERS
TH1F *(* m_histCellAmp)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
float(* m_rc_gcorrsigma1sigma2)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
void finalCell()
finalCell is called during finalize Here the cell variables of the ntuple are filled.
static constexpr int NSAMPLES
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerFitKey
static constexpr int NCELLGAINS
float(* m_gchi2)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
uint8_t(* m_channel)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
int(* m_evt)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
void deleteHist()
deleteHist is called at finalize to ensure that no histogram goes into any output root file delete []...
int digiChannel2PMT(int ros, int chan)
virtual StatusCode initialize() override
Only array initialization is done here All the helpers initialization is done at the first event.
int(* m_cell_nch)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][Tile::MAX_GAIN]
virtual StatusCode finalize() override
The output ntuple is created in finalize method.
float(* m_gerrsigma2)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
float(* m_rc_ggpar)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN][NPARS]
ToolHandle< TileCondIdTransforms > m_tileIdTrans
float(* m_rc_gerrsigma2)[Tile::MAX_ROS][Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
TileRawChNoiseCalibAlg(const std::string &name, ISvcLocator *pSvcLocator)
float(* m_ecell_rms)[Tile::MAX_DRAWER][NSAMPLES][NTOWERS][NCELLGAINS]
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
float amplitude(int ind=0) const
Identifier cell_ID_index(int &index, int &pmt) const
HWIdentifier adc_HWID(void) const
Definition TileRawData.h:53
@ IS_CALIBRATION
true: calibration, false: physics
bool doFit
double xmax
Definition listroot.cxx:61
static TFile * fout
Definition listroot.cxx:40
double xmin
Definition listroot.cxx:60
bool binwidth
Definition listroot.cxx:58
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition index.py:1