1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 //________________________________________________________________________
19 // A help class for monitoring and calibration tools: MOOD, AMORE etc.,
20 // It can be created and used a la (ctor):
22 //Create the object for making the histograms
23 fPedestals = new AliCaloCalibPedestal( fDetType );
24 // AliCaloCalibPedestal knows how many modules we have for PHOS or EMCAL
25 fNumModules = fPedestals->GetModules();
28 // fPedestals->ProcessEvent(fCaloRawStream);
29 // asked to draw histograms:
30 // fPedestals->GetDeadMap(i)->Draw("col");
32 // fPedestals->GetPeakProfileHighGainRatio((i < fNumModules) ? i : fVisibleModule)->Draw("colz");
34 // The pseudo-code examples above were from the first implementation in MOOD (summer 2007).
35 //________________________________________________________________________
37 //#include "TCanvas.h"
47 #include "AliRawReader.h"
48 #include "AliCaloRawStreamV3.h"
51 #include "AliCaloCalibPedestal.h"
53 ClassImp(AliCaloCalibPedestal)
57 // ctor; initialize everything in order to avoid compiler warnings
58 AliCaloCalibPedestal::AliCaloCalibPedestal(kDetType detectorType) :
62 fPedestalLEDRefLowGain(),
63 fPedestalLEDRefHighGain(),
64 fPeakMinusPedLowGain(),
65 fPeakMinusPedHighGain(),
66 fPeakMinusPedHighGainHisto(),
67 fPedestalLowGainDiff(),
68 fPedestalHighGainDiff(),
69 fPedestalLEDRefLowGainDiff(),
70 fPedestalLEDRefHighGainDiff(),
71 fPeakMinusPedLowGainDiff(),
72 fPeakMinusPedHighGainDiff(),
73 fPedestalLowGainRatio(),
74 fPedestalHighGainRatio(),
75 fPedestalLEDRefLowGainRatio(),
76 fPedestalLEDRefHighGainRatio(),
77 fPeakMinusPedLowGainRatio(),
78 fPeakMinusPedHighGainRatio(),
84 fResurrectedTowers(0),
97 fSelectPedestalSamples(kTRUE),
98 fFirstPedestalSample(0),
99 fLastPedestalSample(15),
101 fWarningThreshold(50),
102 fWarningFraction(0.002),
105 //Default constructor. First we set the detector-type related constants.
106 if (detectorType == kPhos) {
107 fColumns = fgkPhosCols;
109 fLEDRefs = fgkPhosLEDRefs;
110 fModules = fgkPhosModules;
111 fCaloString = "PHOS";
117 //We'll just trust the enum to keep everything in line, so that if detectorType
118 //isn't kPhos then it is kEmCal. Note, however, that this is not necessarily the
119 //case, if someone intentionally gives another number
120 fColumns = AliEMCALGeoParams::fgkEMCALCols;
121 fRows = AliEMCALGeoParams::fgkEMCALRows;
122 fLEDRefs = AliEMCALGeoParams::fgkEMCALLEDRefs;
123 fModules = AliEMCALGeoParams::fgkEMCALModules;
124 fCaloString = "EMCAL";
129 fDetType = detectorType;
131 // ValidateProfiles(); // not to be done in ctor; info from Axel N.
134 //_____________________________________________________________________
135 void AliCaloCalibPedestal::ValidateProfiles()
137 //Make sure the basic histos exist
138 if (!fPedestalLowGain.IsEmpty()) return; //The profiles already exist. We just check one, because they're all created at
141 //Then, loop for the requested number of modules
143 for (int i = 0; i < fModules; i++) {
144 //Pedestals, low gain
145 name = "hPedlowgain";
147 title = "Pedestals, low gain, module ";
149 fPedestalLowGain.Add(new TProfile2D(name, title,
150 fColumns, 0.0, fColumns,
151 fRows, fRowMin, fRowMax,"s"));
153 //Pedestals, high gain
154 name = "hPedhighgain";
156 title = "Pedestals, high gain, module ";
158 fPedestalHighGain.Add(new TProfile2D(name, title,
159 fColumns, 0.0, fColumns,
160 fRows, fRowMin, fRowMax,"s"));
162 //LED Ref/Mon pedestals, low gain
163 name = "hPedestalLEDReflowgain";
165 title = "Pedestal LEDRef, low gain, module ";
167 fPedestalLEDRefLowGain.Add(new TProfile(name, title,
168 fLEDRefs, 0.0, fLEDRefs, "s"));
170 //LED Ref/Mon pedestals, high gain
171 name = "hPedestalLEDRefhighgain";
173 title = "Pedestal LEDRef, high gain, module ";
175 fPedestalLEDRefHighGain.Add(new TProfile(name, title,
176 fLEDRefs, 0.0, fLEDRefs, "s"));
178 //Peak-Pedestals, low gain
179 name = "hPeakMinusPedlowgain";
181 title = "Peak-Pedestal, low gain, module ";
183 fPeakMinusPedLowGain.Add(new TProfile2D(name, title,
184 fColumns, 0.0, fColumns,
185 fRows, fRowMin, fRowMax,"s"));
187 //Peak-Pedestals, high gain
188 name = "hPeakMinusPedhighgain";
190 title = "Peak-Pedestal, high gain, module ";
192 fPeakMinusPedHighGain.Add(new TProfile2D(name, title,
193 fColumns, 0.0, fColumns,
194 fRows, fRowMin, fRowMax,"s"));
196 //Peak-Pedestals, high gain - TH2F histo
197 name = "hPeakMinusPedhighgainHisto";
199 title = "Peak-Pedestal, high gain, module ";
201 fPeakMinusPedHighGainHisto.Add(new TH2F(name, title,
202 fColumns*fRows, 0.0, fColumns*fRows,
207 title = "Dead map, module ";
209 fDeadMap.Add(new TH2D(name, title, fColumns, 0.0, fColumns,
210 fRows, fRowMin, fRowMax));
212 }//end for nModules create the histograms
214 CompressAndSetOwner();
217 //_____________________________________________________________________
218 void AliCaloCalibPedestal::CompressAndSetOwner()
220 //Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
221 fPedestalLowGain.Compress();
222 fPedestalHighGain.Compress();
223 fPedestalLEDRefLowGain.Compress();
224 fPedestalLEDRefHighGain.Compress();
225 fPeakMinusPedLowGain.Compress();
226 fPeakMinusPedHighGain.Compress();
227 fPeakMinusPedHighGainHisto.Compress();
230 // set owner ship for everyone
231 fPedestalLowGain.SetOwner(kTRUE);
232 fPedestalHighGain.SetOwner(kTRUE);
233 fPedestalLEDRefLowGain.SetOwner(kTRUE);
234 fPedestalLEDRefHighGain.SetOwner(kTRUE);
235 fPeakMinusPedLowGain.SetOwner(kTRUE);
236 fPeakMinusPedHighGain.SetOwner(kTRUE);
237 fPeakMinusPedHighGainHisto.SetOwner(kTRUE);
238 fPedestalLowGainDiff.SetOwner(kTRUE);
239 fPedestalHighGainDiff.SetOwner(kTRUE);
240 fPedestalLEDRefLowGainDiff.SetOwner(kTRUE);
241 fPedestalLEDRefHighGainDiff.SetOwner(kTRUE);
242 fPeakMinusPedLowGainDiff.SetOwner(kTRUE);
243 fPeakMinusPedHighGainDiff.SetOwner(kTRUE);
244 fPedestalLowGainRatio.SetOwner(kTRUE);
245 fPedestalHighGainRatio.SetOwner(kTRUE);
246 fPedestalLEDRefLowGainRatio.SetOwner(kTRUE);
247 fPedestalLEDRefHighGainRatio.SetOwner(kTRUE);
248 fPeakMinusPedLowGainRatio.SetOwner(kTRUE);
249 fPeakMinusPedHighGainRatio.SetOwner(kTRUE);
250 fDeadMap.SetOwner(kTRUE);
254 //_____________________________________________________________________
255 AliCaloCalibPedestal::~AliCaloCalibPedestal()
257 if (fReference) delete fReference;//Delete the reference object, if it has been loaded
259 // delete also TObjArray's
260 fPedestalLowGain.Delete();
261 fPedestalHighGain.Delete();
262 fPedestalLEDRefLowGain.Delete();
263 fPedestalLEDRefHighGain.Delete();
264 fPeakMinusPedLowGain.Delete();
265 fPeakMinusPedHighGain.Delete();
266 fPeakMinusPedHighGainHisto.Delete();
267 fPedestalLowGainDiff.Delete();
268 fPedestalHighGainDiff.Delete();
269 fPedestalLEDRefLowGainDiff.Delete();
270 fPedestalLEDRefHighGainDiff.Delete();
271 fPeakMinusPedLowGainDiff.Delete();
272 fPeakMinusPedHighGainDiff.Delete();
273 fPedestalLowGainRatio.Delete();
274 fPedestalHighGainRatio.Delete();
275 fPedestalLEDRefLowGainRatio.Delete();
276 fPedestalLEDRefHighGainRatio.Delete();
277 fPeakMinusPedLowGainRatio.Delete();
278 fPeakMinusPedHighGainRatio.Delete();
284 //_____________________________________________________________________
285 AliCaloCalibPedestal::AliCaloCalibPedestal(AliCaloCalibPedestal &ped) :
289 fPedestalLEDRefLowGain(),
290 fPedestalLEDRefHighGain(),
291 fPeakMinusPedLowGain(),
292 fPeakMinusPedHighGain(),
293 fPeakMinusPedHighGainHisto(),
294 fPedestalLowGainDiff(),
295 fPedestalHighGainDiff(),
296 fPedestalLEDRefLowGainDiff(),
297 fPedestalLEDRefHighGainDiff(),
298 fPeakMinusPedLowGainDiff(),
299 fPeakMinusPedHighGainDiff(),
300 fPedestalLowGainRatio(),
301 fPedestalHighGainRatio(),
302 fPedestalLEDRefLowGainRatio(),
303 fPedestalLEDRefHighGainRatio(),
304 fPeakMinusPedLowGainRatio(),
305 fPeakMinusPedHighGainRatio(),
307 fNEvents(ped.GetNEvents()),
308 fNChanFills(ped.GetNChanFills()),
309 fDeadTowers(ped.GetDeadTowerCount()),
310 fNewDeadTowers(ped.GetDeadTowerNew()),
311 fResurrectedTowers(ped.GetDeadTowerResurrected()),
312 fReference( 0 ), //! note that we do not try to copy the reference info here
313 fDetType(ped.GetDetectorType()),
314 fColumns(ped.GetColumns()),
315 fRows(ped.GetRows()),
316 fLEDRefs(ped.GetLEDRefs()),
317 fModules(ped.GetModules()),
318 fRowMin(ped.GetRowMin()),
319 fRowMax(ped.GetRowMax()),
320 fRowMultiplier(ped.GetRowMultiplier()),
321 fCaloString(ped.GetCaloString()),
322 fMapping(NULL), //! note that we are not copying the map info
323 fRunNumber(ped.GetRunNumber()),
324 fSelectPedestalSamples(ped.GetSelectPedestalSamples()),
325 fFirstPedestalSample(ped.GetFirstPedestalSample()),
326 fLastPedestalSample(ped.GetLastPedestalSample()),
327 fDeadThreshold(ped.GetDeadThreshold()),
328 fWarningThreshold(ped.GetWarningThreshold()),
329 fWarningFraction(ped.GetWarningFraction()),
330 fHotSigma(ped.GetHotSigma())
332 // Then the ObjArray ones; we add the histograms rather than trying TObjArray = assignment
333 //DS: this has not really been tested yet..
334 for (int i = 0; i < fModules; i++) {
335 fPedestalLowGain.Add( ped.GetPedProfileLowGain(i) );
336 fPedestalHighGain.Add( ped.GetPedProfileHighGain(i) );
337 fPedestalLEDRefLowGain.Add( ped.GetPedLEDRefProfileLowGain(i) );
338 fPedestalLEDRefHighGain.Add( ped.GetPedLEDRefProfileHighGain(i) );
339 fPeakMinusPedLowGain.Add( ped.GetPeakProfileLowGain(i) );
340 fPeakMinusPedHighGain.Add( ped.GetPeakProfileHighGain(i) );
341 fPeakMinusPedHighGainHisto.Add( ped.GetPeakHighGainHisto(i) );
343 fDeadMap.Add( ped.GetDeadMap(i) );
346 CompressAndSetOwner();
349 // assignment operator; use copy ctor to make life easy..
350 //_____________________________________________________________________
351 AliCaloCalibPedestal& AliCaloCalibPedestal::operator = (AliCaloCalibPedestal &source)
353 // assignment operator; use copy ctor
354 if (&source == this) return *this;
356 new (this) AliCaloCalibPedestal(source);
360 //_____________________________________________________________________
361 void AliCaloCalibPedestal::Reset()
363 ValidateProfiles(); // make sure histos/profiles exist
364 // Reset all arrays/histograms
365 for (int i = 0; i < fModules; i++) {
366 GetPedProfileLowGain(i)->Reset();
367 GetPedProfileHighGain(i)->Reset();
368 GetPedLEDRefProfileLowGain(i)->Reset();
369 GetPedLEDRefProfileHighGain(i)->Reset();
370 GetPeakProfileLowGain(i)->Reset();
371 GetPeakProfileHighGain(i)->Reset();
372 GetPeakHighGainHisto(i)->Reset();
373 GetDeadMap(i)->Reset();
375 if (!fPedestalLowGainDiff.IsEmpty()) {
376 //This means that the comparison profiles have been created.
378 GetPedProfileLowGainDiff(i)->Reset();
379 GetPedProfileHighGainDiff(i)->Reset();
380 GetPedLEDRefProfileLowGainDiff(i)->Reset();
381 GetPedLEDRefProfileHighGainDiff(i)->Reset();
382 GetPeakProfileLowGainDiff(i)->Reset();
383 GetPeakProfileHighGainDiff(i)->Reset();
385 GetPedProfileLowGainRatio(i)->Reset();
386 GetPedProfileHighGainRatio(i)->Reset();
387 GetPedLEDRefProfileLowGainRatio(i)->Reset();
388 GetPedLEDRefProfileHighGainRatio(i)->Reset();
389 GetPeakProfileLowGainRatio(i)->Reset();
390 GetPeakProfileHighGainRatio(i)->Reset();
397 fResurrectedTowers = 0;
399 //To think about: should fReference be deleted too?... let's not do it this time, at least...
402 // Parameter/cut handling
403 //_____________________________________________________________________
404 void AliCaloCalibPedestal::SetParametersFromFile(const char *parameterFile)
406 // Note: this method is a bit more complicated than it really has to be
407 // - allowing for multiple entries per line, arbitrary order of the
408 // different variables etc. But I wanted to try and do this in as
409 // correct a C++ way as I could (as an exercise).
411 static const string delimitor("::");
413 // open, check input file
414 ifstream in( parameterFile );
416 printf("in AliCaloCalibPedestal::SetParametersFromFile - Using default/run_time parameters.\n");
423 while ((in.rdstate() & ios::failbit) == 0 ) {
425 // Read into the raw char array and then construct a string
426 // to do the searching
427 in.getline(readline, 1024);
428 istringstream s(readline);
430 while ( ( s.rdstate() & ios::failbit ) == 0 ) {
435 // check stream status
436 if( ( s.rdstate() & ios::failbit ) == ios::failbit) break;
438 // skip rest of line if comments found
439 if( keyValue.substr( 0, 2 ) == "//" ) break;
441 // look for "::" in keyValue pair
442 size_t position = keyValue.find( delimitor );
443 if( position == string::npos ) {
444 printf("wrong format for key::value pair: %s\n", keyValue.c_str());
447 // split keyValue pair
448 string key( keyValue.substr( 0, position ) );
449 string value( keyValue.substr( position+delimitor.size(),
450 keyValue.size()-delimitor.size() ) );
452 // check value does not contain a new delimitor
453 if( value.find( delimitor ) != string::npos ) {
454 printf("wrong format for key::value pair: %s\n", keyValue.c_str());
457 // debug: check key value pair
458 // printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
460 // if the key matches with something we expect, we assign the new value
461 istringstream iss(value);
462 // the comparison strings defined at the beginning of this method
463 if ( (key == "fFirstPedestalSample") || (key == "fLastPedestalSample") || (key == "fDeadThreshold") || (key == "fWarningThreshold") || (key == "fWarningFraction") || (key == "fHotSigma") ) {
464 printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
466 if (key == "fFirstPedestalSample") {
467 iss >> fFirstPedestalSample;
469 else if (key == "fLastPedestalSample") {
470 iss >> fLastPedestalSample;
472 else if (key == "fDeadThreshold") {
473 iss >> fDeadThreshold;
475 else if (key == "fWarningThreshold") {
476 iss >> fWarningThreshold;
478 else if (key == "fWarningFraction") {
479 iss >> fWarningFraction;
481 else if (key == "fHotSigma") {
495 //_____________________________________________________________________
496 void AliCaloCalibPedestal::WriteParametersToFile(const char *parameterFile)
498 //Write parameters in file.
500 static const string delimitor("::");
501 ofstream out( parameterFile );
502 out << "// " << parameterFile << endl;
503 out << "fFirstPedestalSample" << "::" << fFirstPedestalSample << endl;
504 out << "fLastPedestalSample" << "::" << fLastPedestalSample << endl;
505 out << "fDeadThreshold" << "::" << fDeadThreshold << endl;
506 out << "fWarningThreshold" << "::" << fWarningThreshold << endl;
507 out << "fWarningFraction" << "::" << fWarningFraction << endl;
508 out << "fHotSigma" << "::" << fHotSigma << endl;
514 //_____________________________________________________________________
515 Bool_t AliCaloCalibPedestal::AddInfo(AliCaloCalibPedestal *ped)
517 ValidateProfiles(); // make sure histos/profiles exist
518 // just do this for the basic histograms/profiles that get filled in ProcessEvent
519 // may not have data for all modules, but let's just Add everything..
520 for (int i = 0; i < fModules; i++) {
521 GetPedProfileLowGain(i)->Add( ped->GetPedProfileLowGain(i) );
522 GetPedProfileHighGain(i)->Add( ped->GetPedProfileHighGain(i) );
523 GetPeakProfileLowGain(i)->Add( ped->GetPeakProfileLowGain(i) );
524 GetPeakProfileHighGain(i)->Add( ped->GetPeakProfileHighGain(i) );
525 GetPeakHighGainHisto(i)->Add( ped->GetPeakHighGainHisto(i) );
529 // DeadMap; Diff profiles etc would need to be redone after this operation
531 return kTRUE;//We succesfully added info from the supplied object
534 //_____________________________________________________________________
535 Bool_t AliCaloCalibPedestal::ProcessEvent(AliRawReader *rawReader)
537 // if fMapping is NULL the rawstream will crate its own mapping
538 AliCaloRawStreamV3 rawStream(rawReader, fCaloString, (AliAltroMapping**)fMapping);
539 if (fDetType == kEmCal) {
540 rawReader->Select("EMCAL", 0, AliEMCALGeoParams::fgkLastAltroDDL) ; //select EMCAL DDL range
542 return ProcessEvent(&rawStream);
545 //_____________________________________________________________________
546 Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
548 // Method to process=analyze one event in the data stream
549 if (!in) return kFALSE; //Return right away if there's a null pointer
550 fNEvents++; // one more event
552 if (fNEvents==1) ValidateProfiles(); // 1st event, make sure histos/profiles exist
554 // indices for the reading
557 int i = 0; // sample counter
560 // start loop over input stream
561 while (in->NextDDL()) {
562 while (in->NextChannel()) {
565 int max = AliEMCALGeoParams::fgkSampleMin, min = AliEMCALGeoParams::fgkSampleMax; // min and max sample values
570 vector<int> pedSamples;
572 while (in->NextBunch()) {
573 const UShort_t *sig = in->GetSignals();
574 startBin = in->GetStartTimeBin();
575 nsamples += in->GetBunchLength();
576 for (i = 0; i < in->GetBunchLength(); i++) {
580 // check if it's a min or max value
581 if (sample < min) min = sample;
582 if (sample > max) max = sample;
584 // should we add it for the pedestal calculation?
585 if ( (fFirstPedestalSample<=time && time<=fLastPedestalSample) || // sample time in range
586 !fSelectPedestalSamples ) { // or we don't restrict the sample range.. - then we'll take all
587 pedSamples.push_back( sig[i] );
591 } // loop over samples in bunch
592 } // loop over bunches
594 if (nsamples > 0) { // this check is needed for when we have zero-supp. on, but not sparse readout
596 // it should be enough to check the SuperModule info for each DDL really, but let's keep it here for now
597 int arrayPos = in->GetModule(); //The modules are numbered starting from 0
598 if (arrayPos >= fModules) {
599 //TODO: return an error message, if appopriate (perhaps if debug>0?)
603 if (arrayPos < 0 || arrayPos >= fModules) {
604 printf("Oh no: arrayPos = %i.\n", arrayPos);
607 fNChanFills++; // one more channel found, and profile to be filled
608 //NOTE: coordinates are (column, row) for the profiles
609 if ( in->IsLowGain() ) {
610 //fill the low gain histograms
611 ((TProfile2D*)fPeakMinusPedLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
612 if (nPed>0) { // only fill pedestal info in case it could be calculated
613 for ( i=0; i<nPed; i++) {
614 ((TProfile2D*)fPedestalLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), pedSamples[i]);
618 else if ( in->IsHighGain() ) {
619 //fill the high gain ones
620 ((TProfile2D*)fPeakMinusPedHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
621 if (nPed>0) { // only fill pedestal info in case it could be calculated
622 for ( i=0; i<nPed; i++) {
623 ((TProfile2D*)fPedestalHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), pedSamples[i]);
626 // for warning checks
627 int idx = in->GetRow() + fRows * in->GetColumn();
628 ((TH2F*)fPeakMinusPedHighGainHisto[arrayPos])->Fill(idx, max - min);
630 else if ( in->IsLEDMonData() ) {
631 // for LED Mon data, the mapping class holds the gain info in the Row variable
632 // and the Strip number in the Column..
633 int gain = in->GetRow();
634 int stripId = in->GetColumn();
635 if (nPed>0 && stripId<fLEDRefs) {
637 for ( i=0; i<nPed; i++) {
638 ((TProfile*)fPedestalLEDRefLowGain[arrayPos])->Fill(stripId, pedSamples[i]);
642 for ( i=0; i<nPed; i++) {
643 ((TProfile*)fPedestalLEDRefHighGain[arrayPos])->Fill(stripId, pedSamples[i]);
649 } // nsamples>0 check, some data found for this channel; not only trailer/header
650 }// end while over channel
651 }//end while over DDL's, of input stream
653 in->Reset(); // just in case the next customer forgets to check if the stream was reset..
658 //_____________________________________________________________________
659 Bool_t AliCaloCalibPedestal::SaveHistograms(TString fileName, Bool_t saveEmptyHistos)
661 //Saves all the histograms (or profiles, to be accurate) to the designated file
662 ValidateProfiles(); // make sure histos/profiles exist
663 TFile destFile(fileName, "recreate");
665 if (destFile.IsZombie()) {
671 for (int i = 0; i < fModules; i++) {
672 if( ((TProfile2D *)fPeakMinusPedLowGain[i])->GetEntries() || saveEmptyHistos) {
673 fPeakMinusPedLowGain[i]->Write();
675 if( ((TProfile2D *)fPeakMinusPedHighGain[i])->GetEntries() || saveEmptyHistos) {
676 fPeakMinusPedHighGain[i]->Write();
678 if( ((TProfile2D *)fPedestalLowGain[i])->GetEntries() || saveEmptyHistos) {
679 fPedestalLowGain[i]->Write();
681 if( ((TProfile2D *)fPedestalHighGain[i])->GetEntries() || saveEmptyHistos) {
682 fPedestalHighGain[i]->Write();
684 if( ((TProfile *)fPedestalLEDRefLowGain[i])->GetEntries() || saveEmptyHistos) {
685 fPedestalLEDRefLowGain[i]->Write();
687 if( ((TProfile *)fPedestalLEDRefHighGain[i])->GetEntries() || saveEmptyHistos) {
688 fPedestalLEDRefHighGain[i]->Write();
690 if( ((TH2F *)fPeakMinusPedHighGainHisto[i])->GetEntries() || saveEmptyHistos) {
691 fPeakMinusPedHighGainHisto[i]->Write();
701 //_____________________________________________________________________
702 Bool_t AliCaloCalibPedestal::LoadReferenceCalib(TString fileName, TString objectName)
705 //Make sure that the histograms created when loading the object are not destroyed as the file object is destroyed
706 TH1::AddDirectory(kFALSE);
708 TFile *sourceFile = new TFile(fileName);
709 if (sourceFile->IsZombie()) {
710 return kFALSE;//We couldn't load the reference
713 if (fReference) delete fReference;//Delete the reference object, if it already exists
716 fReference = (AliCaloCalibPedestal*)sourceFile->Get(objectName);
718 if (!fReference || !(fReference->InheritsFrom(AliCaloCalibPedestal::Class())) || (fReference->GetDetectorType() != fDetType)) {
719 if (fReference) delete fReference;//Delete the object, in case we had an object of the wrong type
726 //Reset the histogram ownership behaviour. NOTE: a better workaround would be good, since this may accidentally set AddDirectory to true, even
727 //if we are called by someone who has set it to false...
728 TH1::AddDirectory(kTRUE);
730 return kTRUE;//We succesfully loaded the object
734 //_____________________________________________________________________
735 Bool_t AliCaloCalibPedestal::SetReference(AliCaloCalibPedestal *ref)
737 if (fReference) delete fReference;//Delete the reference object, if it already exists
742 if (!fReference || (fReference->GetDetectorType() != fDetType)) {
743 if (fReference) delete fReference;//Delete the object, in case we had an object of the wrong type
748 return kTRUE;//We succesfully loaded the object
751 //_____________________________________________________________________
752 void AliCaloCalibPedestal::ValidateComparisonProfiles()
754 //Make sure the comparison histos exist
755 if (!fPedestalLowGainDiff.IsEmpty()) return; //The profiles already exist. We just check one, because they're all created at
759 //Then, loop for the requested number of modules
761 for (int i = 0; i < fModules; i++) {
762 //Pedestals, low gain
763 name = "hPedlowgainDiff";
765 title = "Pedestals difference, low gain, module ";
767 fPedestalLowGainDiff.Add(new TProfile2D(name, title,
768 fColumns, 0.0, fColumns,
769 fRows, fRowMin, fRowMax,"s"));
771 //Pedestals, high gain
772 name = "hPedhighgainDiff";
774 title = "Pedestals difference, high gain, module ";
776 fPedestalHighGainDiff.Add(new TProfile2D(name, title,
777 fColumns, 0.0, fColumns,
778 fRows, fRowMin, fRowMax,"s"));
780 //LED Ref/Mon pedestals, low gain
781 name = "hPedestalLEDReflowgainDiff";
783 title = "Pedestal difference LEDRef, low gain, module ";
785 fPedestalLEDRefLowGainDiff.Add(new TProfile(name, title,
786 fLEDRefs, 0.0, fLEDRefs, "s"));
788 //LED Ref/Mon pedestals, high gain
789 name = "hPedestalLEDRefhighgainDiff";
791 title = "Pedestal difference LEDRef, high gain, module ";
793 fPedestalLEDRefHighGainDiff.Add(new TProfile(name, title,
794 fLEDRefs, 0.0, fLEDRefs, "s"));
796 //Peak-Pedestals, high gain
797 name = "hPeakMinusPedhighgainDiff";
799 title = "Peak-Pedestal difference, high gain, module ";
801 fPeakMinusPedHighGainDiff.Add(new TProfile2D(name, title,
802 fColumns, 0.0, fColumns,
803 fRows, fRowMin, fRowMax,"s"));
805 //Peak-Pedestals, low gain
806 name = "hPeakMinusPedlowgainDiff";
808 title = "Peak-Pedestal difference, low gain, module ";
810 fPeakMinusPedLowGainDiff.Add(new TProfile2D(name, title,
811 fColumns, 0.0, fColumns,
812 fRows, fRowMin, fRowMax,"s"));
814 //Pedestals, low gain
815 name = "hPedlowgainRatio";
817 title = "Pedestals ratio, low gain, module ";
819 fPedestalLowGainRatio.Add(new TProfile2D(name, title,
820 fColumns, 0.0, fColumns,
821 fRows, fRowMin, fRowMax,"s"));
823 //Pedestals, high gain
824 name = "hPedhighgainRatio";
826 title = "Pedestals ratio, high gain, module ";
828 fPedestalHighGainRatio.Add(new TProfile2D(name, title,
829 fColumns, 0.0, fColumns,
830 fRows, fRowMin, fRowMax,"s"));
832 //LED Ref/Mon pedestals, low gain
833 name = "hPedestalLEDReflowgainRatio";
835 title = "Pedestal ratio LEDRef, low gain, module ";
837 fPedestalLEDRefLowGainRatio.Add(new TProfile(name, title,
838 fLEDRefs, 0.0, fLEDRefs, "s"));
840 //LED Ref/Mon pedestals, high gain
841 name = "hPedestalLEDRefhighgainRatio";
843 title = "Pedestal ratio LEDRef, high gain, module ";
845 fPedestalLEDRefHighGainRatio.Add(new TProfile(name, title,
846 fLEDRefs, 0.0, fLEDRefs, "s"));
848 //Peak-Pedestals, low gain
849 name = "hPeakMinusPedlowgainRatio";
851 title = "Peak-Pedestal ratio, low gain, module ";
853 fPeakMinusPedLowGainRatio.Add(new TProfile2D(name, title,
854 fColumns, 0.0, fColumns,
855 fRows, fRowMin, fRowMax,"s"));
857 //Peak-Pedestals, high gain
858 name = "hPeakMinusPedhighgainRatio";
860 title = "Peak-Pedestal ratio, high gain, module ";
862 fPeakMinusPedHighGainRatio.Add(new TProfile2D(name, title,
863 fColumns, 0.0, fColumns,
864 fRows, fRowMin, fRowMax,"s"));
866 }//end for nModules create the histograms
869 //_____________________________________________________________________
870 void AliCaloCalibPedestal::ComputeDiffAndRatio()
872 // calculate differences and ratios relative to a reference
873 ValidateProfiles(); // make sure histos/profiles exist
874 ValidateComparisonProfiles();//Make sure the comparison histos exist
877 return;//Return if the reference object isn't loaded
883 for (int i = 0; i < fModules; i++) {
884 //For computing the difference, we cannot simply do TProfile2D->Add(), because that subtracts the sum of all entries,
885 //which means that the mean of the new profile will not be the difference of the means. So do it by hand:
886 for (int j = 0; j < fColumns; j++) {
887 for (int k = 0; k < fRows; k++) {
888 bin = ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->GetBin(j+1, k+1);//Note that we assume here that all histos have the same structure...
890 if (fReference->GetPeakProfileHighGain(i)->GetBinContent(bin) > 0) {
891 diff = GetPeakProfileHighGain(i)->GetBinContent(bin) - fReference->GetPeakProfileHighGain(i)->GetBinContent(bin);
892 ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinContent(bin, diff);
893 ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinEntries(bin, 1);
894 ratio = GetPeakProfileHighGain(i)->GetBinContent(bin) / fReference->GetPeakProfileHighGain(i)->GetBinContent(bin);
895 ((TProfile2D*)fPeakMinusPedHighGainRatio[i])->SetBinContent(bin, ratio);
896 ((TProfile2D*)fPeakMinusPedHighGainRatio[i])->SetBinEntries(bin, 1);
899 if (fReference->GetPeakProfileLowGain(i)->GetBinContent(bin) > 0) {
900 diff = GetPeakProfileLowGain(i)->GetBinContent(bin) - fReference->GetPeakProfileLowGain(i)->GetBinContent(bin);
901 ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinContent(bin, diff);
902 ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinEntries(bin, 1);
903 ratio = GetPeakProfileLowGain(i)->GetBinContent(bin) / fReference->GetPeakProfileLowGain(i)->GetBinContent(bin);
904 ((TProfile2D*)fPeakMinusPedLowGainRatio[i])->SetBinContent(bin, ratio);
905 ((TProfile2D*)fPeakMinusPedLowGainRatio[i])->SetBinEntries(bin, 1);
908 if (fReference->GetPedProfileHighGain(i)->GetBinContent(bin) > 0) {
909 diff = GetPedProfileHighGain(i)->GetBinContent(bin) - fReference->GetPedProfileHighGain(i)->GetBinContent(bin);
910 ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinContent(bin, diff);
911 ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinEntries(bin, 1);
912 ratio = GetPedProfileHighGain(i)->GetBinContent(bin) / fReference->GetPedProfileHighGain(i)->GetBinContent(bin);
913 ((TProfile2D*)fPedestalHighGainRatio[i])->SetBinContent(bin, ratio);
914 ((TProfile2D*)fPedestalHighGainRatio[i])->SetBinEntries(bin, 1);
917 if (fReference->GetPedProfileLowGain(i)->GetBinContent(bin) > 0) {
918 diff = GetPedProfileLowGain(i)->GetBinContent(bin) - fReference->GetPedProfileLowGain(i)->GetBinContent(bin);
919 ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinContent(bin, diff);
920 ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinEntries(bin, 1);
921 ratio = GetPedProfileLowGain(i)->GetBinContent(bin) / fReference->GetPedProfileLowGain(i)->GetBinContent(bin);
922 ((TProfile2D*)fPedestalLowGainRatio[i])->SetBinContent(bin, ratio);
923 ((TProfile2D*)fPedestalLowGainRatio[i])->SetBinEntries(bin, 1);
929 // same for LED Ref/Mon channels
930 for (int j = 0; j <= fLEDRefs; j++) {
931 bin = j+1;//Note that we assume here that all histos have the same structure...
933 if (fReference->GetPedLEDRefProfileHighGain(i)->GetBinContent(bin) > 0) {
934 diff = GetPedLEDRefProfileHighGain(i)->GetBinContent(bin) - fReference->GetPedLEDRefProfileHighGain(i)->GetBinContent(bin);
935 ((TProfile*)fPedestalLEDRefHighGainDiff[i])->SetBinContent(bin, diff);
936 ((TProfile*)fPedestalLEDRefHighGainDiff[i])->SetBinEntries(bin, 1);
937 ratio = GetPedLEDRefProfileHighGain(i)->GetBinContent(bin) / fReference->GetPedLEDRefProfileHighGain(i)->GetBinContent(bin);
938 ((TProfile*)fPedestalLEDRefHighGainRatio[i])->SetBinContent(bin, ratio);
939 ((TProfile*)fPedestalLEDRefHighGainRatio[i])->SetBinEntries(bin, 1);
942 if (fReference->GetPedLEDRefProfileLowGain(i)->GetBinContent(bin) > 0) {
943 diff = GetPedLEDRefProfileLowGain(i)->GetBinContent(bin) - fReference->GetPedLEDRefProfileLowGain(i)->GetBinContent(bin);
944 ((TProfile*)fPedestalLEDRefLowGainDiff[i])->SetBinContent(bin, diff);
945 ((TProfile*)fPedestalLEDRefLowGainDiff[i])->SetBinEntries(bin, 1);
946 ratio = GetPedLEDRefProfileLowGain(i)->GetBinContent(bin) / fReference->GetPedLEDRefProfileLowGain(i)->GetBinContent(bin);
947 ((TProfile*)fPedestalLEDRefLowGainRatio[i])->SetBinContent(bin, ratio);
948 ((TProfile*)fPedestalLEDRefLowGainRatio[i])->SetBinEntries(bin, 1);
957 //_____________________________________________________________________
958 void AliCaloCalibPedestal::ComputeHotAndWarningTowers(const char * hotMapFile)
959 { // look for hot/noisy towers
960 ValidateProfiles(); // make sure histos/profiles exist
962 char name[512];//Quite a long temp buffer, just in case the filename includes a path
965 snprintf(name, 512, "%s.txt", hotMapFile);
966 fout = new ofstream(name);
967 if (!fout->is_open()) {
969 fout = 0;//Set the pointer to empty if the file was not opened
973 for(int i = 0; i < fModules; i++){
975 //first we compute the peak-pedestal distribution for each supermodule...
976 if( GetPeakHighGainHisto(i)->GetEntries() > 0 ) {
977 double min = GetPeakProfileHighGain(i)->GetBinContent(GetPeakProfileHighGain(i)->GetMinimumBin());
978 double max = GetPeakProfileHighGain(i)->GetBinContent(GetPeakProfileHighGain(i)->GetMaximumBin());
979 TH1D *hPeakFit = new TH1D(Form("hFit_%d", i), Form("hFit_%d", i), (int)((max-min)*10), min-1, max+1);
981 for (int j = 1; j <= fColumns; j++) {
982 for (int k = 1; k <= fRows; k++) {
983 hPeakFit->Fill(GetPeakProfileHighGain(i)->GetBinContent(j, k));
987 //...and then we try to fit it
988 double mean = hPeakFit->GetMean();
989 double sigma = hPeakFit->GetRMS();
991 hPeakFit->Fit("gaus", "OQ", "", mean - 3*sigma, mean + 3*sigma);
992 mean = hPeakFit->GetFunction("gaus")->GetParameter(1);
993 sigma = hPeakFit->GetFunction("gaus")->GetParameter(2);
995 catch (const std::exception & e) {
996 printf("AliCaloCalibPedestal: TH1D PeakFit exception %s", e.what());
1002 //Then we look for warm/hot towers
1003 TH2F * hPeak2D = GetPeakHighGainHisto(i);
1004 hPeak2D->GetYaxis()->SetRangeUser( fWarningThreshold, hPeak2D->GetYaxis()->GetBinUpEdge(hPeak2D->GetNbinsY()) );
1007 int warnCounter = 0;
1008 for (int j = 1; j <= fColumns; j++) {
1009 for (int k = 1; k <= fRows; k++) {
1010 //we start looking for warm/warning towers...
1011 // histogram x-axis index
1012 idx = k-1 + fRows*(j-1); // this is what is used in the Fill call
1013 hPeak2D->GetXaxis()->SetRangeUser(idx, idx);
1014 warnCounter = (int) hPeak2D->Integral();
1015 if(warnCounter > fNEvents * fWarningFraction) {
1016 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kWarning);
1017 /* printf("mod %d col %d row %d warnCounter %d - status %d\n",
1018 i, j-1, k-1, warnCounter, (int) (kWarning)); */
1020 //...then we look for hot ones (towers whose values are greater than mean + X*sigma)
1021 if(GetPeakProfileHighGain(i)->GetBinContent(j, k) > mean + fHotSigma*sigma ) {
1022 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kHot);
1023 /* printf("mod %d col %d row %d binc %d - status %d\n",
1024 i, j-1, k-1, (int)(GetPeakProfileHighGain(i)->GetBinContent(j, k)), (int) (kHot)); */
1027 //Write the status to the hot/warm map file, if the file is open.
1028 // module - column - row - status (1=dead, 2= warm/warning , 3 = hot, see .h file enum)
1029 if (fout && ((TH2D*)fDeadMap[i])->GetBinContent(j, k) > 1) {
1034 << ((TH2D*)fDeadMap[i])->GetBinContent(j, k) << endl; }
1044 //_____________________________________________________________________
1045 void AliCaloCalibPedestal::ComputeDeadTowers(const char * deadMapFile)
1047 ValidateProfiles(); // make sure histos/profiles exist
1048 //Computes the number of dead towers etc etc into memory, after this you can call the GetDead... -functions
1052 ofstream * fout = 0;
1053 ofstream * diff = 0;
1054 char name[512];//Quite a long temp buffer, just in case the filename includes a path
1057 snprintf(name, 512, "%s.txt", deadMapFile);
1058 fout = new ofstream(name);
1059 snprintf(name, 512, "%sdiff.txt", deadMapFile);
1060 diff = new ofstream(name);
1061 if (!fout->is_open()) {
1063 fout = 0;//Set the pointer to empty if the file was not opened
1065 if (!diff->is_open()) {
1067 fout = 0;//Set the pointer to empty if the file was not opened
1071 for (int i = 0; i < fModules; i++) {
1072 if (GetPeakProfileHighGain(i)->GetEntries() > 0) { //don't care about empty histos
1073 for (int j = 1; j <= fColumns; j++) {
1074 for (int k = 1; k <= fRows; k++) {
1076 if (GetPeakProfileHighGain(i)->GetBinContent(j, k) < fDeadThreshold) {//It's dead
1077 countTot++;//One more dead total
1083 << "0" << endl;//Write the status to the deadmap file, if the file is open.
1086 if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) >= fDeadThreshold) {
1087 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kRecentlyDeceased);
1088 countNew++;//This tower wasn't dead before!
1090 ( *diff) << i << " "
1094 << "0" << endl;//Write the status to the deadmap difference file, if the file is open.
1098 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kDead);//This has been dead before. Nothing new
1101 else { //It's ALIVE!!
1102 //Don't bother with writing the live ones.
1103 if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) < fDeadThreshold) {
1104 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kResurrected);
1105 countRes++; //This tower was dead before => it's a miracle! :P
1111 << "1" << endl;//Write the status to the deadmap difference file, if the file is open.
1115 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kAlive);
1120 }//end for j/columns
1121 }//end if GetEntries >= 0
1130 fDeadTowers = countTot;
1131 fNewDeadTowers = countNew;
1132 fResurrectedTowers = countRes;
1135 //_____________________________________________________________________
1136 Bool_t AliCaloCalibPedestal::IsBadChannel(int imod, int icol, int irow) const
1138 // Check if status info histo exists
1139 if (!fDeadMap[imod]) {
1143 //Check if channel is dead or hot.
1144 Int_t status = (Int_t) ( ((TH2D*)fDeadMap[imod])->GetBinContent(icol,irow) );
1145 if(status == kAlive)
1152 //_____________________________________________________________________
1153 void AliCaloCalibPedestal::SetChannelStatus(int imod, int icol, int irow, int status)
1155 ValidateProfiles(); // make sure histos/profiles exist
1156 //Set status of channel dead, hot, alive ...
1157 ((TH2D*)fDeadMap[imod])->SetBinContent(icol, irow, status);