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 **************************************************************************/
18 Revision 1.1 2005/10/11 12:31:50 masera
19 Preprocessor classes for SPD (Paul Nilsson)
23 ///////////////////////////////////////////////////////////////////////////
24 // AliITSPreprocessorSPD implementation by P. Nilsson 2005
25 // MAIN AUTHOR/CONTACT: Paul.Nilsson@cern.ch
27 // The purpose of this class is to provide algorithms for identification
28 // of "bad channels" such as dead channels and noisy channels in the SPD
30 // Examples on how to use this class can be found in the macros:
32 // .findNoisyChannels.C (Locate and store noisy channels in the CDB)
33 // .readNoisyChannels.C (Read noisy channels from the CDB)
34 // .findDeadChannels.C (Locate and store dead channels in the CDB)
35 // .readDeadChannels.C (Read dead channels from the CDB)
36 ///////////////////////////////////////////////////////////////////////////
39 #include "AliITSPreprocessorSPD.h"
40 #include "AliCDBEntry.h"
41 #include "AliITSCalibrationSPD.h"
42 ClassImp(AliITSPreprocessorSPD)
45 //__________________________________________________________________________
46 AliITSPreprocessorSPD::AliITSPreprocessorSPD(void):
51 fMaximumNumberOfEvents(1000000),
52 fHighestModuleNumber(0),
53 fSelectedAlgorithm(kOptimizedForRealData),
54 fGeometryMode(kALICEGeometry),
55 fNumberOfBadChannels(0),
59 fBadChannelsObjArray(0),
60 fBadChannelsIntArray(0),
61 fBadChannelsIndexArray(0),
62 fBadChannelsContainer(0)
64 // Default constructor for the SPD preprocessor
66 // Initialization has to be done by hand using Set* methods and the Open method
70 // Return: <empty/uninitialized AliITSPreprocessorSPD object>
74 //__________________________________________________________________________
75 AliITSPreprocessorSPD::AliITSPreprocessorSPD(const char *fileName, const char *mode,
76 const char *fileNameg, const Int_t maxNumberOfEvents):
81 // Standard constructor for the SPD preprocessor
83 // Input : Name of digit file
85 // Return: Initialized SPD preprocessor object
88 AliITSPreprocessorSPD::Init();
89 AliITSPreprocessorSPD::SetMaximumNumberOfEvents(maxNumberOfEvents);
91 // Open and read the galice and digit files
92 if (!AliITSPreprocessorSPD::Open(fileName, mode, fileNameg))
94 AliError("Failed to open file");
100 //__________________________________________________________________________
101 AliITSPreprocessorSPD::AliITSPreprocessorSPD(const AliITSPreprocessorSPD &prep) :
104 // Default copy constructor
105 // Notice that only pointer addresses are copied!
106 // Memory allocations of new objects are not done.
108 fITSLoader = prep.fITSLoader;
109 fRunLoader = prep.fRunLoader;
110 fThresholdRatio = prep.fThresholdRatio;
111 fThreshold = prep.fThreshold;
112 fMaximumNumberOfEvents = prep.fMaximumNumberOfEvents;
113 fHighestModuleNumber = prep.fHighestModuleNumber;
114 fSelectedAlgorithm = prep.fSelectedAlgorithm;
115 fGeometryMode = prep.fGeometryMode;
116 fNumberOfBadChannels = prep.fNumberOfBadChannels;
118 fVMEMode = prep.fVMEMode;
119 fDigitsHistogram = prep.fDigitsHistogram;
120 fBadChannelsObjArray = prep.fBadChannelsObjArray;
121 fBadChannelsIntArray = prep.fBadChannelsIntArray;
122 fBadChannelsIndexArray = prep.fBadChannelsIndexArray;
123 fBadChannelsContainer = prep.fBadChannelsContainer;
127 //__________________________________________________________________________
128 AliITSPreprocessorSPD& AliITSPreprocessorSPD::operator=(const AliITSPreprocessorSPD &prep)
130 // Assignment operator
132 AliError("Not implemented");
134 if (this != &prep) { } // Do not delete this line
140 //__________________________________________________________________________
141 AliITSPreprocessorSPD::~AliITSPreprocessorSPD(void)
143 // Destructor for the SPD preprocessor
145 if (fDigitsHistogram)
147 // try fDigitsHistogram->Delete(); if the following crashes
148 for (UInt_t module = 0; module < fNumberOfModules; module++)
150 (*fDigitsHistogram)[module]->Delete();
152 delete fDigitsHistogram;
153 fDigitsHistogram = 0;
156 if (fNumberOfBadChannels)
158 delete [] fNumberOfBadChannels;
159 fNumberOfBadChannels = 0;
162 if (fBadChannelsIntArray)
164 delete [] fBadChannelsIntArray;
165 fBadChannelsIntArray = 0;
168 if (fBadChannelsIndexArray)
170 delete [] fBadChannelsIndexArray;
171 fBadChannelsIndexArray = 0;
174 if (fBadChannelsObjArray)
176 fBadChannelsObjArray->Delete();
177 delete fBadChannelsObjArray;
178 fBadChannelsObjArray = 0;
184 delete fBadChannelsContainer;
185 fBadChannelsContainer = 0;
189 //__________________________________________________________________________
190 void AliITSPreprocessorSPD::Init(void)
192 // Initialization of the SPD preprocessor
195 // Output: Several logistical variables
198 // Default maximum number of events per histogram
199 fMaximumNumberOfEvents = 1000000;
201 // Default noisy channel removal algorithm
202 fSelectedAlgorithm = kOptimizedForRealData;
204 // Default noisy channel threshold and threshold ratio
205 // (threshold for current bin content divided by the average neighboring bin contents)
207 fThresholdRatio = 5.;
209 // Set default geometry mode (ALICE geometry). This also sets fNumberOfModules
210 AliITSPreprocessorSPD::SetGeometryMode(kALICEGeometry);
212 // The highest module number with found bad channels
213 fHighestModuleNumber = 0;
215 // Assume input is not from a VME file
218 // Initialization is complete
223 //__________________________________________________________________________
224 void AliITSPreprocessorSPD::SetGeometryMode(UInt_t mode)
226 // Set the geometry mode
228 // Input : Geometry mode (either kTestBeamGeometry or kALICEGeometry)
232 fGeometryMode = mode;
234 // In case of an input VME file, the number of modules has already been fixed.
235 // Do not try to change it
238 if (mode == kALICEGeometry)
240 fNumberOfModules = kNumberOfSPDModules;
242 else if (mode == kTestBeamGeometry)
244 fNumberOfModules = kNumberOfTestBeamSPDModules;
248 AliError("Unknown geometry mode, defaults to ALICE geometry");
249 fNumberOfModules = kNumberOfSPDModules;
255 //__________________________________________________________________________
256 void AliITSPreprocessorSPD::SetFakeNoisyChannel(Int_t module, Int_t column, Int_t row)
258 // Introduce a fake noisy channel in the hit histograms
260 // Input : Module, column and row numbers
261 // Output: Updated hit histograms
264 if ((UInt_t)module < fNumberOfModules)
266 ((TH2F*)(*fDigitsHistogram)[module])->Fill(column, row, 1000000);
270 AliError("No such module number");
275 //__________________________________________________________________________
276 Bool_t AliITSPreprocessorSPD::Open(const char *fileName, const char *mode, const char *fileNameg)
280 // Input : Name and mode of ITS digit file, name of galice file
282 // Return: kTRUE if loaders succeed
284 Bool_t status = kFALSE;
285 Bool_t status0 = kFALSE;
286 Bool_t status1 = kFALSE;
287 Bool_t status2 = kFALSE;
288 Bool_t status3 = kFALSE;
290 // Only proceed if initialization has been done
293 TString m = (TString)mode;
294 if (m == "daq" || m == "DAQ")
296 // Open the data file and get the run loader
297 fRunLoader = AliRunLoader::Open(fileNameg);
300 // Get the gAlice object
301 status0 = AliITSPreprocessorSPD::GetgAlice();
303 // Get the ITS digits
304 if (status0) status1 = AliITSPreprocessorSPD::GetITSDigits(fileName);
306 // Create the test beam object
307 if (status1) status2 = AliITSPreprocessorSPD::CreateGeometryObj();
309 // Fill histograms with DAQ digits
310 if (status2) status3 = AliITSPreprocessorSPD::FillHistograms();
312 status = status0 & status1 & status2 & status3;
316 AliError("Failed to get the run loader");
319 else if (m == "vme" || m == "VME")
321 // Open the VME file that contains histograms with fired channels as read by the stand-alone VME system
322 TFile *vmeFile = TFile::Open(fileName);
324 if (!vmeFile->IsOpen())
326 AliError("Could not open VME input file");
330 // Get the histograms from the VME file that contains all fired channels
331 status0 = AliITSPreprocessorSPD::GetVMEHistograms(vmeFile);
333 // Create the test beam object
334 if (status0) status1 = AliITSPreprocessorSPD::CreateGeometryObj();
337 // This boolean will be used to override any attempts of changing the number of modules by the user
338 // with the SetGeometryMode method. For VME files the number of modules will entirely be determined by
339 // the input VME root file, i.e. by the number of histograms in this file
342 status = status0 & status1;
346 AliError("Unknown filetype - assuming DAQ file");
349 // At this stage, the final number of modules will be known (safe to define arrays)
350 // In case data is read from a VME root file, it will not be known before
353 // Create the arrays for bookkeeping and storing the noisy channels
354 if (!fBadChannelsObjArray)
356 fBadChannelsObjArray = new TObjArray();
358 if (!fBadChannelsIndexArray)
360 // This array will contain the begin and end indices for each module, i.e. where to begin
361 // and stop reading the fBadChannelsObjArray for a certain module.
362 // The last position of the array will contain the end index of the last module
363 fBadChannelsIndexArray = new Int_t[fNumberOfModules + 1];
364 for (UInt_t module = 0; module < fNumberOfModules + 1; module++)
366 fBadChannelsIndexArray[module] = 0;
373 AliError("SPD preprocessor not initialized. Can't load digits");
380 //__________________________________________________________________________
381 Bool_t AliITSPreprocessorSPD::GetgAlice(void)
383 // Get the gAlice object
386 // Output: gAlice object
387 // Return: kTRUE if the gAlice object was found
389 Bool_t status = kTRUE;
392 fRunLoader->LoadgAlice();
393 if (!fRunLoader->GetAliRun())
395 AliError("gAlice not found on file. Aborting.");
403 //__________________________________________________________________________
404 Bool_t AliITSPreprocessorSPD::GetVMEHistograms(TFile *vmeFile)
406 // Get pre-filled digit histograms from input VME file
408 // Input : pointer to VME file
410 // Return: kTRUE if histograms are found on file
412 Bool_t status = kFALSE;
414 // Get the file directory
415 TDirectory *dir = (TDirectory *)vmeFile;
417 // Get the number of keys (histograms in this case corresponding to modules/ladders)
418 fNumberOfModules = dir->GetNkeys();
419 if ((fNumberOfModules > 0) && (fNumberOfModules <= kNumberOfSPDModules))
423 // Create bad channel histograms
424 fDigitsHistogram = new TObjArray(fNumberOfModules);
426 // Create a key iterator
427 TIter nextkey(dir->GetListOfKeys());
430 // Loop over all objects, read them in to memory one by one
432 while ( (key = (TKey *)nextkey()) )
434 (*fDigitsHistogram)[module++] = (TH2F *)key->ReadObj();
437 if (module > fNumberOfModules)
439 AliError("Wrong number of keys in VME file");
447 AliError("Wrong number of histograms in VME file");
452 //__________________________________________________________________________
453 Bool_t AliITSPreprocessorSPD::GetITSDigits(const char *fileName)
455 // Get the ITS digits
457 // Input : name of digits file
458 // Output: fITSLoader object, ITS digits
459 // Return: kTRUE if loader succeed
461 Bool_t status = kTRUE;
463 // Load the gAlice and the header
464 fRunLoader->LoadgAlice();
465 fRunLoader->LoadHeader();
467 // Get the ITS loader
468 fITSLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
471 AliError("ITS loader not found");
476 // Open the digits file
477 fITSLoader->SetDigitsFileName(fileName);
484 //__________________________________________________________________________
485 TClonesArray* AliITSPreprocessorSPD::CreateDigitsArray(void) const
487 // Creation of the digits array
491 // Return: Pointer to the SPD digits array
493 // Create an array for 5 chips with 8192 channels each
494 TClonesArray *digitsArray = new TClonesArray("AliITSdigitSPD", kNumberOfChannels);
500 //__________________________________________________________________________
501 Bool_t AliITSPreprocessorSPD::CreateGeometryObj(void)
503 // Creation of the geometry object
505 // This object is used to get the number of SPD half-staves
508 // Output: fGeometryObj
509 // Return: kTRUE if fGeometryObj has been created
511 Bool_t status = true;
513 // Create geometry object
514 // fGeometryObj = new ...
515 // if (!fGeometryObj) status = kFALSE;
517 // Get SPD parameters
518 // fNumberOfColumns = fGeometryObject->GetNumberOfColumns();
519 // fNumberOfRows = fGeometryObject->GetNumberOfRows();
521 fNumberOfColumns = kNumberOfColumns;
522 fNumberOfRows = kNumberOfRows;
528 //__________________________________________________________________________
529 void AliITSPreprocessorSPD::CreateHistograms(void)
531 // Create the noisy channel histograms
534 // Output: Noisy channel histograms
538 char n[4]; // For storing the module number (maximum module number is 240)
540 // Create noisy channel histograms
541 fDigitsHistogram = new TObjArray(fNumberOfModules);
543 for (UInt_t i = 0; i < fNumberOfModules; i++)
546 moduleName = "module_";
548 moduleName.Append(n);
550 (*fDigitsHistogram)[i] = new TH2F(moduleName,"Digits",
551 fNumberOfColumns,-.5,(1.*fNumberOfColumns - .5),
552 fNumberOfRows,-.5,(1.*fNumberOfRows - .5));
557 //__________________________________________________________________________
558 Bool_t AliITSPreprocessorSPD::FillHistograms(void)
560 // Fill the histograms with digits (hit positions of unclustered hits)
562 // (There is one digit histogram per SPD module, i.e. a half-stave, 10 chips)
564 // Input : No arguments (Empty digit histograms)
565 // Output: Filled digit histograms
566 // Return: kTRUE if histograms are filled with digits, kFALSE otherwise
568 AliInfo("Filling noisy channel histograms");
570 Bool_t status = kTRUE;
571 AliITSdigitSPD *digitSPD = 0;
574 TBranch *digitsSPDBranch;
578 fITSLoader->LoadDigits("read");
580 // Create noisy channel histograms
581 AliITSPreprocessorSPD::CreateHistograms();
583 // Create an empty SPD digits array
584 TClonesArray *digitsArraySPD = AliITSPreprocessorSPD::CreateDigitsArray();
586 // Get number of events
587 UInt_t numberOfEvents = (fRunLoader->TreeE()) ? static_cast<UInt_t>(fRunLoader->TreeE()->GetEntries()) : 0;
589 // Make sure we don't try to analyze more data than there actually is
590 if (numberOfEvents < fMaximumNumberOfEvents)
592 fMaximumNumberOfEvents = numberOfEvents;
595 // Loop over all digits and put them in the corresponding histograms
596 if (numberOfEvents > 0)
598 for (UInt_t event = 0; event < fMaximumNumberOfEvents; event++)
600 // Get the current event
601 fRunLoader->GetEvent(event);
603 // Get the ITS digits tree
604 digitsTree = fITSLoader->TreeD();
606 // Disable all branches except the SPD branch to speed up the reading process
607 digitsTree->SetBranchStatus("ITSDigitsSPD",1);
608 digitsTree->SetBranchStatus("ITSDigitsSDD",0);
609 digitsTree->SetBranchStatus("ITSDigitsSSD",0);
611 // Reset the SPD digits array to make sure it is empty
612 digitsArraySPD->Clear();
614 // Get the SPD digits branch and set the address
615 digitsSPDBranch = digitsTree->GetBranch("ITSDigitsSPD");
617 digitsSPDBranch->SetAddress(&digitsArraySPD);
619 if (event%100 == 0) AliInfo(Form("Event #%d", event));
621 // Loop over all modules
622 UInt_t numberOfDigits = 0;
623 for (UInt_t module = 0; module < fNumberOfModules; module++)
625 // Get event data for current module
626 digitsTree->GetEvent(module);
628 // Get the number of entries
629 numberOfDigits = digitsArraySPD->GetEntries();
631 // Loop over all digits
632 for (UInt_t digit = 0; digit < numberOfDigits; digit++)
634 // Get the current digit
635 digitSPD = (AliITSdigitSPD*) digitsArraySPD->At(digit);
636 row = digitSPD->GetCoord1();
637 column = digitSPD->GetCoord2();
639 // Fill the digits histogram
640 ((TH2F*)(*fDigitsHistogram)[module])->Fill(column, row);
645 } // end numberOfEvents > 0
653 delete digitsArraySPD;
660 //__________________________________________________________________________
661 Bool_t AliITSPreprocessorSPD::FindDeadChannels(void)
663 // Locate dead channels
665 // Input : Filled hit histograms
666 // Output: TObjArray (fBadChannelsObjArray) with all identified dead channels
667 // Return: kTRUE if dead channels have been found
669 Bool_t status = kFALSE;
671 // Proceed only if properly initialized
676 // Initialize counters
677 fNumberOfBadChannels = new Int_t[fNumberOfModules];
678 for (UInt_t module = 0; module < fNumberOfModules; module++)
680 fNumberOfBadChannels[module] = 0;
683 // Loop over all modules (intentional modularization - DCS will occationally want to
684 // look for noisy channels in certain modules, but not all)
685 fIndex = 0; // Global bad channels array counter (must be reset here)
686 for (UInt_t module = 0; module < fNumberOfModules; module++)
688 status |= AliITSPreprocessorSPD::FindDeadChannelsInModule(module);
693 AliError("Dead channels can only be found in data taken with stand-alone VME system");
698 AliError("Not properly initialized");
705 //__________________________________________________________________________
706 Bool_t AliITSPreprocessorSPD::FindDeadChannelsInModule(UInt_t module)
708 // Locate dead channels
709 // This method assumes that the preprocessor is operator in VME mode.
710 // The algorithm is very simple. It assumes that the data was taken in
711 // a mode where all working SPD pixels should respond as being hit.
712 // fThreshold is used as the limit where everything below this value will
713 // be considered as "dead".
715 // Input : Filled hit histograms
716 // Output: TObjArray (fBadChannelsObjArray) with all identified noisy channels
717 // Return: kTRUE if dead channels have been found
719 // Store the index number for this module
720 fBadChannelsIndexArray[module] = fIndex++;
722 UInt_t xBin, numberOfXBins;
723 UInt_t yBin, numberOfYBins;
726 numberOfXBins = ((TH2F*)(*fDigitsHistogram)[module])->GetNbinsX();
727 numberOfYBins = ((TH2F*)(*fDigitsHistogram)[module])->GetNbinsY();
729 // Loop over all bins in this histogram
730 for (xBin = 1; xBin <= numberOfXBins; xBin++)
731 for (yBin = 1; yBin <= numberOfYBins; yBin++)
733 binContent = ((TH2F*)(*fDigitsHistogram)[module])->GetBinContent(xBin, yBin);
735 // Store this channel/bin if outside accepted limits
736 // A channel has to fire MORE times than the fThreshold value, or it will
737 // be considered as "dead"
738 if (binContent <= fThreshold)
740 // Store the dead channel in the array
741 // The channel object will be deleted in the destructor using the TObjArray Delete() method
742 // (The array will assume ownership of the channel object)
743 AliITSChannelSPD *channel = new AliITSChannelSPD((Int_t)(xBin - 1), (Int_t)(yBin - 1));
745 // Store the noisy channel in the array
746 fBadChannelsObjArray->Add(channel);
748 // Keep track of the number of bad channels in this module
749 fNumberOfBadChannels[module]++;
752 // Keep track of the highest module number
753 if (module > fHighestModuleNumber) fHighestModuleNumber = module;
755 //AliInfo(Form("New dead pixel in (m,c,r) = (%d,%d,%d)", module, xBin - 1, yBin - 1));
759 return (fNumberOfBadChannels[module] > 0);
763 //__________________________________________________________________________
764 Bool_t AliITSPreprocessorSPD::FindNoisyChannels(void)
766 // Locate noisy channels by searching through the digit histograms
767 // (There is one digit histogram per SPD module, i.e. a half-stave, 5 chips)
770 // Output: TObjArray (fBadChannelsObjArray) with all identified noisy channels
771 // Return: kTRUE if noisy channels have been found
773 Bool_t status = kFALSE;
775 // Proceed only if properly initialized
778 // (For testing purposes, noisy channels can be inserted here)
779 //SetFakeNoisyChannel(4,10,10);
780 // Initialize counters
781 fNumberOfBadChannels = new Int_t[fNumberOfModules];
782 for (UInt_t module = 0; module < fNumberOfModules; module++)
784 fNumberOfBadChannels[module] = 0;
787 // Scan through all the histogram bins and search for average filling deviations
788 if ((fSelectedAlgorithm == kOptimizedForRealData) || (fSelectedAlgorithm == kOptimizedForRealDataRMS))
790 // Noisy channel algorithm optimized for real data..........................
791 // Histograms can have any shape (both thresholds and quotients are used)
792 // This algorithm can be used to find noisy channels even if the data was
793 // taken with beam. All channels outside accepted limits (set by fThreshold
794 // and fThresholdRatio) will be marked as noisy
796 if (fSelectedAlgorithm == kOptimizedForRealData)
798 AliInfo("Searching for noisy channels (optimized for real data)");
802 AliInfo("Searching for noisy channels (optimized for real data, RMS version)");
805 // Loop over all modules (intentional modularization - DCS will occationally want to
806 // look for noisy channels in certain modules, but not all)
807 fIndex = 0; // Global bad channels array counter (must be reset here)
808 for (UInt_t module = 0; module < fNumberOfModules; module++)
810 status |= AliITSPreprocessorSPD::FindNoisyChannelsInModuleAlgo0(module);
815 // Noisy channel algorithm optimized for calibration data...........................
816 // Histograms will/should only contain noisy channels (only thresholds are used)
817 // Calibration histograms should have no background. The calibration data
818 // should have been taken without beam. All channels outside accepted limits
819 // (set by fThreshold) will be marked as noisy
821 AliInfo("Searching for noisy channels (optimized for calibration data)");
823 // Loop over all modules (intentional modularization - DCS will occationally want to
824 // look for noisy channels in certain modules, but not all)
825 fIndex = 0; // Global bad channels array counter (must be reset here)
826 for (UInt_t module = 0; module < fNumberOfModules; module++)
828 status |= AliITSPreprocessorSPD::FindNoisyChannelsInModuleAlgo1(module);
834 AliError("Not properly initialized");
841 //__________________________________________________________________________
842 Bool_t AliITSPreprocessorSPD::FindNoisyChannelsInModuleAlgo0(UInt_t module)
844 // Locate the noisy channels in a module (optimized for real data)
846 // For each channel in these histograms, the algorithm checks the average
847 // filling of the neighboring 3, 5 or 8 channels (depending on the location
848 // of the channel in question; corner, border or inside), or compares with the
849 // RMS of the neighbors. If the average is "much" lower, the channel will be
850 // considered to be noisy. The default noisy-to-normal fraction is stored in the
851 // fThresholdRatio varible. It can be set with the SetThresholdRatio method.
852 // The channel also has to have fired more than a certain minimum, fThreshold.
853 // It can be set with the SetThreshold method.
855 // To avoid difficulties with noisy channels that occur in pairs, the
856 // neighboring channel with largest number of fillings will be removed from
857 // the average calculation.
859 // NOTE: Since this method modifies the fBadChannelsObjArray and fBadChannelsIndexArray
860 // it is essential to initialize the fIndex counter before calling this module
861 // the first time. The bad channel data does not have to be ordered per module
862 // in the fBadChannelsObjArray, but the indices of where the data of a certain module
863 // starts has to be correct. A wrong fIndex can lead to segmentation violation
865 // Input : module number, filled digit histograms
866 // Output: TObjArray (fBadChannelsObjArray) with all identified noisy channels,
867 // Int_t[] (fBadChannelsIndexArray) with fBadChannelsObjArray module indices,
868 // number of noisy channels in this module (global variable fNumberOfBadChannels[module])
869 // Return: kTRUE if there are noisy channels in this module
871 // Store the index number for this module
872 fBadChannelsIndexArray[module] = fIndex++;
874 UInt_t xBin, numberOfXBins;
875 UInt_t yBin, numberOfYBins;
878 UInt_t numberOfNeighboringBins;
880 Float_t sumBinContent;
881 Float_t neighborBinContent;
882 Float_t maxBinContent;
883 Float_t averageBinContent;
886 numberOfXBins = (UInt_t)((TH2F*)(*fDigitsHistogram)[module])->GetNbinsX();
887 numberOfYBins = (UInt_t)((TH2F*)(*fDigitsHistogram)[module])->GetNbinsY();
889 // Loop over all bins in this histogram
890 for (xBin = 1; xBin <= numberOfXBins; xBin++)
891 for (yBin = 1; yBin <= numberOfYBins; yBin++)
893 numberOfNeighboringBins = 0;
894 averageBinContent = 0.;
896 binContent = ((TH2F*)(*fDigitsHistogram)[module])->GetBinContent(xBin, yBin);
899 // Calculate the average pixel level on the surrounding pixels
900 for (neighborXBin = xBin - 1; neighborXBin <= xBin + 1; neighborXBin++)
901 for (neighborYBin = yBin - 1; neighborYBin <= yBin + 1; neighborYBin++)
903 if ( !((neighborXBin == xBin) && (neighborYBin == yBin)) )
905 // Only update the number of neighboring bins when we are not on the border
906 if ((neighborXBin > 0) && (neighborXBin <= numberOfXBins+1) &&
907 (neighborYBin > 0) && (neighborYBin <= numberOfYBins+1))
910 ((TH2F*)(*fDigitsHistogram)[module])->GetBinContent(neighborXBin, neighborYBin);
912 if (fSelectedAlgorithm == kOptimizedForRealDataRMS)
915 sumBinContent += neighborBinContent*neighborBinContent;
920 sumBinContent += neighborBinContent;
923 if (neighborBinContent > maxBinContent) maxBinContent = neighborBinContent;
925 numberOfNeighboringBins++;
930 // Calculate the average. Remove the largest neighboring bin
931 // (Correction for potential clusters of noisy channels)
932 if (fSelectedAlgorithm == kOptimizedForRealDataRMS)
934 // Square the max bin content before removing it from the average calculation
935 maxBinContent *= maxBinContent;
937 averageBinContent = TMath::Sqrt((sumBinContent - maxBinContent)/(Float_t)(numberOfNeighboringBins - 1));
942 averageBinContent = (sumBinContent - maxBinContent)/(Float_t)(numberOfNeighboringBins - 1);
945 // Store this channel/bin if outside accepted limits
946 // The threshold ratio is the threshold for the current bin content divided by the
947 // average neighboring bin contents. The threshold bin content is the minimum number of
948 // times a channel has to have fired to be called noisy
949 ratio = (averageBinContent > 0) ? binContent/averageBinContent : 0.;
950 if ( ((ratio >= fThresholdRatio) || (ratio == 0.)) && (binContent >= fThreshold) )
952 // Store the noisy channel in the array
953 // The channel object will be deleted in the destructor using the TObjArray Delete() method
954 // (The array will assume ownership of the channel object)
955 AliITSChannelSPD *channel = new AliITSChannelSPD((Int_t)(xBin - 1), (Int_t)(yBin - 1));
957 // Store the noisy channel in the array
958 fBadChannelsObjArray->Add(channel);
960 // Keep track of the number of bad channels in this module
961 fNumberOfBadChannels[module]++;
964 // Keep track of the highest module number
965 if (module > fHighestModuleNumber) fHighestModuleNumber = module;
967 AliInfo(Form("New noisy pixel in (m,c,r) = (%d,%d,%d)", module, xBin - 1, yBin - 1));
968 AliInfo(Form("- Noisy pixel fired %d times, average neighborhood: %f",(Int_t)binContent,averageBinContent));
972 return (fNumberOfBadChannels[module] > 0);
976 //__________________________________________________________________________
977 Bool_t AliITSPreprocessorSPD::FindNoisyChannelsInModuleAlgo1(UInt_t module)
979 // Locate the noisy channels in a module (optimized for calibration data)
981 // This algorithm locates noisy channels by assuming original data was taken
982 // in calibration mode. This should be done without beam and will thus only
983 // contain data corresponding to background and noisy channels. The latter
984 // should be clearly visible in this data so this algorithm simply assumes
985 // that all histogram bins that are filled more than fThreshold times are
988 // NOTE: Since this method modifies the fBadChannelsObjArray and fBadChannelsIndexArray
989 // it is essential to initialize the fIndex counter before calling this module
990 // the first time. The bad channel data does not have to be ordered per module
991 // in the fBadChannelsObjArray, but the indices of where the data of a certain module
992 // starts has to be correct. A wrong fIndex can lead to segmentation violation
994 // Input : module number, filled digit histograms
995 // Output: TObjArray (fBadChannelsObjArray) with all identified noisy channels,
996 // Int_t[] (fBadChannelsIndexArray) with fBadChannelsObjArray module indices,
997 // number of noisy channels in this module (global variable fNumberOfBadChannels[module])
998 // Return: kTRUE if there are noisy channels in this module
1000 // Store the index number for this module
1001 fBadChannelsIndexArray[module] = fIndex++;
1003 UInt_t xBin, numberOfXBins;
1004 UInt_t yBin, numberOfYBins;
1007 numberOfXBins = ((TH2F*)(*fDigitsHistogram)[module])->GetNbinsX();
1008 numberOfYBins = ((TH2F*)(*fDigitsHistogram)[module])->GetNbinsY();
1010 // Loop over all bins in this histogram
1011 for (xBin = 1; xBin <= numberOfXBins; xBin++)
1012 for (yBin = 1; yBin <= numberOfYBins; yBin++)
1014 binContent = ((TH2F*)(*fDigitsHistogram)[module])->GetBinContent(xBin, yBin);
1016 // Store this channel/bin if outside accepted limits
1017 // The threshold bin content is the minimum number of times a channel has to have
1018 // fired to be called noisy
1019 if (binContent >= fThreshold)
1021 // Store the noisy channel in the array
1022 // The channel object will be deleted in the destructor using the TObjArray Delete() method
1023 // (The array will assume ownership of the channel object)
1024 AliITSChannelSPD *channel = new AliITSChannelSPD((Int_t)(xBin - 1), (Int_t)(yBin - 1));
1026 // Store the noisy channel in the array
1027 fBadChannelsObjArray->Add(channel);
1029 // Keep track of the number of bad channels in this module
1030 fNumberOfBadChannels[module]++;
1033 // Keep track of the highest module number
1034 if (module > fHighestModuleNumber) fHighestModuleNumber = module;
1036 AliInfo(Form("New noisy pixel in (m,c,r) = (%d,%d,%d)", module, xBin - 1, yBin - 1));
1037 AliInfo(Form("- Noisy pixel fired %d times",(Int_t)binContent));
1041 return (fNumberOfBadChannels[module] > 0);
1045 //__________________________________________________________________________
1046 void AliITSPreprocessorSPD::PrintChannels(void)
1048 // Print all found bad channels to stdout
1050 // Input : fBadChannelsObjArray
1051 // Output: (dump to stdout)
1056 AliITSChannelSPD *channel = 0;
1058 // Print the bad channels stores in the array
1059 AliInfo("\nModule #\tColumn #\tRow #\n------------------------------------------------");
1060 for (UInt_t module = 0; module < fNumberOfModules; module++)
1063 while (j < fNumberOfBadChannels[module])
1065 channel = (AliITSChannelSPD *) fBadChannelsObjArray->At(i++);
1066 std::cout << module << "\t\t" << channel->GetColumn() << "\t\t" << channel->GetRow() << std::endl;
1068 // Go to next bad channel
1073 AliInfo(Form("%d bad channels were found", fBadChannelsObjArray->GetEntries()));
1077 //__________________________________________________________________________
1078 void AliITSPreprocessorSPD::MarkNoisyChannels(void)
1080 // WARNING: THIS METHOD DOESN'T WORK!!!
1082 // Mark all identified noisy channels
1084 // Input : List of noisy channels, original digits tree
1085 // Output: New digits tree containing SPD digits marked when noisy
1088 // The original digits tree (digitsTree) is cloned except for the SPD branch (ITSDigitSPD).
1089 // This branch is then redefined for each event and will contain all the original
1090 // information. All known noisy channels will be marked by using the TObject status bits
1091 // according to the following scheme. Dead channels are included for completeness. Note
1092 // that a dead channel will NEVER show up among digits..
1094 // Interpretation of digit status bits (LSB):
1095 // Dead channel Noisy channel | Integer
1096 // -----------------------------------------
1101 // meaning e.g. that a channel that is noisy will have the first bit set in its status bits
1103 // Do not continue unless we are processing DAQ data
1106 AliInfo("Marking bad channels");
1108 // Create the storage container that will be used to access the bad channels
1109 if (!fBadChannelsContainer)
1111 // Add the bad channels array to the storage container
1112 // (ownership is passed to the AliRunDataStorage object)
1113 fBadChannelsContainer = new AliITSBadChannelsSPD();
1115 // Convert the bad channels from TObjArray to Int_t[]
1116 AliITSPreprocessorSPD::ConvertObjToIntArray();
1118 // Store the arrays in the bad channels container object
1119 const Int_t kBadChannelsArraySize =
1120 2*fBadChannelsObjArray->GetEntries() + fNumberOfModules;
1121 fBadChannelsContainer->Put(fBadChannelsIntArray, kBadChannelsArraySize,
1122 fBadChannelsIndexArray, fNumberOfModules);
1125 // Create the bad channels helper object
1126 // (will be used to find a bad channel within a TObjArray)
1127 AliITSBadChannelsAuxSPD *aux = new AliITSBadChannelsAuxSPD();
1129 AliITSdigitSPD *digitSPD = 0;
1130 UInt_t numberOfDigits;
1132 Bool_t mark = kFALSE;
1134 TBranch *digitsBranch = 0;
1137 // Create an empty SPD digit array
1138 TObjArray *digitsArraySPD = new TObjArray();
1140 // Get the digits in update mode (we want to modify them if there are noisy channels)
1141 fITSLoader->UnloadDigits();
1142 fITSLoader->LoadDigits("update");
1144 // Get the number of events
1145 UInt_t numberOfEvents = (fRunLoader->TreeE()) ? static_cast<UInt_t>(fRunLoader->TreeE()->GetEntries()) : 0;
1147 // Loop over all events
1148 for (UInt_t event = 0; event < numberOfEvents; event++)
1150 if (event%100 == 0) AliInfo(Form("Event #%d", event));
1152 // Get the current event
1153 fRunLoader->GetEvent(event);
1155 // Get the ITS digits tree
1156 digitsTree = fITSLoader->TreeD();
1158 // Get SPD branch that will contain all digits with marked noisy channels
1159 digitsBranch = digitsTree->GetBranch("ITSDigitsSPD");
1160 digitsBranch->SetAddress(&digitsArraySPD);
1162 // Get the stored number of modules
1163 UInt_t numberOfModules = (Int_t)digitsTree->GetEntries();
1164 TObjArray **newDigitsArraySPD = new TObjArray*[numberOfModules];
1166 Int_t *digitNumber = new Int_t[numberOfModules];
1167 for (UInt_t m = 0; m < numberOfModules; m++)
1169 newDigitsArraySPD[m] = new TObjArray();
1173 AliInfo(Form("ent = %d", (Int_t)digitsTree->GetEntries()));
1175 // Reset the SPD digit arrays to make sure they are empty
1176 digitsArraySPD->Clear();
1178 // Get the SPD digits branch from the original digits tree and set the address
1179 digitsBranch = digitsTree->GetBranch("ITSDigitsSPD");
1180 digitsBranch->SetAddress(&digitsArraySPD);
1182 // Loop over all modules
1183 for (UInt_t module = 0; module < fNumberOfModules; module++)
1185 // Get event data for current module
1186 digitsTree->GetEvent(module);
1188 // Get the hits in the current module
1189 TObjArray *moduleObjArray = fBadChannelsContainer->CreateModuleObjArray(module);
1191 // Get the number of entries
1192 numberOfDigits = digitsArraySPD->GetEntries();
1194 // Loop over all digits and all channels
1195 for (UInt_t digit = 0; digit < numberOfDigits; digit++)
1197 // Get the current digit
1198 digitSPD = (AliITSdigitSPD*) digitsArraySPD->At(digit);
1199 newDigit[0] = digitSPD->GetCoord1(); // row
1200 newDigit[1] = digitSPD->GetCoord2(); // column
1201 newDigit[2] = digitSPD->GetSignal(); // signal
1203 // Check if this channel is noisy
1204 // (Compare with all stored channels in the bad channels array)
1205 if (aux->Find(digitSPD, moduleObjArray))
1207 // Set the mark flag and break the loop
1211 // Store this digit in the SPD digits array using a placement new operation
1212 new ((*newDigitsArraySPD[module])[digitNumber[module]]) AliITSdigitSPD(newDigit);
1214 // Mark it if noisy and store in the noisy channel array
1217 // Store this digit in the marked SPD digits array using a placement new operation
1218 //new ((*badChannels[m])[numberOfBadChannels[m]]) AliITSChannelSPD(newBadChannel);
1219 //new ((*newDigitsArraySPD[module])[digitNumber[module]]) AliITSdigitSPD(newDigit);
1221 // Mark the original channel as noisy
1222 ((*newDigitsArraySPD[module])[digitNumber[module]])->SetBit(kNoisyChannel);
1227 digitNumber[module]++;
1232 delete moduleObjArray;
1235 } // end module loop
1237 digitsBranch->Reset();
1238 digitsBranch->ResetAddress();
1241 delete digitsArraySPD;
1243 digitsTree->Reset();
1245 // WHY THIS RANGE?????????????????????????????????????????????????????????????????????
1246 for (UInt_t n = 0; n < event; n++)
1248 digitsTree->SetBranchAddress("ITSDigitsSPD", &newDigitsArraySPD[n]);
1252 digitsTree->AutoSave();
1255 for (UInt_t n = 0; n < event; n++)
1257 delete newDigitsArraySPD[n];
1259 delete [] newDigitsArraySPD;
1260 newDigitsArraySPD = 0;
1261 delete [] digitNumber;
1266 } // end loop over all events
1268 // Unload the digits
1269 fITSLoader->UnloadDigits();
1279 //__________________________________________________________________________
1280 Bool_t AliITSPreprocessorSPD::Store(AliCDBId &id, AliCDBMetaData *md)
1282 // Store the bad channels object in the calibration database
1283 // (See the corresponding run macro for further explanations)
1285 // Input : fBadChannelsObjArray (now containing all found bad channels), object meta data
1286 // Output: Database file containing the bad channels
1287 // Return: kTRUE if successful
1289 Bool_t status = kFALSE;
1291 AliInfo("Storing bad channels");
1293 // Add the bad channels array to the storage container
1294 // (ownership is passed to the AliRunDataStorage object)
1295 fBadChannelsContainer = new AliITSBadChannelsSPD();
1297 // Convert the bad channels from TObjArray to Int_t[]
1298 AliITSPreprocessorSPD::ConvertObjToIntArray();
1300 // Store the arrays in the bad channels container object
1301 const Int_t kBadChannelsArraySize =
1302 2*fBadChannelsObjArray->GetEntries() + fNumberOfModules;
1303 fBadChannelsContainer->Put(fBadChannelsIntArray, kBadChannelsArraySize,
1304 fBadChannelsIndexArray, fNumberOfModules);
1306 // Store the container
1307 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
1308 //AliError("No storage set!");
1310 AliCDBManager::Instance()->SetDefaultStorage("local://Calib");
1313 if (AliCDBManager::Instance()->GetDefaultStorage()->Put(fBadChannelsContainer, id, md))
1315 AliInfo("Bad channels object stored in database");
1320 AliError("Failed to store object in database");
1327 //__________________________________________________________________________
1328 void AliITSPreprocessorSPD::ConvertObjToIntArray()
1330 // Convert the bad channel TObjArray to an Int_t array
1332 // Input : fBadChannelsObjArray (now containing all found bad channels)
1333 // Output: fBadChannelsIntArray
1337 // The TObjArray of this class (fBadChannelsObjArray) is converted to a sequential
1338 // Int_t array (fBadChannelsIntArray) in this method. For each module, the first
1339 // stored number is the number of bad channels in the current module. This is
1340 // followed by all the columns and rows of the bad channels:
1342 // badChannelsArray =
1343 // | N(m) | col0 | row0 | .. | colN(m) | N(m+1) | col0 | row0 | ...
1344 // . .......... module m ......... . .... module m+1 ......
1346 // The bad channels index array (fBadChannelsIndexArray) contains the indices of
1347 // the badChannelsArray, i.e. where the bad channels in certain module starts:
1349 // fBadChannelsObjArray =
1350 // | i0 | i1 | .. | iM | (where M = the number of SPD modules)
1352 // e.g. i1 corresponds to the index of the badChannelsArray where N(1) is stored,
1353 // i.e. the number of bad channels for module 1
1355 const Int_t kBadChannelsArraySize =
1356 2*fBadChannelsObjArray->GetEntries() + fNumberOfModules;
1357 fBadChannelsIntArray = new Int_t[kBadChannelsArraySize]; // Will be deleted in dtor
1358 AliITSChannelSPD *channel = 0;
1363 // Loop over all modules
1364 for (UInt_t module = 0; module < fNumberOfModules; module++)
1366 // Encode the number of bad channels of the current module
1367 fBadChannelsIntArray[k++] = fNumberOfBadChannels[module];
1369 // The columns and rows of the fBadChannelsObjArray will be stored sequentially
1370 // in the Int_t array
1372 while (j < fNumberOfBadChannels[module])
1374 channel = (AliITSChannelSPD *) fBadChannelsObjArray->At(i++);
1375 fBadChannelsIntArray[k++] = channel->GetColumn();
1376 fBadChannelsIntArray[k++] = channel->GetRow();
1378 // Go to next bad channel
1385 //__________________________________________________________________________
1386 Bool_t AliITSPreprocessorSPD::Store(AliCDBId& /*id*/, AliCDBMetaData* /*md*/, Int_t runNumber)
1388 // Store the bad channels object in the calibration database
1389 // (See the corresponding run macro for further explanations)
1391 // Input : fBadChannelsObjArray (now containing all found bad channels), object meta data
1392 // Output: Database file containing the bad channels
1393 // Return: kTRUE if successful
1395 Bool_t status = kFALSE;
1397 AliInfo("Storing bad channels");
1399 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
1400 AliWarning("No storage set! Will use dummy one");
1401 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
1405 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSPD", runNumber);
1407 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
1408 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
1409 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
1411 entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSPD", runNumber);
1412 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
1415 TObjArray *respSPD = (TObjArray *)entrySPD->GetObject();
1418 AliWarning("Can not get calibration from calibration database !");
1423 AliITSChannelSPD *channel = 0;
1424 AliITSCalibrationSPD* res;
1425 for (Int_t module=0; module<respSPD->GetEntries(); module++) {
1427 res = (AliITSCalibrationSPD*) respSPD->At(module);
1428 res->SetNBadChannels(fNumberOfBadChannels[module]*2+1);
1429 res->AddBadChannel(fNumberOfBadChannels[module],k++);
1431 while (j < fNumberOfBadChannels[module])
1433 channel = (AliITSChannelSPD *) fBadChannelsObjArray->At(i++);
1434 res->AddBadChannel(channel->GetColumn(),k++);
1435 res->AddBadChannel(channel->GetRow(),k++);
1437 // Go to next bad channel
1444 AliCDBManager::Instance()->Put(entrySPD);
1445 entrySPD->SetObject(NULL);
1446 entrySPD->SetOwner(kTRUE);