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()));
97 /// 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
123 DecodeStatus(status,pedStatus,hvStatus,gainStatus,occStatus);
127 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
128 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
129 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
130 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
131 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
132 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
134 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
135 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
136 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
137 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
138 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
139 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
140 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
142 if ( hvStatus & kHVError ) s+="& HV is on error ";
143 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
144 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
145 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
146 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
147 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
149 if ( occStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
150 if ( occStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
151 if ( occStatus & kBusPatchOccupancyTooHigh ) s+="& bus patch occupancy too high ";
152 if ( occStatus & kBusPatchOccupancyTooLow ) s+="& bus patch occupancy too low ";
153 if ( occStatus & kDEOccupancyTooHigh ) s+="& DE occupancy too high ";
154 if ( occStatus & kDEOccupancyTooLow ) s+="& DE occupancy too low ";
156 if ( s[0] == '&' ) s[0] = ' ';
161 //_____________________________________________________________________________
163 AliMUONPadStatusMaker::AsCondition(Int_t mask)
165 /// return a human readable version of the mask's equivalent condition
167 TString s(AsString(mask));
169 s.ReplaceAll("&","|");
174 //_____________________________________________________________________________
176 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
181 /// Build a complete status from specific parts (ped,hv,gain)
183 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
184 ( ( gainStatus & 0xFF ) << 16 ) |
185 ( ( occStatus & 0xFF ) << 24 ) ;
188 //_____________________________________________________________________________
190 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
196 /// Decode complete status into specific parts (ped,hv,gain)
198 occStatus = ( status & 0xFF000000 ) >> 24;
199 gainStatus = ( status & 0xFF0000 ) >> 16;
200 pedStatus = ( status & 0xFF00 ) >> 8;
201 hvStatus = (status & 0xFF);
204 //_____________________________________________________________________________
206 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
207 Bool_t& hvChannelTooLow,
208 Bool_t& hvChannelTooHigh,
209 Bool_t& hvChannelON) const
211 /// Get HV status for one HV sector of St12
213 /// For a given PCB in a given DE, get the HV status (both the channel
215 /// Returns false if hv switch changed during the run.
217 AliCodeTimerAuto("",0)
219 if (!fHV) return kFALSE;
221 Bool_t error = kFALSE;
222 hvChannelTooLow = kFALSE;
223 hvChannelTooHigh = kFALSE;
226 AliMpDCSNamer hvNamer("TRACKER");
228 TString hvChannel(hvNamer.DCSChannelName(detElemId,sector));
230 TMap* hvMap = fkCalibrationData.HV();
231 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
234 AliError(Form("Did not find expected alias (%s) for DE %d",
235 hvChannel.Data(),detElemId));
240 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
243 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
248 // find out min and max value, and makes a cut
254 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
256 Float_t hv = val->GetFloat();
257 hvMin = TMath::Min(hv,hvMin);
258 hvMax = TMath::Max(hv,hvMax);
261 float lowThreshold = fHVSt12Limits.X();
262 float highThreshold = fHVSt12Limits.Y();
264 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
265 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
266 if ( hvMin < 1 ) hvChannelON = kFALSE;
273 //_____________________________________________________________________________
275 AliMUONPadStatusMaker::SwitchValue(const TObjArray& dcsArray)
277 /// Loop over the dcs value for a single switch to decide whether
278 /// we should consider it on or off
280 // we'll count the number of ON/OFF for this pad, to insure
281 // consistency (i.e. if status changed during the run, we should
282 // at least notify this fact ;-) and hope it's not the norm)
285 TIter next(&dcsArray);
288 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
290 if ( val->GetBool() )
300 if ( (nTrue>0 && nFalse>0) )
302 // change of state during the run, consider it off
308 /// switch = FALSE means the HV was flowding up to the PCB.
309 /// i.e. switch = FALSE = ON
316 //_____________________________________________________________________________
318 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
319 Bool_t& hvChannelTooLow,
320 Bool_t& hvChannelTooHigh,
322 Bool_t& hvSwitchON) const
324 /// For a given PCB in a given DE, get the HV status (both the channel
326 /// Returns false if something goes wrong (in particular if
327 /// hv switch changed during the run).
329 AliCodeTimerAuto("",0)
331 if (!fHV) return kFALSE;
333 Bool_t error = kFALSE;
334 hvChannelTooLow = kFALSE;
335 hvChannelTooHigh = kFALSE;
339 AliMpDCSNamer hvNamer("TRACKER");
341 TString hvChannel(hvNamer.DCSChannelName(detElemId));
343 TMap* hvMap = fkCalibrationData.HV();
345 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
348 AliError(Form("Did not find expected alias (%s) for DE %d",
349 hvChannel.Data(),detElemId));
354 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
357 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
362 // find out min and max value, and makes a cut
368 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
370 Float_t hv = val->GetFloat();
371 hvMin = TMath::Min(hv,hvMin);
372 hvMax = TMath::Max(hv,hvMax);
375 float lowThreshold = fHVSt345Limits.X();
376 float highThreshold = fHVSt345Limits.Y();
378 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
379 else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
380 if ( hvMin < 1 ) hvChannelON = kFALSE;
384 TString hvSwitch(hvNamer.DCSSwitchName(detElemId,pcbIndex));
385 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
388 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
389 hvSwitch.Data(),detElemId,pcbIndex));
394 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
397 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
402 Float_t sv = SwitchValue(*values);
403 if ( sv < 0.99 ) hvSwitchON = kFALSE;
409 //_____________________________________________________________________________
411 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
413 /// Get HV status of one manu
415 AliCodeTimerAuto("",0)
417 if ( !fHV ) return kMissing;
419 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
423 return (Int_t)(lint - 1);
428 AliMpDCSNamer hvNamer("TRACKER");
430 switch ( AliMpDEManager::GetStationType(detElemId) )
432 case AliMp::kStation12:
434 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
437 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
438 Bool_t error = HVSt12Status(detElemId,sector,
442 if ( error ) status |= kHVError;
443 if ( hvChannelTooLow ) status |= kHVTooLow;
444 if ( hvChannelTooHigh ) status |= kHVTooHigh;
445 if ( !hvChannelON ) status |= kHVChannelOFF;
446 // assign this status to all the other manus handled by the same HV channel
447 SetHVStatus(detElemId,sector,status);
451 case AliMp::kStation345:
453 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
456 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
457 Bool_t error = HVSt345Status(detElemId,pcbIndex,
458 hvChannelTooLow,hvChannelTooHigh,
459 hvChannelON,hvSwitchON);
460 if ( error ) status |= kHVError;
461 if ( hvChannelTooLow ) status |= kHVTooLow;
462 if ( hvChannelTooHigh ) status |= kHVTooHigh;
463 if ( !hvSwitchON ) status |= kHVSwitchOFF;
464 if ( !hvChannelON) status |= kHVChannelOFF;
465 // assign this status to all the other manus handled by the same HV channel
466 SetHVStatus(detElemId,pcbIndex,status);
477 //_____________________________________________________________________________
479 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
481 /// Get the neighbours parameters for a given manu
482 AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
483 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
486 //_____________________________________________________________________________
488 AliMUONPadStatusMaker::NeighboursStore() const
490 /// Return the store containing all the neighbours
491 return fkCalibrationData.Neighbours();
494 //_____________________________________________________________________________
496 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
498 /// Compute the status of a given manu, using all available information,
499 /// i.e. pedestals, gains, and HV
501 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
504 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
506 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
508 Int_t hvStatus = HVStatus(detElemId,manuId);
510 Int_t occStatus = OccupancyStatus(detElemId,manuId);
512 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
518 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
519 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
520 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
521 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
522 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
523 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
524 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
528 pedStatus = kPedMissing;
535 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
536 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
537 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
539 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
540 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
541 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
542 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
543 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
544 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
548 gainStatus = kGainMissing;
551 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,occStatus);
553 param->SetValueAsIntFast(manuChannel,0,status);
559 //_____________________________________________________________________________
561 AliMUONPadStatusMaker::OccupancyStatus(Int_t detElemId, Int_t manuId) const
563 /// Get the "other" status for a given manu
569 const Int_t occIndex = 2;
571 Double_t occ = fTrackerData->DetectionElement(detElemId,occIndex);
573 if ( occ <= fDEOccupancyLimits.X() )
575 rv |= kDEOccupancyTooLow;
577 else if ( occ > fDEOccupancyLimits.Y() )
579 rv |= kDEOccupancyTooHigh;
582 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
584 occ = fTrackerData->BusPatch(busPatchId,occIndex);
586 if ( occ <= fBuspatchOccupancyLimits.X() )
588 rv |= kBusPatchOccupancyTooLow;
590 else if ( occ > fBuspatchOccupancyLimits.Y() )
592 rv |= kBusPatchOccupancyTooHigh;
595 occ = fTrackerData->Manu(detElemId,manuId,occIndex);
597 if ( occ <= fManuOccupancyLimits.X() )
599 rv |= kManuOccupancyTooLow;
601 else if ( occ > fManuOccupancyLimits.Y() )
603 rv |= kManuOccupancyTooHigh;
609 //_____________________________________________________________________________
611 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
613 /// Get the status container for a given manu
615 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
618 // not already there, so compute it now
619 AliCodeTimerAuto("ComputeStatus",0);
620 param = ComputeStatus(detElemId,manuId);
625 //_____________________________________________________________________________
627 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
629 /// Get the status for a given channel
631 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
634 // not already there, so compute it now
635 param = ComputeStatus(detElemId,manuId);
637 return param->ValueAsInt(manuChannel,0);
640 //_____________________________________________________________________________
642 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
644 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
645 /// is different thing from St12 and St345)
647 AliCodeTimerAuto("",0)
649 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
651 const AliMpArrayI* manus = de->ManusForHV(index);
653 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
655 Int_t manuId = manus->GetValue(i);
656 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);
660 //_____________________________________________________________________________
662 AliMUONPadStatusMaker::SetLimits(const AliMUONRecoParam& recoParams)
664 /// Set the limits from the recoparam
666 SetHVSt12Limits(recoParams.HVSt12LowLimit(),recoParams.HVSt12HighLimit());
667 SetHVSt345Limits(recoParams.HVSt345LowLimit(),recoParams.HVSt345HighLimit());
669 SetPedMeanLimits(recoParams.PedMeanLowLimit(),recoParams.PedMeanHighLimit());
670 SetPedSigmaLimits(recoParams.PedSigmaLowLimit(),recoParams.PedSigmaHighLimit());
672 SetGainA1Limits(recoParams.GainA1LowLimit(),recoParams.GainA1HighLimit());
673 SetGainA2Limits(recoParams.GainA2LowLimit(),recoParams.GainA2HighLimit());
674 SetGainThresLimits(recoParams.GainThresLowLimit(),recoParams.GainThresHighLimit());
676 SetManuOccupancyLimits(recoParams.ManuOccupancyLowLimit(),recoParams.ManuOccupancyHighLimit());
677 SetBuspatchOccupancyLimits(recoParams.BuspatchOccupancyLowLimit(),recoParams.BuspatchOccupancyHighLimit());
678 SetDEOccupancyLimits(recoParams.DEOccupancyLowLimit(),recoParams.DEOccupancyHighLimit());
681 //_____________________________________________________________________________
683 AliMUONPadStatusMaker::Report(UInt_t mask)
685 /// Report the number of bad pads, according to the mask,
686 /// and the various reasons why they are bad (with occurence rates)
689 AliCodeTimerAuto("",0);
691 AliMUONLogger log(1064008);
696 AliMpManuIterator it;
698 Int_t detElemId, manuId;
700 while ( it.Next(detElemId,manuId) )
702 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
704 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
706 if ( de->IsConnectedChannel(manuId,i) )
710 Int_t status = PadStatus(detElemId,manuId,i);
712 if ( ( status & mask) || (!mask && status) )
715 log.Log(AsString(status));
724 cout << Form("According to mask %x (human readable form below) %6d pads are bad (over a total of %6d, i.e. %7.2f %%)",
725 mask,nBadPads,nPads,nPads ? nBadPads*100.0/nPads : 0.0) << endl;
726 cout << AliMUONPadStatusMaker::AsCondition(mask) << endl;
727 cout << "--------" << endl;
729 while ( log.Next(msg,ntimes) )
731 cout << Form("The message (%120s) occured %15d times (%7.4f %%)",msg.Data(),ntimes,ntimes*100.0/nPads) << endl;