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 //________________________________________________________________________
44 #include "AliRawReader.h"
45 #include "AliCaloRawStreamV3.h"
48 #include "AliCaloCalibPedestal.h"
50 ClassImp(AliCaloCalibPedestal)
54 // ctor; initialize everything in order to avoid compiler warnings
55 AliCaloCalibPedestal::AliCaloCalibPedestal(kDetType detectorType) :
59 fPedestalRMSLowGain(),
60 fPedestalRMSHighGain(),
61 fPeakMinusPedLowGain(),
62 fPeakMinusPedHighGain(),
63 fPedestalLowGainDiff(),
64 fPedestalHighGainDiff(),
65 fPeakMinusPedLowGainDiff(),
66 fPeakMinusPedHighGainDiff(),
67 fPedestalLowGainRatio(),
68 fPedestalHighGainRatio(),
69 fPeakMinusPedLowGainRatio(),
70 fPeakMinusPedHighGainRatio(),
76 fResurrectedTowers(0),
88 fSelectPedestalSamples(kTRUE),
89 fFirstPedestalSample(0),
90 fLastPedestalSample(15)
92 //Default constructor. First we set the detector-type related constants.
93 if (detectorType == kPhos) {
94 fColumns = fgkPhosCols;
96 fModules = fgkPhosModules;
103 //We'll just trust the enum to keep everything in line, so that if detectorType
104 //isn't kPhos then it is kEmCal. Note, however, that this is not necessarily the
105 //case, if someone intentionally gives another number
106 fColumns = AliEMCALGeoParams::fgkEMCALCols;
107 fRows = AliEMCALGeoParams::fgkEMCALRows;
108 fModules = AliEMCALGeoParams::fgkEMCALModules;
109 fCaloString = "EMCAL";
114 fDetType = detectorType;
116 //Then, loop for the requested number of modules
118 for (int i = 0; i < fModules; i++) {
119 //Pedestals, low gain
120 name = "hPedlowgain";
122 title = "Pedestals, low gain, module ";
124 fPedestalLowGain.Add(new TProfile2D(name, title,
125 fColumns, 0.0, fColumns,
126 fRows, fRowMin, fRowMax,"s"));
128 //Pedestals, high gain
129 name = "hPedhighgain";
131 title = "Pedestals, high gain, module ";
133 fPedestalHighGain.Add(new TProfile2D(name, title,
134 fColumns, 0.0, fColumns,
135 fRows, fRowMin, fRowMax,"s"));
136 //All Samples, low gain
137 name = "hPedestalRMSlowgain";
139 title = "Pedestal RMS, low gain, module ";
141 fPedestalRMSLowGain.Add(new TProfile2D(name, title,
142 fColumns, 0.0, fColumns,
143 fRows, fRowMin, fRowMax,"s"));
145 //All Samples, high gain
146 name = "hPedestalRMShighgain";
148 title = "Pedestal RMS, high gain, module ";
150 fPedestalRMSHighGain.Add(new TProfile2D(name, title,
151 fColumns, 0.0, fColumns,
152 fRows, fRowMin, fRowMax,"s"));
154 //Peak-Pedestals, low gain
155 name = "hPeakMinusPedlowgain";
157 title = "Peak-Pedestal, low gain, module ";
159 fPeakMinusPedLowGain.Add(new TProfile2D(name, title,
160 fColumns, 0.0, fColumns,
161 fRows, fRowMin, fRowMax,"s"));
163 //Peak-Pedestals, high gain
164 name = "hPeakMinusPedhighgain";
166 title = "Peak-Pedestal, high gain, module ";
168 fPeakMinusPedHighGain.Add(new TProfile2D(name, title,
169 fColumns, 0.0, fColumns,
170 fRows, fRowMin, fRowMax,"s"));
174 title = "Dead map, module ";
176 fDeadMap.Add(new TH2D(name, title, fColumns, 0.0, fColumns,
177 fRows, fRowMin, fRowMax));
179 }//end for nModules create the histograms
181 //Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
182 fPedestalLowGain.Compress();
183 fPedestalHighGain.Compress();
184 fPedestalRMSLowGain.Compress();
185 fPedestalRMSHighGain.Compress();
186 fPeakMinusPedLowGain.Compress();
187 fPeakMinusPedHighGain.Compress();
189 //Make them the owners of the profiles, so we don't need to care about deleting them
190 //fPedestalLowGain.SetOwner();
191 //fPedestalHighGain.SetOwner();
192 //fPeakMinusPedLowGain.SetOwner();
193 //fPeakMinusPedHighGain.SetOwner();
198 //_____________________________________________________________________
199 AliCaloCalibPedestal::~AliCaloCalibPedestal()
201 if (fReference) delete fReference;//Delete the reference object, if it has been loaded
202 //TObjArray will delete the histos/profiles when it is deleted.
206 //_____________________________________________________________________
207 AliCaloCalibPedestal::AliCaloCalibPedestal(const AliCaloCalibPedestal &ped) :
211 fPedestalRMSLowGain(),
212 fPedestalRMSHighGain(),
213 fPeakMinusPedLowGain(),
214 fPeakMinusPedHighGain(),
215 fPedestalLowGainDiff(),
216 fPedestalHighGainDiff(),
217 fPeakMinusPedLowGainDiff(),
218 fPeakMinusPedHighGainDiff(),
219 fPedestalLowGainRatio(),
220 fPedestalHighGainRatio(),
221 fPeakMinusPedLowGainRatio(),
222 fPeakMinusPedHighGainRatio(),
224 fNEvents(ped.GetNEvents()),
225 fNChanFills(ped.GetNChanFills()),
226 fDeadTowers(ped.GetDeadTowerCount()),
227 fNewDeadTowers(ped.GetDeadTowerNew()),
228 fResurrectedTowers(ped.GetDeadTowerResurrected()),
229 fReference( 0 ), //! note that we do not try to copy the reference info here
230 fDetType(ped.GetDetectorType()),
231 fColumns(ped.GetColumns()),
232 fRows(ped.GetRows()),
233 fModules(ped.GetModules()),
234 fRowMin(ped.GetRowMin()),
235 fRowMax(ped.GetRowMax()),
236 fRowMultiplier(ped.GetRowMultiplier()),
237 fCaloString(ped.GetCaloString()),
238 fMapping(NULL), //! note that we are not copying the map info
239 fRunNumber(ped.GetRunNumber()),
240 fSelectPedestalSamples(ped.GetSelectPedestalSamples()),
241 fFirstPedestalSample(ped.GetFirstPedestalSample()),
242 fLastPedestalSample(ped.GetLastPedestalSample())
244 // Then the ObjArray ones; we add the histograms rather than trying TObjArray = assignment
245 //DS: this has not really been tested yet..
246 for (int i = 0; i < fModules; i++) {
247 fPedestalLowGain.Add( ped.GetPedProfileLowGain(i) );
248 fPedestalHighGain.Add( ped.GetPedProfileHighGain(i) );
249 fPedestalRMSLowGain.Add( ped.GetPedRMSProfileLowGain(i) );
250 fPedestalRMSHighGain.Add( ped.GetPedRMSProfileHighGain(i) );
251 fPeakMinusPedLowGain.Add( ped.GetPeakProfileLowGain(i) );
252 fPeakMinusPedHighGain.Add( ped.GetPeakProfileHighGain(i) );
254 fDeadMap.Add( ped.GetDeadMap(i) );
257 //Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
258 fPedestalLowGain.Compress();
259 fPedestalHighGain.Compress();
260 fPedestalRMSLowGain.Compress();
261 fPedestalRMSHighGain.Compress();
262 fPeakMinusPedLowGain.Compress();
263 fPeakMinusPedHighGain.Compress();
267 // assignment operator; use copy ctor to make life easy..
268 //_____________________________________________________________________
269 AliCaloCalibPedestal& AliCaloCalibPedestal::operator = (const AliCaloCalibPedestal &source)
271 // assignment operator; use copy ctor
272 if (&source == this) return *this;
274 new (this) AliCaloCalibPedestal(source);
278 //_____________________________________________________________________
279 void AliCaloCalibPedestal::Reset()
281 // Reset all arrays/histograms
282 for (int i = 0; i < fModules; i++) {
283 GetPedProfileLowGain(i)->Reset();
284 GetPedProfileHighGain(i)->Reset();
285 GetPeakProfileLowGain(i)->Reset();
286 GetPeakProfileHighGain(i)->Reset();
287 GetDeadMap(i)->Reset();
289 if (!fPedestalLowGainDiff.IsEmpty()) {
290 //This means that the comparison profiles have been created.
292 GetPedProfileLowGainDiff(i)->Reset();
293 GetPedProfileHighGainDiff(i)->Reset();
294 GetPeakProfileLowGainDiff(i)->Reset();
295 GetPeakProfileHighGainDiff(i)->Reset();
297 GetPedProfileLowGainRatio(i)->Reset();
298 GetPedProfileHighGainRatio(i)->Reset();
299 GetPeakProfileLowGainRatio(i)->Reset();
300 GetPeakProfileHighGainRatio(i)->Reset();
307 fResurrectedTowers = 0;
309 //To think about: should fReference be deleted too?... let's not do it this time, at least...
312 // Parameter/cut handling
313 //_____________________________________________________________________
314 void AliCaloCalibPedestal::SetParametersFromFile(const char *parameterFile)
316 // Note: this method is a bit more complicated than it really has to be
317 // - allowing for multiple entries per line, arbitrary order of the
318 // different variables etc. But I wanted to try and do this in as
319 // correct a C++ way as I could (as an exercise).
321 static const string delimitor("::");
323 // open, check input file
324 ifstream in( parameterFile );
326 printf("in AliCaloCalibPedestal::SetParametersFromFile - Using default/run_time parameters.\n");
333 while ((in.rdstate() & ios::failbit) == 0 ) {
335 // Read into the raw char array and then construct a string
336 // to do the searching
337 in.getline(readline, 1024);
338 istringstream s(readline);
340 while ( ( s.rdstate() & ios::failbit ) == 0 ) {
345 // check stream status
346 if( s.rdstate() & ios::failbit ) break;
348 // skip rest of line if comments found
349 if( keyValue.substr( 0, 2 ) == "//" ) break;
351 // look for "::" in keyValue pair
352 size_t position = keyValue.find( delimitor );
353 if( position == string::npos ) {
354 printf("wrong format for key::value pair: %s\n", keyValue.c_str());
357 // split keyValue pair
358 string key( keyValue.substr( 0, position ) );
359 string value( keyValue.substr( position+delimitor.size(),
360 keyValue.size()-delimitor.size() ) );
362 // check value does not contain a new delimitor
363 if( value.find( delimitor ) != string::npos ) {
364 printf("wrong format for key::value pair: %s\n", keyValue.c_str());
367 // debug: check key value pair
368 // printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
370 // if the key matches with something we expect, we assign the new value
371 istringstream iss(value);
372 // the comparison strings defined at the beginning of this method
373 if ( (key == "fFirstPedestalSample") || (key == "fLastPedestalSample") ) {
374 printf("AliCaloCalibPedestal::SetParametersFromFile - key %s value %s\n", key.c_str(), value.c_str());
376 if (key == "fFirstPedestalSample") {
377 iss >> fFirstPedestalSample;
379 else if (key == "fLastPedestalSample") {
380 iss >> fLastPedestalSample;
392 //_____________________________________________________________________
393 void AliCaloCalibPedestal::WriteParametersToFile(const char *parameterFile)
395 //Write parameters in file.
397 static const string delimitor("::");
398 ofstream out( parameterFile );
399 out << "// " << parameterFile << endl;
400 out << "fFirstPedestalSample" << "::" << fFirstPedestalSample << endl;
401 out << "fLastPedestalSample" << "::" << fLastPedestalSample << endl;
407 //_____________________________________________________________________
408 Bool_t AliCaloCalibPedestal::AddInfo(const AliCaloCalibPedestal *ped)
410 // just do this for the basic histograms/profiles that get filled in ProcessEvent
411 // may not have data for all modules, but let's just Add everything..
412 for (int i = 0; i < fModules; i++) {
413 GetPedProfileLowGain(i)->Add( ped->GetPedProfileLowGain(i) );
414 GetPedProfileHighGain(i)->Add( ped->GetPedProfileHighGain(i) );
415 GetPeakProfileLowGain(i)->Add( ped->GetPeakProfileLowGain(i) );
416 GetPeakProfileHighGain(i)->Add( ped->GetPeakProfileHighGain(i) );
419 // DeadMap; Diff profiles etc would need to be redone after this operation
421 return kTRUE;//We succesfully added info from the supplied object
424 //_____________________________________________________________________
425 Bool_t AliCaloCalibPedestal::ProcessEvent(AliRawReader *rawReader)
427 // if fMapping is NULL the rawstream will crate its own mapping
428 AliCaloRawStreamV3 rawStream(rawReader, fCaloString, (AliAltroMapping**)fMapping);
429 if (fDetType == kEmCal) {
430 rawReader->Select("EMCAL", 0, AliEMCALGeoParams::fgkLastAltroDDL) ; //select EMCAL DDL range
432 return ProcessEvent(&rawStream);
435 //_____________________________________________________________________
436 Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStreamV3 *in)
438 // Method to process=analyze one event in the data stream
439 if (!in) return kFALSE; //Return right away if there's a null pointer
440 fNEvents++; // one more event
442 // indices for the reading
446 int i = 0; // sample counter
449 // start loop over input stream
450 while (in->NextDDL()) {
451 while (in->NextChannel()) {
454 int max = AliEMCALGeoParams::fgkSampleMin, min = AliEMCALGeoParams::fgkSampleMax; // min and max sample values
457 // for the pedestal calculation
458 int sampleSum = 0; // sum of samples
459 int squaredSampleSum = 0; // sum of samples squared
460 int nSum = 0; // number of samples in sum
462 double mean = 0, squaredMean = 0, rms = 0;
464 while (in->NextBunch()) {
465 const UShort_t *sig = in->GetSignals();
466 startBin = in->GetStartTimeBin();
467 nsamples += in->GetBunchLength();
468 for (i = 0; i < in->GetBunchLength(); i++) {
472 // check if it's a min or max value
473 if (sample < min) min = sample;
474 if (sample > max) max = sample;
476 // should we add it for the pedestal calculation?
477 if ( (fFirstPedestalSample<=time && time<=fLastPedestalSample) || // sample time in range
478 !fSelectPedestalSamples ) { // or we don't restrict the sample range.. - then we'll take all
480 squaredSampleSum += sample*sample;
484 } // loop over samples in bunch
485 } // loop over bunches
487 if (nsamples > 0) { // this check is needed for when we have zero-supp. on, but not sparse readout
489 // calculate pedesstal estimate: mean of possibly selected samples
491 mean = sampleSum / (1.0 * nSum);
492 squaredMean = squaredSampleSum / (1.0 * nSum);
493 // The variance (rms squared) is equal to the mean of the squares minus the square of the mean..
494 rms = sqrt(squaredMean - mean*mean);
502 // we're done with the calc. for this channel; let's prepare to fill histo
503 gain = -1; // init to not valid value
504 if ( in->IsLowGain() ) {
507 else if ( in->IsHighGain() ) {
511 // it should be enough to check the SuperModule info for each DDL really, but let's keep it here for now
512 int arrayPos = in->GetModule(); //The modules are numbered starting from 0
513 if (arrayPos >= fModules) {
514 //TODO: return an error message, if appopriate (perhaps if debug>0?)
518 if (arrayPos < 0 || arrayPos >= fModules) {
519 printf("Oh no: arrayPos = %i.\n", arrayPos);
522 fNChanFills++; // one more channel found, and profile to be filled
523 //NOTE: coordinates are (column, row) for the profiles
525 //fill the low gain histograms
526 ((TProfile2D*)fPeakMinusPedLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
527 if (nSum>0) { // only fill pedestal info in case it could be calculated
528 ((TProfile2D*)fPedestalLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), mean);
529 ((TProfile2D*)fPedestalRMSLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), rms);
532 else if (gain == 1) {
533 //fill the high gain ones
534 ((TProfile2D*)fPeakMinusPedHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
535 if (nSum>0) { // only fill pedestal info in case it could be calculated
536 ((TProfile2D*)fPedestalHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), mean);
537 ((TProfile2D*)fPedestalRMSHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), rms);
541 } // nsamples>0 check, some data found for this channel; not only trailer/header
542 }// end while over channel
543 }//end while over DDL's, of input stream
545 in->Reset(); // just in case the next customer forgets to check if the stream was reset..
550 //_____________________________________________________________________
551 Bool_t AliCaloCalibPedestal::SaveHistograms(TString fileName, Bool_t saveEmptyHistos)
553 //Saves all the histograms (or profiles, to be accurate) to the designated file
555 TFile destFile(fileName, "recreate");
557 if (destFile.IsZombie()) {
563 for (int i = 0; i < fModules; i++) {
564 if( ((TProfile2D *)fPeakMinusPedLowGain[i])->GetEntries() || saveEmptyHistos) {
565 fPeakMinusPedLowGain[i]->Write();
567 if( ((TProfile2D *)fPeakMinusPedHighGain[i])->GetEntries() || saveEmptyHistos) {
568 fPeakMinusPedHighGain[i]->Write();
570 if( ((TProfile2D *)fPedestalLowGain[i])->GetEntries() || saveEmptyHistos) {
571 fPedestalLowGain[i]->Write();
573 if( ((TProfile2D *)fPedestalHighGain[i])->GetEntries() || saveEmptyHistos) {
574 fPedestalHighGain[i]->Write();
575 Printf("save %d", i);
577 if( ((TProfile2D *)fPedestalRMSLowGain[i])->GetEntries() || saveEmptyHistos) {
578 fPedestalRMSLowGain[i]->Write();
580 if( ((TProfile2D *)fPedestalRMSHighGain[i])->GetEntries() || saveEmptyHistos) {
581 fPedestalRMSHighGain[i]->Write();
590 //_____________________________________________________________________
591 Bool_t AliCaloCalibPedestal::LoadReferenceCalib(TString fileName, TString objectName)
594 //Make sure that the histograms created when loading the object are not destroyed as the file object is destroyed
595 TH1::AddDirectory(kFALSE);
597 TFile *sourceFile = new TFile(fileName);
598 if (sourceFile->IsZombie()) {
599 return kFALSE;//We couldn't load the reference
602 if (fReference) delete fReference;//Delete the reference object, if it already exists
605 fReference = (AliCaloCalibPedestal*)sourceFile->Get(objectName);
607 if (!fReference || !(fReference->InheritsFrom(AliCaloCalibPedestal::Class())) || (fReference->GetDetectorType() != fDetType)) {
608 if (fReference) delete fReference;//Delete the object, in case we had an object of the wrong type
615 //Reset the histogram ownership behaviour. NOTE: a better workaround would be good, since this may accidentally set AddDirectory to true, even
616 //if we are called by someone who has set it to false...
617 TH1::AddDirectory(kTRUE);
619 return kTRUE;//We succesfully loaded the object
622 //_____________________________________________________________________
623 void AliCaloCalibPedestal::ValidateComparisonProfiles()
625 //Make sure the comparison histos exist
626 if (!fPedestalLowGainDiff.IsEmpty()) return; //The profiles already exist. We just check one, because they're all created at
630 //Then, loop for the requested number of modules
632 for (int i = 0; i < fModules; i++) {
633 //Pedestals, low gain
634 name = "hPedlowgainDiff";
636 title = "Pedestals difference, low gain, module ";
638 fPedestalLowGainDiff.Add(new TProfile2D(name, title,
639 fColumns, 0.0, fColumns,
640 fRows, fRowMin, fRowMax,"s"));
642 //Pedestals, high gain
643 name = "hPedhighgainDiff";
645 title = "Pedestals difference, high gain, module ";
647 fPedestalHighGainDiff.Add(new TProfile2D(name, title,
648 fColumns, 0.0, fColumns,
649 fRows, fRowMin, fRowMax,"s"));
651 //Peak-Pedestals, high gain
652 name = "hPeakMinusPedhighgainDiff";
654 title = "Peak-Pedestal difference, high gain, module ";
656 fPeakMinusPedHighGainDiff.Add(new TProfile2D(name, title,
657 fColumns, 0.0, fColumns,
658 fRows, fRowMin, fRowMax,"s"));
660 //Pedestals, low gain
661 name = "hPedlowgainRatio";
663 title = "Pedestals ratio, low gain, module ";
665 fPedestalLowGainRatio.Add(new TProfile2D(name, title,
666 fColumns, 0.0, fColumns,
667 fRows, fRowMin, fRowMax,"s"));
669 //Pedestals, high gain
670 name = "hPedhighgainRatio";
672 title = "Pedestals ratio, high gain, module ";
674 fPedestalHighGainRatio.Add(new TProfile2D(name, title,
675 fColumns, 0.0, fColumns,
676 fRows, fRowMin, fRowMax,"s"));
678 //Peak-Pedestals, low gain
679 name = "hPeakMinusPedlowgainRatio";
681 title = "Peak-Pedestal ratio, low gain, module ";
683 fPeakMinusPedLowGainRatio.Add(new TProfile2D(name, title,
684 fColumns, 0.0, fColumns,
685 fRows, fRowMin, fRowMax,"s"));
687 //Peak-Pedestals, high gain
688 name = "hPeakMinusPedhighgainRatio";
690 title = "Peak-Pedestal ratio, high gain, module ";
692 fPeakMinusPedHighGainRatio.Add(new TProfile2D(name, title,
693 fColumns, 0.0, fColumns,
694 fRows, fRowMin, fRowMax,"s"));
696 }//end for nModules create the histograms
699 //_____________________________________________________________________
700 void AliCaloCalibPedestal::ComputeDiffAndRatio()
702 // calculate differences and ratios relative to a reference
703 ValidateComparisonProfiles();//Make sure the comparison histos exist
706 return;//Return if the reference object isn't loaded
709 for (int i = 0; i < fModules; i++) {
710 //Compute the ratio of the histograms
712 ((TProfile2D*)fPedestalLowGainRatio[i])->Divide(GetPedProfileLowGain(i), fReference->GetPedProfileLowGain(i), 1.0, 1.0);
713 ((TProfile2D*)fPedestalHighGainRatio[i])->Divide(GetPedProfileHighGain(i), fReference->GetPedProfileHighGain(i), 1.0, 1.0);
714 ((TProfile2D*)fPeakMinusPedLowGainRatio[i])->Divide(GetPeakProfileLowGain(i), fReference->GetPeakProfileLowGain(i), 1.0, 1.0);
715 ((TProfile2D*)fPeakMinusPedHighGainRatio[i])->Divide(GetPeakProfileHighGain(i), fReference->GetPeakProfileHighGain(i), 1.0, 1.0);
717 //For computing the difference, we cannot simply do TProfile2D->Add(), because that subtracts the sum of all entries,
718 //which means that the mean of the new profile will not be the difference of the means. So do it by hand:
719 for (int j = 0; j <= fColumns; j++) {
720 for (int k = 0; k <= fRows; k++) {
721 int bin = ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->GetBin(j+1, k+1);//Note that we assume here that all histos have the same structure...
722 double diff = fReference->GetPeakProfileHighGain(i)->GetBinContent(bin) - GetPeakProfileHighGain(i)->GetBinContent(bin);
723 ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinContent(j+1, k+1, diff);
724 ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinEntries(bin, 1);
726 diff = fReference->GetPeakProfileLowGain(i)->GetBinContent(bin) - GetPeakProfileLowGain(i)->GetBinContent(bin);
727 ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinContent(j+1, k+1, diff);
728 ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinEntries(bin, 1);
730 diff = fReference->GetPedProfileHighGain(i)->GetBinContent(bin) - GetPedProfileHighGain(i)->GetBinContent(bin);
731 ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinContent(j+1, k+1, diff);
732 ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinEntries(bin, 1);
734 diff = fReference->GetPedProfileLowGain(i)->GetBinContent(bin) - GetPedProfileLowGain(i)->GetBinContent(bin);
735 ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinContent(j+1, k+1, diff);
736 ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinEntries(bin, 1);
745 //_____________________________________________________________________
746 void AliCaloCalibPedestal::ComputeDeadTowers(int threshold, const char * deadMapFile)
748 //Computes the number of dead towers etc etc into memory, after this you can call the GetDead... -functions
754 char name[512];//Quite a long temp buffer, just in case the filename includes a path
757 snprintf(name, 512, "%s.txt", deadMapFile);
758 fout = new ofstream(name);
759 snprintf(name, 512, "%sdiff.txt", deadMapFile);
760 diff = new ofstream(name);
761 if (!fout->is_open()) {
763 fout = 0;//Set the pointer to empty if the file was not opened
765 if (!diff->is_open()) {
767 fout = 0;//Set the pointer to empty if the file was not opened
771 for (int i = 0; i < fModules; i++) {
772 if (GetPeakProfileHighGain(i)->GetEntries() > 0) { //don't care about empty histos
773 for (int j = 1; j <= fColumns; j++) {
774 for (int k = 1; k <= fRows; k++) {
776 if (GetPeakProfileHighGain(i)->GetBinContent(j, k) < threshold) {//It's dead
777 countTot++;//One more dead total
780 << (fRows - k) << " "
783 << "0" << endl;//Write the status to the deadmap file, if the file is open.
786 if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) >= threshold) {
787 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kRecentlyDeceased);
788 countNew++;//This tower wasn't dead before!
791 << (fRows - k) << " "
794 << "0" << endl;//Write the status to the deadmap difference file, if the file is open.
798 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kDead);//This has been dead before. Nothing new
801 else { //It's ALIVE!!
802 //Don't bother with writing the live ones.
804 // (*fout) << i << " "
805 // << (fRows - k) << " "
808 // << "1" << endl;//Write the status to the deadmap file, if the file is open.
809 if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) < threshold) {
810 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kResurrected);
811 countRes++; //This tower was dead before => it's a miracle! :P
814 << (fRows - k) << " "
817 << "1" << endl;//Write the status to the deadmap difference file, if the file is open.
821 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kAlive);
827 }//end if GetEntries >= 0
836 fDeadTowers = countTot;
837 fNewDeadTowers = countNew;
838 fResurrectedTowers = countRes;
841 //_____________________________________________________________________
842 Bool_t AliCaloCalibPedestal::IsBadChannel(int imod, int icol, int irow) const
844 //Check if channel is dead or hot.
846 Int_t status = (Int_t) ( ((TH2D*)fDeadMap[imod])->GetBinContent(icol,irow) );
854 //_____________________________________________________________________
855 void AliCaloCalibPedestal::SetChannelStatus(int imod, int icol, int irow, int status)
857 //Set status of channel dead, hot, alive ...
859 ((TH2D*)fDeadMap[imod])->SetBinContent(icol,irow, status);