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 //________________________________________________________________________
43 #include "AliCaloRawStream.h"
46 #include "AliCaloCalibPedestal.h"
48 ClassImp(AliCaloCalibPedestal)
52 // ctor; initialize everything in order to avoid compiler warnings
53 AliCaloCalibPedestal::AliCaloCalibPedestal(kDetType detectorType) :
59 fPeakMinusPedLowGain(),
60 fPeakMinusPedHighGain(),
61 fPedestalLowGainDiff(),
62 fPedestalHighGainDiff(),
63 fPeakMinusPedLowGainDiff(),
64 fPeakMinusPedHighGainDiff(),
65 fPedestalLowGainRatio(),
66 fPedestalHighGainRatio(),
67 fPeakMinusPedLowGainRatio(),
68 fPeakMinusPedHighGainRatio(),
74 fResurrectedTowers(0),
87 //Default constructor. First we set the detector-type related constants.
88 if (detectorType == kPhos) {
89 fColumns = fgkPhosCols;
91 fModules = fgkPhosModules;
98 //We'll just trust the enum to keep everything in line, so that if detectorType
99 //isn't kPhos then it is kEmCal. Note, however, that this is not necessarily the
100 //case, if someone intentionally gives another number
101 fColumns = fgkEmCalCols;
102 fRows = fgkEmCalRows;
103 fModules = fgkEmCalModules;
104 fCaloString = "EMCAL";
109 fDetType = detectorType;
111 //Then, loop for the requested number of modules
113 for (int i = 0; i < fModules; i++) {
114 //Pedestals, low gain
115 name = "hPedlowgain";
117 title = "Pedestals, low gain, module ";
119 fPedestalLowGain.Add(new TProfile2D(name, title,
120 fColumns, 0.0, fColumns,
121 fRows, fRowMin, fRowMax,"s"));
123 //Pedestals, high gain
124 name = "hPedhighgain";
126 title = "Pedestals, high gain, module ";
128 fPedestalHighGain.Add(new TProfile2D(name, title,
129 fColumns, 0.0, fColumns,
130 fRows, fRowMin, fRowMax,"s"));
131 //All Samples, low gain
132 name = "hSamplelowgain";
134 title = "All Samples, low gain, module ";
136 fSampleLowGain.Add(new TProfile2D(name, title,
137 fColumns, 0.0, fColumns,
138 fRows, fRowMin, fRowMax,"s"));
140 //All Samples, high gain
141 name = "hSamplehighgain";
143 title = "All Samples, high gain, module ";
145 fSampleHighGain.Add(new TProfile2D(name, title,
146 fColumns, 0.0, fColumns,
147 fRows, fRowMin, fRowMax,"s"));
149 //Peak-Pedestals, low gain
150 name = "hPeakMinusPedlowgain";
152 title = "Peak-Pedestal, low gain, module ";
154 fPeakMinusPedLowGain.Add(new TProfile2D(name, title,
155 fColumns, 0.0, fColumns,
156 fRows, fRowMin, fRowMax,"s"));
158 //Peak-Pedestals, high gain
159 name = "hPeakMinusPedhighgain";
161 title = "Peak-Pedestal, high gain, module ";
163 fPeakMinusPedHighGain.Add(new TProfile2D(name, title,
164 fColumns, 0.0, fColumns,
165 fRows, fRowMin, fRowMax,"s"));
169 title = "Dead map, module ";
171 fDeadMap.Add(new TH2D(name, title, fColumns, 0.0, fColumns,
172 fRows, fRowMin, fRowMax));
174 }//end for nModules create the histograms
176 //Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
177 fPedestalLowGain.Compress();
178 fPedestalHighGain.Compress();
179 fSampleLowGain.Compress();
180 fSampleHighGain.Compress();
181 fPeakMinusPedLowGain.Compress();
182 fPeakMinusPedHighGain.Compress();
184 //Make them the owners of the profiles, so we don't need to care about deleting them
185 //fPedestalLowGain.SetOwner();
186 //fPedestalHighGain.SetOwner();
187 //fPeakMinusPedLowGain.SetOwner();
188 //fPeakMinusPedHighGain.SetOwner();
193 //_____________________________________________________________________
194 AliCaloCalibPedestal::~AliCaloCalibPedestal()
196 if (fReference) delete fReference;//Delete the reference object, if it has been loaded
197 //TObjArray will delete the histos/profiles when it is deleted.
201 //_____________________________________________________________________
202 AliCaloCalibPedestal::AliCaloCalibPedestal(const AliCaloCalibPedestal &ped) :
208 fPeakMinusPedLowGain(),
209 fPeakMinusPedHighGain(),
210 fPedestalLowGainDiff(),
211 fPedestalHighGainDiff(),
212 fPeakMinusPedLowGainDiff(),
213 fPeakMinusPedHighGainDiff(),
214 fPedestalLowGainRatio(),
215 fPedestalHighGainRatio(),
216 fPeakMinusPedLowGainRatio(),
217 fPeakMinusPedHighGainRatio(),
219 fNEvents(ped.GetNEvents()),
220 fNChanFills(ped.GetNChanFills()),
221 fDeadTowers(ped.GetDeadTowerCount()),
222 fNewDeadTowers(ped.GetDeadTowerNew()),
223 fResurrectedTowers(ped.GetDeadTowerResurrected()),
224 fReference( 0 ), //! note that we do not try to copy the reference info here
225 fDetType(ped.GetDetectorType()),
226 fColumns(ped.GetColumns()),
227 fRows(ped.GetRows()),
228 fModules(ped.GetModules()),
229 fRowMin(ped.GetRowMin()),
230 fRowMax(ped.GetRowMax()),
231 fRowMultiplier(ped.GetRowMultiplier()),
232 fCaloString(ped.GetCaloString()),
233 fMapping(NULL), //! note that we are not copying the map info
234 fRunNumber(ped.GetRunNumber())
236 // Then the ObjArray ones; we add the histograms rather than trying TObjArray = assignment
237 //DS: this has not really been tested yet..
238 for (int i = 0; i < fModules; i++) {
239 fPedestalLowGain.Add( ped.GetPedProfileLowGain(i) );
240 fPedestalHighGain.Add( ped.GetPedProfileHighGain(i) );
241 fSampleLowGain.Add( ped.GetSampleProfileLowGain(i) );
242 fSampleHighGain.Add( ped.GetSampleProfileHighGain(i) );
243 fPeakMinusPedLowGain.Add( ped.GetPeakProfileLowGain(i) );
244 fPeakMinusPedHighGain.Add( ped.GetPeakProfileHighGain(i) );
246 fDeadMap.Add( ped.GetDeadMap(i) );
249 //Compress the arrays, in order to remove the empty objects (a 16 slot array is created by default)
250 fPedestalLowGain.Compress();
251 fPedestalHighGain.Compress();
252 fSampleLowGain.Compress();
253 fSampleHighGain.Compress();
254 fPeakMinusPedLowGain.Compress();
255 fPeakMinusPedHighGain.Compress();
259 // assignment operator; use copy ctor to make life easy..
260 //_____________________________________________________________________
261 AliCaloCalibPedestal& AliCaloCalibPedestal::operator = (const AliCaloCalibPedestal &source)
263 // assignment operator; use copy ctor
264 if (&source == this) return *this;
266 new (this) AliCaloCalibPedestal(source);
270 //_____________________________________________________________________
271 void AliCaloCalibPedestal::Reset()
273 // Reset all arrays/histograms
274 for (int i = 0; i < fModules; i++) {
275 GetPedProfileLowGain(i)->Reset();
276 GetPedProfileHighGain(i)->Reset();
277 GetPeakProfileLowGain(i)->Reset();
278 GetPeakProfileHighGain(i)->Reset();
279 GetDeadMap(i)->Reset();
281 if (!fPedestalLowGainDiff.IsEmpty()) {
282 //This means that the comparison profiles have been created.
284 GetPedProfileLowGainDiff(i)->Reset();
285 GetPedProfileHighGainDiff(i)->Reset();
286 GetPeakProfileLowGainDiff(i)->Reset();
287 GetPeakProfileHighGainDiff(i)->Reset();
289 GetPedProfileLowGainRatio(i)->Reset();
290 GetPedProfileHighGainRatio(i)->Reset();
291 GetPeakProfileLowGainRatio(i)->Reset();
292 GetPeakProfileHighGainRatio(i)->Reset();
299 fResurrectedTowers = 0;
301 //To think about: should fReference be deleted too?... let's not do it this time, at least...
304 //_____________________________________________________________________
305 Bool_t AliCaloCalibPedestal::AddInfo(const AliCaloCalibPedestal *ped)
307 // just do this for the basic histograms/profiles that get filled in ProcessEvent
308 // may not have data for all modules, but let's just Add everything..
309 for (int i = 0; i < fModules; i++) {
310 GetPedProfileLowGain(i)->Add( ped->GetPedProfileLowGain(i) );
311 GetPedProfileHighGain(i)->Add( ped->GetPedProfileHighGain(i) );
312 GetPeakProfileLowGain(i)->Add( ped->GetPeakProfileLowGain(i) );
313 GetPeakProfileHighGain(i)->Add( ped->GetPeakProfileHighGain(i) );
316 // DeadMap; Diff profiles etc would need to be redone after this operation
318 return kTRUE;//We succesfully added info from the supplied object
321 //_____________________________________________________________________
322 Bool_t AliCaloCalibPedestal::ProcessEvent(AliRawReader *rawReader)
324 // if fMapping is NULL the rawstream will crate its own mapping
325 AliCaloRawStream rawStream(rawReader, fCaloString, (AliAltroMapping**)fMapping);
326 return ProcessEvent(&rawStream);
329 //_____________________________________________________________________
330 Bool_t AliCaloCalibPedestal::ProcessEvent(AliCaloRawStream *in)
332 // Method to process=analyze one event in the data stream
333 if (!in) return kFALSE; //Return right away if there's a null pointer
335 fNEvents++; // one more event
336 int sample, i = 0; //The sample temp, and the sample number in current event.
337 int max = fgkSampleMin, min = fgkSampleMax;//Use these for picking the pedestal
341 sample = in->GetSignal(); //Get the adc signal
342 if (sample < min) min = sample;
343 if (sample > max) max = sample;
345 if ( i >= in->GetTimeLength()) {
346 //If we're here then we're done with this tower
347 gain = 1 - in->IsLowGain();
349 int arrayPos = in->GetModule(); //The modules are numbered starting from 0
350 if (arrayPos >= fModules) {
351 //TODO: return an error message, if appopriate (perhaps if debug>0?)
356 if (arrayPos < 0 || arrayPos >= fModules) {
357 printf("Oh no: arrayPos = %i.\n", arrayPos);
360 fNChanFills++; // one more channel found, and profile to be filled
361 //NOTE: coordinates are (column, row) for the profiles
363 //fill the low gain histograms
364 ((TProfile2D*)fPedestalLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), min);
365 ((TProfile2D*)fPeakMinusPedLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
366 ((TProfile2D*)fSampleLowGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), sample);
368 else {//fill the high gain ones
369 ((TProfile2D*)fPedestalHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), min);
370 ((TProfile2D*)fPeakMinusPedHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), max - min);
371 ((TProfile2D*)fSampleHighGain[arrayPos])->Fill(in->GetColumn(), fRowMultiplier*in->GetRow(), sample);
374 max = fgkSampleMin; min = fgkSampleMax;
377 }//End if end of tower
379 }//end while, of stream
384 //_____________________________________________________________________
385 Bool_t AliCaloCalibPedestal::SaveHistograms(TString fileName, Bool_t saveEmptyHistos)
387 //Saves all the histograms (or profiles, to be accurate) to the designated file
389 TFile destFile(fileName, "recreate");
391 if (destFile.IsZombie()) {
397 for (int i = 0; i < fModules; i++) {
398 if( ((TProfile2D *)fPeakMinusPedLowGain[i])->GetEntries() || saveEmptyHistos) {
399 fPeakMinusPedLowGain[i]->Write();
401 if( ((TProfile2D *)fPeakMinusPedHighGain[i])->GetEntries() || saveEmptyHistos) {
402 fPeakMinusPedHighGain[i]->Write();
404 if( ((TProfile2D *)fPedestalLowGain[i])->GetEntries() || saveEmptyHistos) {
405 fPedestalLowGain[i]->Write();
407 if( ((TProfile2D *)fPedestalHighGain[i])->GetEntries() || saveEmptyHistos) {
408 fPedestalHighGain[i]->Write();
410 if( ((TProfile2D *)fSampleLowGain[i])->GetEntries() || saveEmptyHistos) {
411 fSampleLowGain[i]->Write();
413 if( ((TProfile2D *)fSampleHighGain[i])->GetEntries() || saveEmptyHistos) {
414 fSampleHighGain[i]->Write();
423 //_____________________________________________________________________
424 Bool_t AliCaloCalibPedestal::LoadReferenceCalib(TString fileName, TString objectName)
427 //Make sure that the histograms created when loading the object are not destroyed as the file object is destroyed
428 TH1::AddDirectory(kFALSE);
430 TFile *sourceFile = new TFile(fileName);
431 if (sourceFile->IsZombie()) {
432 return kFALSE;//We couldn't load the reference
435 if (fReference) delete fReference;//Delete the reference object, if it already exists
438 fReference = (AliCaloCalibPedestal*)sourceFile->Get(objectName);
440 if (!fReference || !(fReference->InheritsFrom(AliCaloCalibPedestal::Class())) || (fReference->GetDetectorType() != fDetType)) {
441 if (fReference) delete fReference;//Delete the object, in case we had an object of the wrong type
448 //Reset the histogram ownership behaviour. NOTE: a better workaround would be good, since this may accidentally set AddDirectory to true, even
449 //if we are called by someone who has set it to false...
450 TH1::AddDirectory(kTRUE);
452 return kTRUE;//We succesfully loaded the object
455 //_____________________________________________________________________
456 void AliCaloCalibPedestal::ValidateComparisonProfiles()
458 //Make sure the comparison histos exist
459 if (!fPedestalLowGainDiff.IsEmpty()) return; //The profiles already exist. We just check one, because they're all created at
463 //Then, loop for the requested number of modules
465 for (int i = 0; i < fModules; i++) {
466 //Pedestals, low gain
467 name = "hPedlowgainDiff";
469 title = "Pedestals difference, low gain, module ";
471 fPedestalLowGainDiff.Add(new TProfile2D(name, title,
472 fColumns, 0.0, fColumns,
473 fRows, fRowMin, fRowMax,"s"));
475 //Pedestals, high gain
476 name = "hPedhighgainDiff";
478 title = "Pedestals difference, high gain, module ";
480 fPedestalHighGainDiff.Add(new TProfile2D(name, title,
481 fColumns, 0.0, fColumns,
482 fRows, fRowMin, fRowMax,"s"));
484 //Peak-Pedestals, high gain
485 name = "hPeakMinusPedhighgainDiff";
487 title = "Peak-Pedestal difference, high gain, module ";
489 fPeakMinusPedHighGainDiff.Add(new TProfile2D(name, title,
490 fColumns, 0.0, fColumns,
491 fRows, fRowMin, fRowMax,"s"));
493 //Pedestals, low gain
494 name = "hPedlowgainRatio";
496 title = "Pedestals ratio, low gain, module ";
498 fPedestalLowGainRatio.Add(new TProfile2D(name, title,
499 fColumns, 0.0, fColumns,
500 fRows, fRowMin, fRowMax,"s"));
502 //Pedestals, high gain
503 name = "hPedhighgainRatio";
505 title = "Pedestals ratio, high gain, module ";
507 fPedestalHighGainRatio.Add(new TProfile2D(name, title,
508 fColumns, 0.0, fColumns,
509 fRows, fRowMin, fRowMax,"s"));
511 //Peak-Pedestals, low gain
512 name = "hPeakMinusPedlowgainRatio";
514 title = "Peak-Pedestal ratio, low gain, module ";
516 fPeakMinusPedLowGainRatio.Add(new TProfile2D(name, title,
517 fColumns, 0.0, fColumns,
518 fRows, fRowMin, fRowMax,"s"));
520 //Peak-Pedestals, high gain
521 name = "hPeakMinusPedhighgainRatio";
523 title = "Peak-Pedestal ratio, high gain, module ";
525 fPeakMinusPedHighGainRatio.Add(new TProfile2D(name, title,
526 fColumns, 0.0, fColumns,
527 fRows, fRowMin, fRowMax,"s"));
529 }//end for nModules create the histograms
532 //_____________________________________________________________________
533 void AliCaloCalibPedestal::ComputeDiffAndRatio()
535 // calculate differences and ratios relative to a reference
536 ValidateComparisonProfiles();//Make sure the comparison histos exist
539 return;//Return if the reference object isn't loaded
542 for (int i = 0; i < fModules; i++) {
543 //Compute the ratio of the histograms
545 ((TProfile2D*)fPedestalLowGainRatio[i])->Divide(GetPedProfileLowGain(i), fReference->GetPedProfileLowGain(i), 1.0, 1.0);
546 ((TProfile2D*)fPedestalHighGainRatio[i])->Divide(GetPedProfileHighGain(i), fReference->GetPedProfileHighGain(i), 1.0, 1.0);
547 ((TProfile2D*)fPeakMinusPedLowGainRatio[i])->Divide(GetPeakProfileLowGain(i), fReference->GetPeakProfileLowGain(i), 1.0, 1.0);
548 ((TProfile2D*)fPeakMinusPedHighGainRatio[i])->Divide(GetPeakProfileHighGain(i), fReference->GetPeakProfileHighGain(i), 1.0, 1.0);
550 //For computing the difference, we cannot simply do TProfile2D->Add(), because that subtracts the sum of all entries,
551 //which means that the mean of the new profile will not be the difference of the means. So do it by hand:
552 for (int j = 0; j <= fColumns; j++) {
553 for (int k = 0; k <= fRows; k++) {
554 int bin = ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->GetBin(j+1, k+1);//Note that we assume here that all histos have the same structure...
555 double diff = fReference->GetPeakProfileHighGain(i)->GetBinContent(bin) - GetPeakProfileHighGain(i)->GetBinContent(bin);
556 ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinContent(j+1, k+1, diff);
557 ((TProfile2D*)fPeakMinusPedHighGainDiff[i])->SetBinEntries(bin, 1);
559 diff = fReference->GetPeakProfileLowGain(i)->GetBinContent(bin) - GetPeakProfileLowGain(i)->GetBinContent(bin);
560 ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinContent(j+1, k+1, diff);
561 ((TProfile2D*)fPeakMinusPedLowGainDiff[i])->SetBinEntries(bin, 1);
563 diff = fReference->GetPedProfileHighGain(i)->GetBinContent(bin) - GetPedProfileHighGain(i)->GetBinContent(bin);
564 ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinContent(j+1, k+1, diff);
565 ((TProfile2D*)fPedestalHighGainDiff[i])->SetBinEntries(bin, 1);
567 diff = fReference->GetPedProfileLowGain(i)->GetBinContent(bin) - GetPedProfileLowGain(i)->GetBinContent(bin);
568 ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinContent(j+1, k+1, diff);
569 ((TProfile2D*)fPedestalLowGainDiff[i])->SetBinEntries(bin, 1);
578 //_____________________________________________________________________
579 void AliCaloCalibPedestal::ComputeDeadTowers(int threshold, const char * deadMapFile)
581 //Computes the number of dead towers etc etc into memory, after this you can call the GetDead... -functions
587 char name[512];//Quite a long temp buffer, just in case the filename includes a path
590 snprintf(name, 512, "%s.txt", deadMapFile);
591 fout = new ofstream(name);
592 snprintf(name, 512, "%sdiff.txt", deadMapFile);
593 diff = new ofstream(name);
594 if (!fout->is_open()) {
596 fout = 0;//Set the pointer to empty if the file was not opened
598 if (!diff->is_open()) {
600 fout = 0;//Set the pointer to empty if the file was not opened
604 for (int i = 0; i < fModules; i++) {
605 if (GetPeakProfileHighGain(i)->GetEntries() > 0) { //don't care about empty histos
606 for (int j = 1; j <= fColumns; j++) {
607 for (int k = 1; k <= fRows; k++) {
609 if (GetPeakProfileHighGain(i)->GetBinContent(j, k) < threshold) {//It's dead
610 countTot++;//One more dead total
613 << (fRows - k) << " "
616 << "0" << endl;//Write the status to the deadmap file, if the file is open.
619 if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) >= threshold) {
620 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kRecentlyDeceased);
621 countNew++;//This tower wasn't dead before!
624 << (fRows - k) << " "
627 << "0" << endl;//Write the status to the deadmap difference file, if the file is open.
631 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kDead);//This has been dead before. Nothing new
634 else { //It's ALIVE!!
635 //Don't bother with writing the live ones.
637 // (*fout) << i << " "
638 // << (fRows - k) << " "
641 // << "1" << endl;//Write the status to the deadmap file, if the file is open.
642 if (fReference && fReference->GetPeakProfileHighGain(i)->GetBinContent(j, k) < threshold) {
643 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kResurrected);
644 countRes++; //This tower was dead before => it's a miracle! :P
647 << (fRows - k) << " "
650 << "1" << endl;//Write the status to the deadmap difference file, if the file is open.
654 ((TH2D*)fDeadMap[i])->SetBinContent(j, k, kAlive);
660 }//end if GetEntries >= 0
669 fDeadTowers = countTot;
670 fNewDeadTowers = countNew;
671 fResurrectedTowers = countRes;