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 //-----------------------------------------------------------------------------
19 /// \class AliMUONPadStatusMaker
21 /// Make a 2DStore of pad statuses, using different sources of information,
22 /// like pedestal values, gain values, and HV values.
24 /// \author Laurent Aphecetche
25 //-----------------------------------------------------------------------------
27 #include "AliMUONPadStatusMaker.h"
29 #include "AliMUON2DMap.h"
30 #include "AliMUON2DStoreValidator.h"
31 #include "AliMUONCalibParamNI.h"
32 #include "AliMUONCalibrationData.h"
33 #include "AliMUONLogger.h"
34 #include "AliMUONRecoParam.h"
35 #include "AliMUONStringIntMap.h"
36 #include "AliMUONTrackerData.h"
37 #include "AliMUONVCalibParam.h"
39 #include "AliMpArea.h"
40 #include "AliMpArrayI.h"
42 #include "AliMpConstants.h"
43 #include "AliMpDDLStore.h"
44 #include "AliMpDEManager.h"
45 #include "AliMpDetElement.h"
46 #include "AliMpDCSNamer.h"
47 #include "AliMpManuIterator.h"
48 #include "AliMpManuUID.h"
50 #include "AliCDBEntry.h"
51 #include "AliCDBManager.h"
52 #include "AliCodeTimer.h"
53 #include "AliDCSValue.h"
56 #include <Riostream.h>
67 ClassImp(AliMUONPadStatusMaker)
70 //_____________________________________________________________________________
71 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
72 : fkCalibrationData(calibData),
73 fGainA1Limits(0,1E30),
74 fGainA2Limits(-1E-30,1E30),
75 fGainThresLimits(0,4095),
76 fHVSt12Limits(0,5000),
77 fHVSt345Limits(0,5000),
78 fPedMeanLimits(0,4095),
79 fPedSigmaLimits(0,4095),
80 fManuOccupancyLimits(0,1.0),
81 fBuspatchOccupancyLimits(0,1.0),
82 fDEOccupancyLimits(0,1.0),
83 fStatus(new AliMUON2DMap(true)),
85 fPedestals(calibData.Pedestals()),
86 fGains(calibData.Gains()),
90 if ( calibData.OccupancyMap() )
92 /// create a tracker data from the occupancy map
93 fTrackerData = new AliMUONTrackerData("OCC","OCC",*(calibData.OccupancyMap()));
98 //_____________________________________________________________________________
99 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
108 //_____________________________________________________________________________
110 AliMUONPadStatusMaker::AsString(Int_t status)
112 /// return a human readable version of the integer status
119 DecodeStatus(status,pedStatus,hvStatus,gainStatus,occStatus);
123 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
124 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
125 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
126 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
127 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
128 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
130 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
131 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
132 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
133 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
134 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
135 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
136 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
138 if ( hvStatus & kHVError ) s+="& HV is on error ";
139 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
140 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
141 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
142 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
143 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
145 if ( occStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
146 if ( occStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
147 if ( occStatus & kBusPatchOccupancyTooHigh ) s+="& bus patch occupancy too high ";
148 if ( occStatus & kBusPatchOccupancyTooLow ) s+="& bus patch occupancy too low ";
149 if ( occStatus & kDEOccupancyTooHigh ) s+="& DE occupancy too high ";
150 if ( occStatus & kDEOccupancyTooLow ) s+="& DE occupancy too low ";
152 if ( s[0] == '&' ) s[0] = ' ';
157 //_____________________________________________________________________________
159 AliMUONPadStatusMaker::AsCondition(Int_t mask)
161 /// return a human readable version of the mask's equivalent condition
163 TString s(AsString(mask));
165 s.ReplaceAll("&","|");
170 //_____________________________________________________________________________
172 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
177 /// Build a complete status from specific parts (ped,hv,gain)
179 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
180 ( ( gainStatus & 0xFF ) << 16 ) |
181 ( ( occStatus & 0xFF ) << 24 ) ;
184 //_____________________________________________________________________________
186 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
192 /// Decode complete status into specific parts (ped,hv,gain)
194 occStatus = ( status & 0xFF000000 ) >> 24;
195 gainStatus = ( status & 0xFF0000 ) >> 16;
196 pedStatus = ( status & 0xFF00 ) >> 8;
197 hvStatus = (status & 0xFF);
200 //_____________________________________________________________________________
202 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
203 Bool_t& hvChannelTooLow,
204 Bool_t& hvChannelTooHigh,
205 Bool_t& hvChannelON) const
207 /// Get HV status for one HV sector of St12
209 /// For a given PCB in a given DE, get the HV status (both the channel
211 /// Returns false if hv switch changed during the run.
213 AliCodeTimerAuto("",0)
215 Bool_t error = kFALSE;
216 hvChannelTooLow = kFALSE;
217 hvChannelTooHigh = kFALSE;
220 AliMpDCSNamer hvNamer("TRACKER");
222 TString hvChannel(hvNamer.DCSChannelName(detElemId,sector));
224 TMap* hvMap = fkCalibrationData.HV();
225 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
228 AliError(Form("Did not find expected alias (%s) for DE %d",
229 hvChannel.Data(),detElemId));
234 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
237 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
242 // find out min and max value, and makes a cut
248 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
250 Float_t hv = val->GetFloat();
251 hvMin = TMath::Min(hv,hvMin);
252 hvMax = TMath::Max(hv,hvMax);
255 float lowThreshold = fHVSt12Limits.X();
256 float highThreshold = fHVSt12Limits.Y();
258 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
259 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
260 if ( hvMin < 1 ) hvChannelON = kFALSE;
267 //_____________________________________________________________________________
269 AliMUONPadStatusMaker::SwitchValue(const TObjArray& dcsArray)
271 /// Loop over the dcs value for a single switch to decide whether
272 /// we should consider it on or off
274 // we'll count the number of ON/OFF for this pad, to insure
275 // consistency (i.e. if status changed during the run, we should
276 // at least notify this fact ;-) and hope it's not the norm)
279 TIter next(&dcsArray);
282 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
284 if ( val->GetBool() )
294 if ( (nTrue>0 && nFalse>0) )
296 // change of state during the run, consider it off
302 /// switch = FALSE means the HV was flowding up to the PCB.
303 /// i.e. switch = FALSE = ON
310 //_____________________________________________________________________________
312 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
313 Bool_t& hvChannelTooLow,
314 Bool_t& hvChannelTooHigh,
316 Bool_t& hvSwitchON) const
318 /// For a given PCB in a given DE, get the HV status (both the channel
320 /// Returns false if something goes wrong (in particular if
321 /// hv switch changed during the run).
323 AliCodeTimerAuto("",0)
325 Bool_t error = kFALSE;
326 hvChannelTooLow = kFALSE;
327 hvChannelTooHigh = kFALSE;
331 AliMpDCSNamer hvNamer("TRACKER");
333 TString hvChannel(hvNamer.DCSChannelName(detElemId));
335 TMap* hvMap = fkCalibrationData.HV();
337 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
340 AliError(Form("Did not find expected alias (%s) for DE %d",
341 hvChannel.Data(),detElemId));
346 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
349 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
354 // find out min and max value, and makes a cut
360 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
362 Float_t hv = val->GetFloat();
363 hvMin = TMath::Min(hv,hvMin);
364 hvMax = TMath::Max(hv,hvMax);
367 float lowThreshold = fHVSt345Limits.X();
368 float highThreshold = fHVSt345Limits.Y();
370 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
371 else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
372 if ( hvMin < 1 ) hvChannelON = kFALSE;
376 TString hvSwitch(hvNamer.DCSSwitchName(detElemId,pcbIndex));
377 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
380 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
381 hvSwitch.Data(),detElemId,pcbIndex));
386 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
389 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
394 Float_t sv = SwitchValue(*values);
395 if ( sv < 0.99 ) hvSwitchON = kFALSE;
401 //_____________________________________________________________________________
403 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
405 /// Get HV status of one manu
407 AliCodeTimerAuto("",0)
409 if ( !fkCalibrationData.HV() ) return kMissing;
411 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
415 return (Int_t)(lint - 1);
420 AliMpDCSNamer hvNamer("TRACKER");
422 switch ( AliMpDEManager::GetStationType(detElemId) )
424 case AliMp::kStation12:
426 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
429 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
430 Bool_t error = HVSt12Status(detElemId,sector,
434 if ( error ) status |= kHVError;
435 if ( hvChannelTooLow ) status |= kHVTooLow;
436 if ( hvChannelTooHigh ) status |= kHVTooHigh;
437 if ( !hvChannelON ) status |= kHVChannelOFF;
438 // assign this status to all the other manus handled by the same HV channel
439 SetHVStatus(detElemId,sector,status);
443 case AliMp::kStation345:
445 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
448 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
449 Bool_t error = HVSt345Status(detElemId,pcbIndex,
450 hvChannelTooLow,hvChannelTooHigh,
451 hvChannelON,hvSwitchON);
452 if ( error ) status |= kHVError;
453 if ( hvChannelTooLow ) status |= kHVTooLow;
454 if ( hvChannelTooHigh ) status |= kHVTooHigh;
455 if ( !hvSwitchON ) status |= kHVSwitchOFF;
456 if ( !hvChannelON) status |= kHVChannelOFF;
457 // assign this status to all the other manus handled by the same HV channel
458 SetHVStatus(detElemId,pcbIndex,status);
469 //_____________________________________________________________________________
471 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
473 /// Get the neighbours parameters for a given manu
474 AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
475 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
478 //_____________________________________________________________________________
480 AliMUONPadStatusMaker::NeighboursStore() const
482 /// Return the store containing all the neighbours
483 return fkCalibrationData.Neighbours();
486 //_____________________________________________________________________________
488 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
490 /// Compute the status of a given manu, using all available information,
491 /// i.e. pedestals, gains, and HV
493 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
496 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
498 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
500 Int_t hvStatus = HVStatus(detElemId,manuId);
502 Int_t occStatus = OccupancyStatus(detElemId,manuId);
504 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
510 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
511 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
512 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
513 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
514 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
515 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
516 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
520 pedStatus = kPedMissing;
527 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
528 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
529 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
531 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
532 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
533 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
534 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
535 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
536 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
540 gainStatus = kGainMissing;
543 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,occStatus);
545 param->SetValueAsIntFast(manuChannel,0,status);
551 //_____________________________________________________________________________
553 AliMUONPadStatusMaker::OccupancyStatus(Int_t detElemId, Int_t manuId) const
555 /// Get the "other" status for a given manu
561 const Int_t occIndex = 2;
563 Double_t occ = fTrackerData->DetectionElement(detElemId,occIndex);
565 if ( occ <= fDEOccupancyLimits.X() )
567 rv |= kDEOccupancyTooLow;
569 else if ( occ > fDEOccupancyLimits.Y() )
571 rv |= kDEOccupancyTooHigh;
574 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
576 occ = fTrackerData->BusPatch(busPatchId,occIndex);
578 if ( occ <= fBuspatchOccupancyLimits.X() )
580 rv |= kBusPatchOccupancyTooLow;
582 else if ( occ > fBuspatchOccupancyLimits.Y() )
584 rv |= kBusPatchOccupancyTooHigh;
587 occ = fTrackerData->Manu(detElemId,manuId,occIndex);
589 if ( occ <= fManuOccupancyLimits.X() )
591 rv |= kManuOccupancyTooLow;
593 else if ( occ > fManuOccupancyLimits.Y() )
595 rv |= kManuOccupancyTooHigh;
601 //_____________________________________________________________________________
603 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
605 /// Get the status container for a given manu
607 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
610 // not already there, so compute it now
611 AliCodeTimerAuto("ComputeStatus",0);
612 param = ComputeStatus(detElemId,manuId);
617 //_____________________________________________________________________________
619 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
621 /// Get the status for a given channel
623 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
626 // not already there, so compute it now
627 param = ComputeStatus(detElemId,manuId);
629 return param->ValueAsInt(manuChannel,0);
632 //_____________________________________________________________________________
634 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
636 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
637 /// is different thing from St12 and St345)
639 AliCodeTimerAuto("",0)
641 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
643 const AliMpArrayI* manus = de->ManusForHV(index);
645 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
647 Int_t manuId = manus->GetValue(i);
648 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);
652 //_____________________________________________________________________________
654 AliMUONPadStatusMaker::SetLimits(const AliMUONRecoParam& recoParams)
656 /// Set the limits from the recoparam
658 SetHVSt12Limits(recoParams.HVSt12LowLimit(),recoParams.HVSt12HighLimit());
659 SetHVSt345Limits(recoParams.HVSt345LowLimit(),recoParams.HVSt345HighLimit());
661 SetPedMeanLimits(recoParams.PedMeanLowLimit(),recoParams.PedMeanHighLimit());
662 SetPedSigmaLimits(recoParams.PedSigmaLowLimit(),recoParams.PedSigmaHighLimit());
664 SetGainA1Limits(recoParams.GainA1LowLimit(),recoParams.GainA1HighLimit());
665 SetGainA2Limits(recoParams.GainA2LowLimit(),recoParams.GainA2HighLimit());
666 SetGainThresLimits(recoParams.GainThresLowLimit(),recoParams.GainThresHighLimit());
668 SetManuOccupancyLimits(recoParams.ManuOccupancyLowLimit(),recoParams.ManuOccupancyHighLimit());
669 SetBuspatchOccupancyLimits(recoParams.BuspatchOccupancyLowLimit(),recoParams.BuspatchOccupancyHighLimit());
670 SetDEOccupancyLimits(recoParams.DEOccupancyLowLimit(),recoParams.DEOccupancyHighLimit());
673 //_____________________________________________________________________________
675 AliMUONPadStatusMaker::Report(UInt_t mask)
677 /// Report the number of bad pads, according to the mask,
678 /// and the various reasons why they are bad (with occurence rates)
681 AliCodeTimerAuto("",0);
683 AliMUONLogger log(1064008);
688 AliMpManuIterator it;
690 Int_t detElemId, manuId;
692 while ( it.Next(detElemId,manuId) )
694 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
696 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
698 if ( de->IsConnectedChannel(manuId,i) )
702 Int_t status = PadStatus(detElemId,manuId,i);
704 if ( ( status & mask) || (!mask && status) )
707 log.Log(AsString(status));
716 cout << Form("According to mask %x (human readable form below) %6d pads are bad (over a total of %6d, i.e. %7.2f %%)",
717 mask,nBadPads,nPads,nPads ? nBadPads*100.0/nPads : 0.0) << endl;
718 cout << AliMUONPadStatusMaker::AsCondition(mask) << endl;
719 cout << "--------" << endl;
721 while ( log.Next(msg,ntimes) )
723 cout << Form("The message (%120s) occured %15d times (%7.4f %%)",msg.Data(),ntimes,ntimes*100.0/nPads) << endl;