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 "AliMUONStringIntMap.h"
34 #include "AliMUONVCalibParam.h"
35 #include "AliMUONTrackerData.h"
37 #include "AliMpArea.h"
38 #include "AliMpArrayI.h"
39 #include "AliMpConstants.h"
40 #include "AliMpDDLStore.h"
41 #include "AliMpDEManager.h"
42 #include "AliMpDetElement.h"
43 #include "AliMpDCSNamer.h"
44 #include "AliMpManuUID.h"
46 #include "AliCDBEntry.h"
47 #include "AliCDBManager.h"
48 #include "AliCodeTimer.h"
49 #include "AliDCSValue.h"
52 #include <Riostream.h>
63 ClassImp(AliMUONPadStatusMaker)
66 //_____________________________________________________________________________
67 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
68 : fkCalibrationData(calibData),
69 fGainA1Limits(0,1E30),
70 fGainA2Limits(-1E-30,1E30),
71 fGainThresLimits(0,4095),
72 fHVSt12Limits(0,5000),
73 fHVSt345Limits(0,5000),
74 fPedMeanLimits(0,4095),
75 fPedSigmaLimits(0,4095),
76 fManuOccupancyLimits(0,1.0),
77 fBusPatchOccupancyLimits(0,1.0),
78 fDEOccupancyLimits(0,1.0),
79 fStatus(new AliMUON2DMap(true)),
81 fPedestals(calibData.Pedestals()),
82 fGains(calibData.Gains()),
86 AliDebug(1,Form("ped store %s gain store %s",
87 fPedestals->ClassName(),
88 fGains->ClassName()));
90 if ( calibData.OccupancyMap() )
92 AliInfo("Will use occupancy map to cut, if so required in AliMUONRecoParam");
93 /// create a tracker data from the occupancy map
94 fTrackerData = new AliMUONTrackerData("OCC","OCC",*(calibData.OccupancyMap()));
98 //_____________________________________________________________________________
99 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
107 //_____________________________________________________________________________
109 AliMUONPadStatusMaker::AsString(Int_t status)
111 /// return a human readable version of the integer status
118 DecodeStatus(status,pedStatus,hvStatus,gainStatus,occStatus);
122 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
123 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
124 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
125 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
126 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
127 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
129 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
130 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
131 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
132 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
133 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
134 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
135 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
137 if ( hvStatus & kHVError ) s+="& HV is on error ";
138 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
139 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
140 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
141 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
142 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
144 if ( occStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
145 if ( occStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
146 if ( occStatus & kBusPatchOccupancyTooHigh ) s+="& bus patch occupancy too high ";
147 if ( occStatus & kBusPatchOccupancyTooLow ) s+="& bus patch occupancy too low ";
148 if ( occStatus & kDEOccupancyTooHigh ) s+="& DE occupancy too high ";
149 if ( occStatus & kDEOccupancyTooLow ) s+="& DE occupancy too low ";
151 if ( s[0] == '&' ) s[0] = ' ';
156 //_____________________________________________________________________________
158 AliMUONPadStatusMaker::AsCondition(Int_t mask)
160 /// return a human readable version of the mask's equivalent condition
162 TString s(AsString(mask));
164 s.ReplaceAll("&","|");
169 //_____________________________________________________________________________
171 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
176 /// Build a complete status from specific parts (ped,hv,gain)
178 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
179 ( ( gainStatus & 0xFF ) << 16 ) |
180 ( ( occStatus & 0xFF ) << 24 ) ;
183 //_____________________________________________________________________________
185 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
191 /// Decode complete status into specific parts (ped,hv,gain)
193 occStatus = ( status & 0xFF000000 ) >> 24;
194 gainStatus = ( status & 0xFF0000 ) >> 16;
195 pedStatus = ( status & 0xFF00 ) >> 8;
196 hvStatus = (status & 0xFF);
199 //_____________________________________________________________________________
201 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
202 Bool_t& hvChannelTooLow,
203 Bool_t& hvChannelTooHigh,
204 Bool_t& hvChannelON) const
206 /// Get HV status for one HV sector of St12
208 /// For a given PCB in a given DE, get the HV status (both the channel
210 /// Returns false if hv switch changed during the run.
214 Bool_t error = kFALSE;
215 hvChannelTooLow = kFALSE;
216 hvChannelTooHigh = kFALSE;
219 AliMpDCSNamer hvNamer("TRACKER");
221 TString hvChannel(hvNamer.DCSChannelName(detElemId,sector));
223 TMap* hvMap = fkCalibrationData.HV();
224 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
227 AliError(Form("Did not find expected alias (%s) for DE %d",
228 hvChannel.Data(),detElemId));
233 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
236 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
241 // find out min and max value, and makes a cut
247 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
249 Float_t hv = val->GetFloat();
250 hvMin = TMath::Min(hv,hvMin);
251 hvMax = TMath::Max(hv,hvMax);
254 float lowThreshold = fHVSt12Limits.X();
255 float highThreshold = fHVSt12Limits.Y();
257 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
258 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
259 if ( hvMin < 1 ) hvChannelON = kFALSE;
266 //_____________________________________________________________________________
268 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
269 Bool_t& hvChannelTooLow,
270 Bool_t& hvChannelTooHigh,
272 Bool_t& hvSwitchON) const
274 /// For a given PCB in a given DE, get the HV status (both the channel
276 /// Returns false if something goes wrong (in particular if
277 /// hv switch changed during the run).
281 Bool_t error = kFALSE;
282 hvChannelTooLow = kFALSE;
283 hvChannelTooHigh = kFALSE;
287 AliMpDCSNamer hvNamer("TRACKER");
289 TString hvChannel(hvNamer.DCSChannelName(detElemId));
291 TMap* hvMap = fkCalibrationData.HV();
293 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
296 AliError(Form("Did not find expected alias (%s) for DE %d",
297 hvChannel.Data(),detElemId));
302 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
305 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
310 // find out min and max value, and makes a cut
316 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
318 Float_t hv = val->GetFloat();
319 hvMin = TMath::Min(hv,hvMin);
320 hvMax = TMath::Max(hv,hvMax);
323 float lowThreshold = fHVSt345Limits.X();
324 float highThreshold = fHVSt345Limits.Y();
326 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
327 else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
328 if ( hvMin < 1 ) hvChannelON = kFALSE;
332 TString hvSwitch(hvNamer.DCSSwitchName(detElemId,pcbIndex));
333 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
336 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
337 hvSwitch.Data(),detElemId,pcbIndex));
342 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
345 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
350 // we'll count the number of ON/OFF for this pad, to insure
351 // consistency (i.e. if status changed during the run, we should
352 // at least notify this fact ;-) and hope it's not the norm)
358 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
360 if ( val->GetBool() )
370 if ( (nTrue>0 && nFalse>0) )
372 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
373 hvSwitch.Data(),nTrue,nFalse));
377 if ( nFalse ) hvSwitchON = kFALSE;
383 //_____________________________________________________________________________
385 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
387 /// Get HV status of one manu
391 if ( !fkCalibrationData.HV() ) return kMissing;
393 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
397 return (Int_t)(lint - 1);
402 AliMpDCSNamer hvNamer("TRACKER");
404 switch ( AliMpDEManager::GetStationType(detElemId) )
406 case AliMp::kStation12:
408 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
411 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
412 Bool_t error = HVSt12Status(detElemId,sector,
416 if ( error ) status |= kHVError;
417 if ( hvChannelTooLow ) status |= kHVTooLow;
418 if ( hvChannelTooHigh ) status |= kHVTooHigh;
419 if ( !hvChannelON ) status |= kHVChannelOFF;
420 // assign this status to all the other manus handled by the same HV channel
421 SetHVStatus(detElemId,sector,status);
425 case AliMp::kStation345:
427 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
430 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
431 Bool_t error = HVSt345Status(detElemId,pcbIndex,
432 hvChannelTooLow,hvChannelTooHigh,
433 hvChannelON,hvSwitchON);
434 if ( error ) status |= kHVError;
435 if ( hvChannelTooLow ) status |= kHVTooLow;
436 if ( hvChannelTooHigh ) status |= kHVTooHigh;
437 if ( !hvSwitchON ) status |= kHVSwitchOFF;
438 if ( !hvChannelON) status |= kHVChannelOFF;
439 // assign this status to all the other manus handled by the same HV channel
440 SetHVStatus(detElemId,pcbIndex,status);
451 //_____________________________________________________________________________
453 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
455 /// Get the neighbours parameters for a given manu
456 AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
457 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
460 //_____________________________________________________________________________
462 AliMUONPadStatusMaker::NeighboursStore() const
464 /// Return the store containing all the neighbours
465 return fkCalibrationData.Neighbours();
468 //_____________________________________________________________________________
470 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
472 /// Compute the status of a given manu, using all available information,
473 /// i.e. pedestals, gains, and HV
475 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
478 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
480 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
482 Int_t hvStatus = HVStatus(detElemId,manuId);
484 Int_t occStatus = OccupancyStatus(detElemId,manuId);
486 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
492 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
493 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
494 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
495 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
496 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
497 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
498 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
502 pedStatus = kPedMissing;
509 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
510 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
511 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
513 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
514 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
515 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
516 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
517 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
518 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
522 gainStatus = kGainMissing;
525 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,occStatus);
527 param->SetValueAsIntFast(manuChannel,0,status);
533 //_____________________________________________________________________________
535 AliMUONPadStatusMaker::OccupancyStatus(Int_t detElemId, Int_t manuId) const
537 /// Get the "other" status for a given manu
543 const Int_t occIndex = 2;
545 Double_t occ = fTrackerData->DetectionElement(detElemId,occIndex);
547 if ( occ <= fDEOccupancyLimits.X() )
549 rv |= kDEOccupancyTooLow;
551 else if ( occ > fDEOccupancyLimits.Y() )
553 rv |= kDEOccupancyTooHigh;
556 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
558 occ = fTrackerData->BusPatch(busPatchId,occIndex);
560 if ( occ <= fBusPatchOccupancyLimits.X() )
562 rv |= kBusPatchOccupancyTooLow;
564 else if ( occ > fBusPatchOccupancyLimits.Y() )
566 rv |= kBusPatchOccupancyTooHigh;
569 occ = fTrackerData->Manu(detElemId,manuId,occIndex);
571 if ( occ <= fManuOccupancyLimits.X() )
573 rv |= kManuOccupancyTooLow;
575 else if ( occ > fManuOccupancyLimits.Y() )
577 rv |= kManuOccupancyTooHigh;
583 //_____________________________________________________________________________
585 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
587 /// Get the status container for a given manu
589 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
592 // not already there, so compute it now
593 AliCodeTimerAuto("ComputeStatus");
594 param = ComputeStatus(detElemId,manuId);
599 //_____________________________________________________________________________
601 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
603 /// Get the status for a given channel
605 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
608 // not already there, so compute it now
609 param = ComputeStatus(detElemId,manuId);
611 return param->ValueAsInt(manuChannel,0);
614 //_____________________________________________________________________________
616 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
618 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
619 /// is different thing from St12 and St345)
623 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
625 const AliMpArrayI* manus = de->ManusForHV(index);
627 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
629 Int_t manuId = manus->GetValue(i);
630 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);