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>
69 ClassImp(AliMUONPadStatusMaker)
72 //_____________________________________________________________________________
73 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
74 : fkCalibrationData(calibData),
75 fGainA1Limits(0,1E30),
76 fGainA2Limits(-1E-30,1E30),
77 fGainThresLimits(0,4095),
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()));
97 /// Only create the fHV internal store if there are some HV values available
104 //_____________________________________________________________________________
105 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
114 //_____________________________________________________________________________
116 AliMUONPadStatusMaker::AsString(Int_t status)
118 /// return a human readable version of the integer status
122 return "Brave New World";
130 DecodeStatus(status,pedStatus,hvStatus,gainStatus,occStatus);
134 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
135 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
136 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
137 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
138 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
139 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
141 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
142 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
143 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
144 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
145 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
146 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
147 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
149 if ( hvStatus & kHVError ) s+="& HV is on error ";
150 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
151 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
152 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
153 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
154 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
156 if ( occStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
157 if ( occStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
158 if ( occStatus & kBusPatchOccupancyTooHigh ) s+="& bus patch occupancy too high ";
159 if ( occStatus & kBusPatchOccupancyTooLow ) s+="& bus patch occupancy too low ";
160 if ( occStatus & kDEOccupancyTooHigh ) s+="& DE occupancy too high ";
161 if ( occStatus & kDEOccupancyTooLow ) s+="& DE occupancy too low ";
163 if ( s[0] == '&' ) s[0] = ' ';
168 //_____________________________________________________________________________
170 AliMUONPadStatusMaker::AsCondition(Int_t mask)
172 /// return a human readable version of the mask's equivalent condition
174 TString s(AsString(mask));
176 s.ReplaceAll("&","|");
181 //_____________________________________________________________________________
183 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
188 /// Build a complete status from specific parts (ped,hv,gain)
190 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
191 ( ( gainStatus & 0xFF ) << 16 ) |
192 ( ( occStatus & 0xFF ) << 24 ) ;
195 //_____________________________________________________________________________
197 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
203 /// Decode complete status into specific parts (ped,hv,gain)
205 occStatus = ( status & 0xFF000000 ) >> 24;
206 gainStatus = ( status & 0xFF0000 ) >> 16;
207 pedStatus = ( status & 0xFF00 ) >> 8;
208 hvStatus = (status & 0xFF);
211 //_____________________________________________________________________________
213 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
214 Bool_t& hvChannelTooLow,
215 Bool_t& hvChannelTooHigh,
216 Bool_t& hvChannelON) const
218 /// Get HV status for one HV sector of St12
220 /// For a given PCB in a given DE, get the HV status (both the channel
222 /// Returns false if hv switch changed during the run.
224 AliCodeTimerAuto("",0)
226 if (!fHV) return kFALSE;
228 Bool_t error = kFALSE;
229 hvChannelTooLow = kFALSE;
230 hvChannelTooHigh = kFALSE;
233 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
235 AliMpDCSNamer hvNamer("TRACKER");
237 TString hvChannel(hvNamer.DCSAliasName(detElemId,sector));
239 TMap* hvMap = fkCalibrationData.HV();
240 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
243 AliError(Form("Did not find expected alias (%s) for DE %d",
244 hvChannel.Data(),detElemId));
249 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
252 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
257 // find out min value, and makes a cut
262 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
264 Float_t hv = val->GetFloat();
265 hvMin = TMath::Min(hv,hvMin);
268 float lowThreshold = HVLimit(chamberId);
270 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
271 if ( hvMin < hvNamer.TrackerHVOFF() ) hvChannelON = kFALSE;
278 //_____________________________________________________________________________
280 AliMUONPadStatusMaker::SwitchValue(const TObjArray& dcsArray)
282 /// Loop over the dcs value for a single switch to decide whether
283 /// we should consider it on or off
285 // we'll count the number of ON/OFF for this pad, to insure
286 // consistency (i.e. if status changed during the run, we should
287 // at least notify this fact ;-) and hope it's not the norm)
290 TIter next(&dcsArray);
293 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
295 if ( val->GetBool() )
305 if ( (nTrue>0 && nFalse>0) )
307 // change of state during the run, consider it off
313 /// switch = FALSE means the HV was flowding up to the PCB.
314 /// i.e. switch = FALSE = ON
321 //_____________________________________________________________________________
323 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
324 Bool_t& hvChannelTooLow,
325 Bool_t& hvChannelTooHigh,
327 Bool_t& hvSwitchON) const
329 /// For a given PCB in a given DE, get the HV status (both the channel
331 /// Returns false if something goes wrong (in particular if
332 /// hv switch changed during the run).
334 AliCodeTimerAuto("",0)
336 if (!fHV) return kFALSE;
338 Bool_t error = kFALSE;
339 hvChannelTooLow = kFALSE;
340 hvChannelTooHigh = kFALSE;
344 AliMpDCSNamer hvNamer("TRACKER");
346 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
348 TString hvChannel(hvNamer.DCSAliasName(detElemId));
350 TMap* hvMap = fkCalibrationData.HV();
352 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
355 AliError(Form("Did not find expected alias (%s) for DE %d",
356 hvChannel.Data(),detElemId));
361 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
364 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
369 // find out min value, and makes a cut
374 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
376 Float_t hv = val->GetFloat();
377 hvMin = TMath::Min(hv,hvMin);
380 float lowThreshold = HVLimit(chamberId);
382 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
383 if ( hvMin < hvNamer.TrackerHVOFF() ) hvChannelON = kFALSE;
387 TString hvSwitch(hvNamer.DCSSwitchAliasName(detElemId,pcbIndex));
388 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
391 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
392 hvSwitch.Data(),detElemId,pcbIndex));
397 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
400 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
405 Float_t sv = SwitchValue(*values);
406 if ( sv < 0.99 ) hvSwitchON = kFALSE;
412 //_____________________________________________________________________________
414 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
416 /// Get HV status of one manu
418 AliCodeTimerAuto("",0)
420 if ( !fHV ) return kMissing;
422 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
426 return (Int_t)(lint - 1);
431 AliMpDCSNamer hvNamer("TRACKER");
433 switch ( AliMpDEManager::GetStationType(detElemId) )
435 case AliMp::kStation12:
437 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
440 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
441 Bool_t error = HVSt12Status(detElemId,sector,
445 if ( error ) status |= kHVError;
446 if ( hvChannelTooLow ) status |= kHVTooLow;
447 if ( hvChannelTooHigh ) status |= kHVTooHigh;
448 if ( !hvChannelON ) status |= kHVChannelOFF;
449 // assign this status to all the other manus handled by the same HV channel
450 SetHVStatus(detElemId,sector,status);
454 case AliMp::kStation345:
456 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
459 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
460 Bool_t error = HVSt345Status(detElemId,pcbIndex,
461 hvChannelTooLow,hvChannelTooHigh,
462 hvChannelON,hvSwitchON);
463 if ( error ) status |= kHVError;
464 if ( hvChannelTooLow ) status |= kHVTooLow;
465 if ( hvChannelTooHigh ) status |= kHVTooHigh;
466 if ( !hvSwitchON ) status |= kHVSwitchOFF;
467 if ( !hvChannelON) status |= kHVChannelOFF;
468 // assign this status to all the other manus handled by the same HV channel
469 SetHVStatus(detElemId,pcbIndex,status);
480 //_____________________________________________________________________________
482 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
484 /// Get the neighbours parameters for a given manu
485 AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
486 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
489 //_____________________________________________________________________________
491 AliMUONPadStatusMaker::NeighboursStore() const
493 /// Return the store containing all the neighbours
494 return fkCalibrationData.Neighbours();
497 //_____________________________________________________________________________
499 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
501 /// Compute the status of a given manu, using all available information,
502 /// i.e. pedestals, gains, and HV
504 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
507 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
509 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
511 Int_t hvStatus = HVStatus(detElemId,manuId);
513 Int_t occStatus = OccupancyStatus(detElemId,manuId);
515 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
521 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
522 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
523 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
524 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
525 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
526 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
527 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
531 pedStatus = kPedMissing;
538 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
539 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
540 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
542 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
543 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
544 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
545 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
546 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
547 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
551 gainStatus = kGainMissing;
554 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,occStatus);
556 param->SetValueAsIntFast(manuChannel,0,status);
562 //_____________________________________________________________________________
564 AliMUONPadStatusMaker::OccupancyStatus(Int_t detElemId, Int_t manuId) const
566 /// Get the "other" status for a given manu
572 const Int_t occIndex = 2;
574 Double_t occ = fTrackerData->DetectionElement(detElemId,occIndex);
576 if ( occ <= fDEOccupancyLimits.X() )
578 rv |= kDEOccupancyTooLow;
580 else if ( occ > fDEOccupancyLimits.Y() )
582 rv |= kDEOccupancyTooHigh;
585 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
587 occ = fTrackerData->BusPatch(busPatchId,occIndex);
589 if ( occ <= fBuspatchOccupancyLimits.X() )
591 rv |= kBusPatchOccupancyTooLow;
593 else if ( occ > fBuspatchOccupancyLimits.Y() )
595 rv |= kBusPatchOccupancyTooHigh;
598 occ = fTrackerData->Manu(detElemId,manuId,occIndex);
600 if ( occ <= fManuOccupancyLimits.X() )
602 rv |= kManuOccupancyTooLow;
604 else if ( occ > fManuOccupancyLimits.Y() )
606 rv |= kManuOccupancyTooHigh;
612 //_____________________________________________________________________________
614 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
616 /// Get the status container for a given manu
618 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
621 // not already there, so compute it now
622 AliCodeTimerAuto("ComputeStatus",0);
623 param = ComputeStatus(detElemId,manuId);
628 //_____________________________________________________________________________
630 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
632 /// Get the status for a given channel
634 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
637 // not already there, so compute it now
638 param = ComputeStatus(detElemId,manuId);
640 return param->ValueAsInt(manuChannel,0);
643 //_____________________________________________________________________________
645 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
647 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
648 /// is different thing from St12 and St345)
650 AliCodeTimerAuto("",0)
652 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
654 const AliMpArrayI* manus = de->ManusForHV(index);
656 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
658 Int_t manuId = manus->GetValue(i);
659 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);
663 //_____________________________________________________________________________
665 AliMUONPadStatusMaker::HVLimit(Int_t chamberId) const
667 /// Get HV limit for a given chamber
668 if ( chamberId >=0 && chamberId < 10 )
670 return fHVLimit[chamberId];
675 //_____________________________________________________________________________
677 AliMUONPadStatusMaker::SetHVLimit(Int_t chamberId, Double_t hv)
679 /// Set hv limit for a given chamber (or all if chamberId==-1)
681 if ( chamberId == -1 )
683 for ( Int_t i = 0; i < 10; ++i )
688 else if ( chamberId >= 0 && chamberId < 10 )
690 fHVLimit[chamberId]=hv;
694 AliError(Form("chamberId=%d is invalid",chamberId));
698 //_____________________________________________________________________________
700 AliMUONPadStatusMaker::SetLimits(const AliMUONRecoParam& recoParams)
702 /// Set the limits from the recoparam
704 for ( int i = 0; i < 10; ++i )
706 SetHVLimit(i,recoParams.HVLimit(i));
709 SetPedMeanLimits(recoParams.PedMeanLowLimit(),recoParams.PedMeanHighLimit());
710 SetPedSigmaLimits(recoParams.PedSigmaLowLimit(),recoParams.PedSigmaHighLimit());
712 SetGainA1Limits(recoParams.GainA1LowLimit(),recoParams.GainA1HighLimit());
713 SetGainA2Limits(recoParams.GainA2LowLimit(),recoParams.GainA2HighLimit());
714 SetGainThresLimits(recoParams.GainThresLowLimit(),recoParams.GainThresHighLimit());
716 SetManuOccupancyLimits(recoParams.ManuOccupancyLowLimit(),recoParams.ManuOccupancyHighLimit());
717 SetBuspatchOccupancyLimits(recoParams.BuspatchOccupancyLowLimit(),recoParams.BuspatchOccupancyHighLimit());
718 SetDEOccupancyLimits(recoParams.DEOccupancyLowLimit(),recoParams.DEOccupancyHighLimit());
721 //_____________________________________________________________________________
723 AliMUONPadStatusMaker::Report(UInt_t mask)
725 /// Report the number of bad pads, according to the mask,
726 /// and the various reasons why they are bad (with occurence rates)
729 AliCodeTimerAuto("",0);
731 AliMUONLogger log(1064008);
736 AliMpManuIterator it;
738 Int_t detElemId, manuId;
740 while ( it.Next(detElemId,manuId) )
742 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
744 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
746 if ( de->IsConnectedChannel(manuId,i) )
750 Int_t status = PadStatus(detElemId,manuId,i);
752 if ( mask && ( status & mask) ) // note that if mask == 0, all pads are good...
755 log.Log(AsString(status));
763 AliError("Got no pad from the iterator ?! That's not normal. Please check !");
770 cout << Form("According to mask %x (human readable form below) %6d pads are bad (over a total of %6d, i.e. %7.2f %%)",
771 mask,nBadPads,nPads,nBadPads*100.0/nPads) << endl;
772 cout << AliMUONPadStatusMaker::AsCondition(mask) << endl;
773 cout << "--------" << endl;
775 while ( log.Next(msg,ntimes) )
777 cout << Form("The message (%120s) occured %15d times (%7.4f %%)",msg.Data(),ntimes,ntimes*100.0/nPads) << endl;