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"
36 #include "AliMpArea.h"
37 #include "AliMpArrayI.h"
38 #include "AliMpConstants.h"
39 #include "AliMpDDLStore.h"
40 #include "AliMpDEIterator.h"
41 #include "AliMpDEManager.h"
42 #include "AliMpDetElement.h"
43 #include "AliMpHVNamer.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>
59 ClassImp(AliMUONPadStatusMaker)
62 //_____________________________________________________________________________
63 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
64 : fCalibrationData(calibData),
65 fGainA0Limits(0,1E30),
66 fGainA1Limits(-1E-30,1E30),
67 fGainThresLimits(0,4095),
68 fHVSt12Limits(0,5000),
69 fHVSt345Limits(0,5000),
70 fPedMeanLimits(0,4095),
71 fPedSigmaLimits(0,4095),
72 fStatus(new AliMUON2DMap(true)),
74 fPedestals(calibData.Pedestals()),
75 fGains(calibData.Gains())
78 AliInfo(Form("ped store %s gain store %s",
79 fPedestals->ClassName(),
80 fGains->ClassName()));
83 //_____________________________________________________________________________
84 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
91 //_____________________________________________________________________________
93 AliMUONPadStatusMaker::AsString(Int_t status)
95 /// return a human readable version of the integer status
100 DecodeStatus(status,pedStatus,hvStatus,gainStatus);
106 // kGainA0TooLow = (1<<1),
107 // kGainA0TooHigh = (1<<2),
108 // kGainA1TooLow = (1<<3),
109 // kGainA1TooHigh = (1<<4),
110 // kGainThresTooLow = (1<<5),
111 // kGainThresTooHigh = (1<<6),
113 // kGainMissing = kMissing // please always use last bit for meaning "missing"
116 // /// Pedestal status
117 // enum EPedestalStatus
120 // kPedMeanZero = (1<<1),
121 // kPedMeanTooLow = (1<<2),
122 // kPedMeanTooHigh = (1<<3),
123 // kPedSigmaTooLow = (1<<4),
124 // kPedSigmaTooHigh = (1<<5),
126 // kPedMissing = kMissing // please always use last bit for meaning "missing"
131 if ( pedStatus == 0 ) s+= " OK";
132 if ( pedStatus & kPedMeanZero ) s += " Mean is Zero. ";
133 if ( pedStatus & kPedMeanTooLow ) s += " Mean Too Low. ";
134 if ( pedStatus & kPedMeanTooHigh ) s += " Mean Too High. ";
135 if ( pedStatus & kPedSigmaTooLow ) s += " Sigma Too Low. ";
136 if ( pedStatus & kPedSigmaTooHigh ) s += " Sigma Too High. ";
137 if ( pedStatus & kPedMissing ) s += " is missing.";
143 // kHVError = (1<<0),
144 // kHVTooLow = (1<<1),
145 // kHVTooHigh = (1<<2),
146 // kHVChannelOFF = (1<<3),
147 // kHVSwitchOFF = (1<<4),
149 // kHVMissing = kMissing // please always use last bit for meaning "missing"
155 //_____________________________________________________________________________
157 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
161 /// Build a complete status from specific parts (ped,hv,gain)
163 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
164 ( ( gainStatus & 0xFF ) << 16 );
167 //_____________________________________________________________________________
169 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
174 /// Decode complete status into specific parts (ped,hv,gain)
176 gainStatus = ( status & 0xFF0000 ) >> 16;
177 pedStatus = ( status & 0xFF00 ) >> 8;
178 hvStatus = (status & 0xFF);
181 //_____________________________________________________________________________
183 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
184 Bool_t& hvChannelTooLow,
185 Bool_t& hvChannelTooHigh,
186 Bool_t& hvChannelON) const
188 /// Get HV status for one HV sector of St12
190 /// For a given PCB in a given DE, get the HV status (both the channel
192 /// Returns false if hv switch changed during the run.
196 Bool_t error = kFALSE;
197 hvChannelTooLow = kFALSE;
198 hvChannelTooHigh = kFALSE;
201 AliMpHVNamer hvNamer;
203 TString hvChannel(hvNamer.DCSHVChannelName(detElemId,sector));
205 TMap* hvMap = fCalibrationData.HV();
206 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
209 AliError(Form("Did not find expected alias (%s) for DE %d",
210 hvChannel.Data(),detElemId));
215 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
218 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
223 // find out min and max value, and makes a cut
229 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
231 Float_t hv = val->GetFloat();
232 hvMin = TMath::Min(hv,hvMin);
233 hvMax = TMath::Max(hv,hvMax);
236 float lowThreshold = fHVSt12Limits.X();
237 float highThreshold = fHVSt12Limits.Y();
239 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
240 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
241 if ( hvMin < 1 ) hvChannelON = kFALSE;
248 //_____________________________________________________________________________
250 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
251 Bool_t& hvChannelTooLow,
252 Bool_t& hvChannelTooHigh,
254 Bool_t& hvSwitchON) const
256 /// For a given PCB in a given DE, get the HV status (both the channel
258 /// Returns false if something goes wrong (in particular if
259 /// hv switch changed during the run).
263 Bool_t error = kFALSE;
264 hvChannelTooLow = kFALSE;
265 hvChannelTooHigh = kFALSE;
269 AliMpHVNamer hvNamer;
271 TString hvChannel(hvNamer.DCSHVChannelName(detElemId));
273 TMap* hvMap = fCalibrationData.HV();
275 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
278 AliError(Form("Did not find expected alias (%s) for DE %d",
279 hvChannel.Data(),detElemId));
284 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
287 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
292 // find out min and max value, and makes a cut
298 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
300 Float_t hv = val->GetFloat();
301 hvMin = TMath::Min(hv,hvMin);
302 hvMax = TMath::Max(hv,hvMax);
305 float lowThreshold = fHVSt345Limits.X();
306 float highThreshold = fHVSt345Limits.Y();
308 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
309 else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
310 if ( hvMin < 1 ) hvChannelON = kFALSE;
314 TString hvSwitch(hvNamer.DCSHVSwitchName(detElemId,pcbIndex));
315 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
318 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
319 hvSwitch.Data(),detElemId,pcbIndex));
324 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
327 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
332 // we'll count the number of ON/OFF for this pad, to insure
333 // consistency (i.e. if status changed during the run, we should
334 // at least notify this fact ;-) and hope it's not the norm)
340 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
342 if ( val->GetBool() )
352 if ( (nTrue>0 && nFalse>0) )
354 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
355 hvSwitch.Data(),nTrue,nFalse));
359 if ( nFalse ) hvSwitchON = kFALSE;
365 //_____________________________________________________________________________
367 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
369 /// Get HV status of one manu
373 if ( !fCalibrationData.HV() ) return kMissing;
375 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
379 return (Int_t)(lint - 1);
384 AliMpHVNamer hvNamer;
386 switch ( AliMpDEManager::GetStationType(detElemId) )
388 case AliMp::kStation1:
389 case AliMp::kStation2:
391 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
394 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
395 Bool_t error = HVSt12Status(detElemId,sector,
399 if ( error ) status |= kHVError;
400 if ( hvChannelTooLow ) status |= kHVTooLow;
401 if ( hvChannelTooHigh ) status |= kHVTooHigh;
402 if ( !hvChannelON ) status |= kHVChannelOFF;
403 // assign this status to all the other manus handled by the same HV channel
404 SetHVStatus(detElemId,sector,status);
408 case AliMp::kStation345:
410 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
413 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
414 Bool_t error = HVSt345Status(detElemId,pcbIndex,
415 hvChannelTooLow,hvChannelTooHigh,
416 hvChannelON,hvSwitchON);
417 if ( error ) status |= kHVError;
418 if ( hvChannelTooLow ) status |= kHVTooLow;
419 if ( hvChannelTooHigh ) status |= kHVTooHigh;
420 if ( !hvSwitchON ) status |= kHVSwitchOFF;
421 if ( !hvChannelON) status |= kHVChannelOFF;
422 // assign this status to all the other manus handled by the same HV channel
423 SetHVStatus(detElemId,pcbIndex,status);
434 //_____________________________________________________________________________
436 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
438 /// Get the neighbours parameters for a given manu
439 AliMUONVStore* neighbourStore = fCalibrationData.Neighbours();
440 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
443 //_____________________________________________________________________________
445 AliMUONPadStatusMaker::NeighboursStore() const
447 /// Return the store containing all the neighbours
448 return fCalibrationData.Neighbours();
451 //_____________________________________________________________________________
453 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
455 /// Compute the status of a given manu, using all available information,
456 /// i.e. pedestals, gains, and HV
458 // AliCodeTimerAuto("")
460 // AliCodeTimerStart("Param creation");
461 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
463 // AliCodeTimerStop("Param creation");
465 // AliCodeTimerStart("FindObject");
466 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
468 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
469 // AliCodeTimerStop("FindObject");
471 Int_t hvStatus = HVStatus(detElemId,manuId);
473 // AliCodeTimerStart("Loop");
475 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
481 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
482 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
483 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
484 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
485 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
486 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
487 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
491 pedStatus = kPedMissing;
498 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
499 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
500 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
502 if ( a0 < fGainA0Limits.X() ) gainStatus |= kGainA0TooLow;
503 else if ( a0 > fGainA0Limits.Y() ) gainStatus |= kGainA0TooHigh;
504 if ( a1 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
505 else if ( a1 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
506 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
507 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
511 gainStatus = kGainMissing;
514 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus);
516 param->SetValueAsIntFast(manuChannel,0,status);
519 // AliCodeTimerStop("Loop");
524 //_____________________________________________________________________________
526 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
528 /// Get the status for a given channel
530 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
533 // not already there, so compute it now
534 AliCodeTimerAuto("ComputeStatus");
535 param = ComputeStatus(detElemId,manuId);
540 //_____________________________________________________________________________
542 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
544 /// Get the status for a given channel
546 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
549 // not already there, so compute it now
550 param = ComputeStatus(detElemId,manuId);
552 return param->ValueAsInt(manuChannel,0);
555 //_____________________________________________________________________________
557 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
559 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
560 /// is different thing from St12 and St345)
564 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
566 const AliMpArrayI* manus = de->ManusForHV(index);
568 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
570 Int_t manuId = manus->GetValue(i);
571 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);