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 fPedMeanLimits(0,4095),
77 fPedSigmaLimits(0,4095),
78 fManuOccupancyLimits(0,1.0),
79 fBuspatchOccupancyLimits(0,1.0),
80 fDEOccupancyLimits(0,1.0),
81 fStatus(new AliMUON2DMap(true)),
83 fPedestals(calibData.Pedestals()),
84 fGains(calibData.Gains()),
88 if ( calibData.OccupancyMap() )
90 /// create a tracker data from the occupancy map
91 fTrackerData = new AliMUONTrackerData("OCC","OCC",*(calibData.OccupancyMap()));
95 /// Only create the fHV internal store if there are some HV values available
102 //_____________________________________________________________________________
103 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
112 //_____________________________________________________________________________
114 AliMUONPadStatusMaker::AsString(Int_t status)
116 /// return a human readable version of the integer status
120 return "Brave New World";
128 DecodeStatus(status,pedStatus,hvStatus,gainStatus,occStatus);
132 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
133 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
134 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
135 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
136 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
137 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
139 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
140 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
141 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
142 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
143 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
144 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
145 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
147 if ( hvStatus & kHVError ) s+="& HV is on error ";
148 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
149 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
150 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
151 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
152 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
154 if ( occStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
155 if ( occStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
156 if ( occStatus & kBusPatchOccupancyTooHigh ) s+="& bus patch occupancy too high ";
157 if ( occStatus & kBusPatchOccupancyTooLow ) s+="& bus patch occupancy too low ";
158 if ( occStatus & kDEOccupancyTooHigh ) s+="& DE occupancy too high ";
159 if ( occStatus & kDEOccupancyTooLow ) s+="& DE occupancy too low ";
161 if ( s[0] == '&' ) s[0] = ' ';
166 //_____________________________________________________________________________
168 AliMUONPadStatusMaker::AsCondition(Int_t mask)
170 /// return a human readable version of the mask's equivalent condition
172 TString s(AsString(mask));
174 s.ReplaceAll("&","|");
179 //_____________________________________________________________________________
181 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
186 /// Build a complete status from specific parts (ped,hv,gain)
188 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
189 ( ( gainStatus & 0xFF ) << 16 ) |
190 ( ( occStatus & 0xFF ) << 24 ) ;
193 //_____________________________________________________________________________
195 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
201 /// Decode complete status into specific parts (ped,hv,gain)
203 occStatus = ( status & 0xFF000000 ) >> 24;
204 gainStatus = ( status & 0xFF0000 ) >> 16;
205 pedStatus = ( status & 0xFF00 ) >> 8;
206 hvStatus = (status & 0xFF);
209 //_____________________________________________________________________________
211 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
212 Bool_t& hvChannelTooLow,
213 Bool_t& hvChannelTooHigh,
214 Bool_t& hvChannelON) const
216 /// Get HV status for one HV sector of St12
218 /// For a given PCB in a given DE, get the HV status (both the channel
220 /// Returns false if hv switch changed during the run.
222 AliCodeTimerAuto("",0)
224 if (!fHV) return kFALSE;
226 Bool_t error = kFALSE;
227 hvChannelTooLow = kFALSE;
228 hvChannelTooHigh = kFALSE;
231 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
233 AliMpDCSNamer hvNamer("TRACKER");
235 TString hvChannel(hvNamer.DCSChannelName(detElemId,sector));
237 TMap* hvMap = fkCalibrationData.HV();
238 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
241 AliError(Form("Did not find expected alias (%s) for DE %d",
242 hvChannel.Data(),detElemId));
247 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
250 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
255 // find out min value, and makes a cut
260 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
262 Float_t hv = val->GetFloat();
263 hvMin = TMath::Min(hv,hvMin);
266 float lowThreshold = HVLimit(chamberId);
268 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
269 if ( hvMin < hvNamer.TrackerHVOFF() ) hvChannelON = kFALSE;
276 //_____________________________________________________________________________
278 AliMUONPadStatusMaker::SwitchValue(const TObjArray& dcsArray)
280 /// Loop over the dcs value for a single switch to decide whether
281 /// we should consider it on or off
283 // we'll count the number of ON/OFF for this pad, to insure
284 // consistency (i.e. if status changed during the run, we should
285 // at least notify this fact ;-) and hope it's not the norm)
288 TIter next(&dcsArray);
291 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
293 if ( val->GetBool() )
303 if ( (nTrue>0 && nFalse>0) )
305 // change of state during the run, consider it off
311 /// switch = FALSE means the HV was flowding up to the PCB.
312 /// i.e. switch = FALSE = ON
319 //_____________________________________________________________________________
321 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
322 Bool_t& hvChannelTooLow,
323 Bool_t& hvChannelTooHigh,
325 Bool_t& hvSwitchON) const
327 /// For a given PCB in a given DE, get the HV status (both the channel
329 /// Returns false if something goes wrong (in particular if
330 /// hv switch changed during the run).
332 AliCodeTimerAuto("",0)
334 if (!fHV) return kFALSE;
336 Bool_t error = kFALSE;
337 hvChannelTooLow = kFALSE;
338 hvChannelTooHigh = kFALSE;
342 AliMpDCSNamer hvNamer("TRACKER");
344 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
346 TString hvChannel(hvNamer.DCSChannelName(detElemId));
348 TMap* hvMap = fkCalibrationData.HV();
350 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
353 AliError(Form("Did not find expected alias (%s) for DE %d",
354 hvChannel.Data(),detElemId));
359 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
362 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
367 // find out min value, and makes a cut
372 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
374 Float_t hv = val->GetFloat();
375 hvMin = TMath::Min(hv,hvMin);
378 float lowThreshold = HVLimit(chamberId);
380 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
381 if ( hvMin < hvNamer.TrackerHVOFF() ) hvChannelON = kFALSE;
385 TString hvSwitch(hvNamer.DCSSwitchName(detElemId,pcbIndex));
386 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
389 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
390 hvSwitch.Data(),detElemId,pcbIndex));
395 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
398 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
403 Float_t sv = SwitchValue(*values);
404 if ( sv < 0.99 ) hvSwitchON = kFALSE;
410 //_____________________________________________________________________________
412 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
414 /// Get HV status of one manu
416 AliCodeTimerAuto("",0)
418 if ( !fHV ) return kMissing;
420 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
424 return (Int_t)(lint - 1);
429 AliMpDCSNamer hvNamer("TRACKER");
431 switch ( AliMpDEManager::GetStationType(detElemId) )
433 case AliMp::kStation12:
435 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
438 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
439 Bool_t error = HVSt12Status(detElemId,sector,
443 if ( error ) status |= kHVError;
444 if ( hvChannelTooLow ) status |= kHVTooLow;
445 if ( hvChannelTooHigh ) status |= kHVTooHigh;
446 if ( !hvChannelON ) status |= kHVChannelOFF;
447 // assign this status to all the other manus handled by the same HV channel
448 SetHVStatus(detElemId,sector,status);
452 case AliMp::kStation345:
454 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
457 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
458 Bool_t error = HVSt345Status(detElemId,pcbIndex,
459 hvChannelTooLow,hvChannelTooHigh,
460 hvChannelON,hvSwitchON);
461 if ( error ) status |= kHVError;
462 if ( hvChannelTooLow ) status |= kHVTooLow;
463 if ( hvChannelTooHigh ) status |= kHVTooHigh;
464 if ( !hvSwitchON ) status |= kHVSwitchOFF;
465 if ( !hvChannelON) status |= kHVChannelOFF;
466 // assign this status to all the other manus handled by the same HV channel
467 SetHVStatus(detElemId,pcbIndex,status);
478 //_____________________________________________________________________________
480 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
482 /// Get the neighbours parameters for a given manu
483 AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
484 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
487 //_____________________________________________________________________________
489 AliMUONPadStatusMaker::NeighboursStore() const
491 /// Return the store containing all the neighbours
492 return fkCalibrationData.Neighbours();
495 //_____________________________________________________________________________
497 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
499 /// Compute the status of a given manu, using all available information,
500 /// i.e. pedestals, gains, and HV
502 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
505 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
507 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
509 Int_t hvStatus = HVStatus(detElemId,manuId);
511 Int_t occStatus = OccupancyStatus(detElemId,manuId);
513 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
519 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
520 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
521 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
522 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
523 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
524 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
525 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
529 pedStatus = kPedMissing;
536 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
537 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
538 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
540 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
541 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
542 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
543 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
544 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
545 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
549 gainStatus = kGainMissing;
552 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,occStatus);
554 param->SetValueAsIntFast(manuChannel,0,status);
560 //_____________________________________________________________________________
562 AliMUONPadStatusMaker::OccupancyStatus(Int_t detElemId, Int_t manuId) const
564 /// Get the "other" status for a given manu
570 const Int_t occIndex = 2;
572 Double_t occ = fTrackerData->DetectionElement(detElemId,occIndex);
574 if ( occ <= fDEOccupancyLimits.X() )
576 rv |= kDEOccupancyTooLow;
578 else if ( occ > fDEOccupancyLimits.Y() )
580 rv |= kDEOccupancyTooHigh;
583 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
585 occ = fTrackerData->BusPatch(busPatchId,occIndex);
587 if ( occ <= fBuspatchOccupancyLimits.X() )
589 rv |= kBusPatchOccupancyTooLow;
591 else if ( occ > fBuspatchOccupancyLimits.Y() )
593 rv |= kBusPatchOccupancyTooHigh;
596 occ = fTrackerData->Manu(detElemId,manuId,occIndex);
598 if ( occ <= fManuOccupancyLimits.X() )
600 rv |= kManuOccupancyTooLow;
602 else if ( occ > fManuOccupancyLimits.Y() )
604 rv |= kManuOccupancyTooHigh;
610 //_____________________________________________________________________________
612 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
614 /// Get the status container for a given manu
616 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
619 // not already there, so compute it now
620 AliCodeTimerAuto("ComputeStatus",0);
621 param = ComputeStatus(detElemId,manuId);
626 //_____________________________________________________________________________
628 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
630 /// Get the status for a given channel
632 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
635 // not already there, so compute it now
636 param = ComputeStatus(detElemId,manuId);
638 return param->ValueAsInt(manuChannel,0);
641 //_____________________________________________________________________________
643 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
645 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
646 /// is different thing from St12 and St345)
648 AliCodeTimerAuto("",0)
650 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
652 const AliMpArrayI* manus = de->ManusForHV(index);
654 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
656 Int_t manuId = manus->GetValue(i);
657 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);
661 //_____________________________________________________________________________
663 AliMUONPadStatusMaker::HVLimit(Int_t chamberId) const
665 /// Get HV limit for a given chamber
666 if ( chamberId >=0 && chamberId < 10 )
668 return fHVLimit[chamberId];
673 //_____________________________________________________________________________
675 AliMUONPadStatusMaker::SetHVLimit(Int_t chamberId, Double_t hv)
677 /// Set hv limit for a given chamber (or all if chamberId==-1)
679 if ( chamberId == -1 )
681 for ( Int_t i = 0; i < 10; ++i )
686 else if ( chamberId >= 0 && chamberId < 10 )
688 fHVLimit[chamberId]=hv;
692 AliError(Form("chamberId=%d is invalid",chamberId));
696 //_____________________________________________________________________________
698 AliMUONPadStatusMaker::SetLimits(const AliMUONRecoParam& recoParams)
700 /// Set the limits from the recoparam
702 for ( int i = 0; i < 10; ++i )
704 SetHVLimit(i,recoParams.HVLimit(i));
707 SetPedMeanLimits(recoParams.PedMeanLowLimit(),recoParams.PedMeanHighLimit());
708 SetPedSigmaLimits(recoParams.PedSigmaLowLimit(),recoParams.PedSigmaHighLimit());
710 SetGainA1Limits(recoParams.GainA1LowLimit(),recoParams.GainA1HighLimit());
711 SetGainA2Limits(recoParams.GainA2LowLimit(),recoParams.GainA2HighLimit());
712 SetGainThresLimits(recoParams.GainThresLowLimit(),recoParams.GainThresHighLimit());
714 SetManuOccupancyLimits(recoParams.ManuOccupancyLowLimit(),recoParams.ManuOccupancyHighLimit());
715 SetBuspatchOccupancyLimits(recoParams.BuspatchOccupancyLowLimit(),recoParams.BuspatchOccupancyHighLimit());
716 SetDEOccupancyLimits(recoParams.DEOccupancyLowLimit(),recoParams.DEOccupancyHighLimit());
719 //_____________________________________________________________________________
721 AliMUONPadStatusMaker::Report(UInt_t mask)
723 /// Report the number of bad pads, according to the mask,
724 /// and the various reasons why they are bad (with occurence rates)
727 AliCodeTimerAuto("",0);
729 AliMUONLogger log(1064008);
734 AliMpManuIterator it;
736 Int_t detElemId, manuId;
738 while ( it.Next(detElemId,manuId) )
740 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
742 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
744 if ( de->IsConnectedChannel(manuId,i) )
748 Int_t status = PadStatus(detElemId,manuId,i);
750 if ( mask && ( status & mask) ) // note that if mask == 0, all pads are good...
753 log.Log(AsString(status));
762 cout << Form("According to mask %x (human readable form below) %6d pads are bad (over a total of %6d, i.e. %7.2f %%)",
763 mask,nBadPads,nPads,nPads ? nBadPads*100.0/nPads : 0.0) << endl;
764 cout << AliMUONPadStatusMaker::AsCondition(mask) << endl;
765 cout << "--------" << endl;
767 while ( log.Next(msg,ntimes) )
769 cout << Form("The message (%120s) occured %15d times (%7.4f %%)",msg.Data(),ntimes,ntimes*100.0/nPads) << endl;