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"
31 #include "AliMUON2DMap.h"
32 #include "AliMUON2DStoreValidator.h"
33 #include "AliMUONCalibParamNI.h"
34 #include "AliMUONCalibrationData.h"
35 #include "AliMUONStringIntMap.h"
36 #include "AliMUONVCalibParam.h"
37 #include "AliMUONVTrackerData.h"
39 #include "AliMpArea.h"
40 #include "AliMpArrayI.h"
41 #include "AliMpConstants.h"
42 #include "AliMpDDLStore.h"
43 #include "AliMpDEManager.h"
44 #include "AliMpDetElement.h"
45 #include "AliMpHVNamer.h"
46 #include "AliMpManuUID.h"
48 #include "AliCDBEntry.h"
49 #include "AliCDBManager.h"
50 #include "AliCodeTimer.h"
51 #include "AliDCSValue.h"
54 #include <Riostream.h>
65 ClassImp(AliMUONPadStatusMaker)
68 //_____________________________________________________________________________
69 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
70 : fCalibrationData(calibData),
71 fGainA1Limits(0,1E30),
72 fGainA2Limits(-1E-30,1E30),
73 fGainThresLimits(0,4095),
74 fHVSt12Limits(0,5000),
75 fHVSt345Limits(0,5000),
76 fPedMeanLimits(0,4095),
77 fPedSigmaLimits(0,4095),
78 fManuOccupancyLimits(0,0.1),
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 TString qaFileName(AliQA::GetQADataFileName("MUON",calibData.RunNumber()));
92 // search the QA file in memory first.
93 TFile* f = static_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(qaFileName.Data()));
97 // then tries to open it
98 if ( gSystem->AccessPathName(qaFileName.Data()) == kFALSE )
100 f = TFile::Open(qaFileName.Data());
103 AliDebug(1,Form("Got %s from disk",qaFileName.Data()));
109 AliDebug(1,Form("Got %s from memory",qaFileName.Data()));
114 TDirectory* d = gDirectory;
118 TIter next(gDirectory->GetListOfKeys());
121 while ( ( key = static_cast<TKey*>(next()) ) && !fTrackerData )
123 TString name(key->GetName());
125 if ( name.Contains("CALZ") )
127 fTrackerData = dynamic_cast<AliMUONVTrackerData*>(key->ReadObj());
136 AliInfo(Form("Will make a cut on MANU occupancy from TrackerData=%s",fTrackerData->GetName()));
140 AliWarning(Form("Found a QA file = %s, but could not get the expected TrackerData in there... (probably not a serious problem though)",
146 AliWarning("Did not find QA file, so will not use manu occupancy as a criteria");
150 //_____________________________________________________________________________
151 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
158 //_____________________________________________________________________________
160 AliMUONPadStatusMaker::AsString(Int_t status)
162 /// return a human readable version of the integer status
169 DecodeStatus(status,pedStatus,hvStatus,gainStatus,otherStatus);
173 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
174 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
175 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
176 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
177 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
178 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
180 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
181 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
182 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
183 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
184 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
185 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
186 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
188 if ( hvStatus & kHVError ) s+="& HV is on error ";
189 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
190 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
191 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
192 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
193 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
195 if ( otherStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
196 if ( otherStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
198 if ( s[0] == '&' ) s[0] = ' ';
203 //_____________________________________________________________________________
205 AliMUONPadStatusMaker::AsCondition(Int_t mask)
207 /// return a human readable version of the mask's equivalent condition
209 TString s(AsString(mask));
211 s.ReplaceAll("&","|");
216 //_____________________________________________________________________________
218 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
223 /// Build a complete status from specific parts (ped,hv,gain)
225 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
226 ( ( gainStatus & 0xFF ) << 16 ) |
227 ( ( otherStatus & 0xFF ) << 24 ) ;
230 //_____________________________________________________________________________
232 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
238 /// Decode complete status into specific parts (ped,hv,gain)
240 otherStatus = ( status & 0xFF000000 ) >> 24;
241 gainStatus = ( status & 0xFF0000 ) >> 16;
242 pedStatus = ( status & 0xFF00 ) >> 8;
243 hvStatus = (status & 0xFF);
246 //_____________________________________________________________________________
248 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
249 Bool_t& hvChannelTooLow,
250 Bool_t& hvChannelTooHigh,
251 Bool_t& hvChannelON) const
253 /// Get HV status for one HV sector of St12
255 /// For a given PCB in a given DE, get the HV status (both the channel
257 /// Returns false if hv switch changed during the run.
261 Bool_t error = kFALSE;
262 hvChannelTooLow = kFALSE;
263 hvChannelTooHigh = kFALSE;
266 AliMpHVNamer hvNamer;
268 TString hvChannel(hvNamer.DCSHVChannelName(detElemId,sector));
270 TMap* hvMap = fCalibrationData.HV();
271 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
274 AliError(Form("Did not find expected alias (%s) for DE %d",
275 hvChannel.Data(),detElemId));
280 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
283 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
288 // find out min and max value, and makes a cut
294 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
296 Float_t hv = val->GetFloat();
297 hvMin = TMath::Min(hv,hvMin);
298 hvMax = TMath::Max(hv,hvMax);
301 float lowThreshold = fHVSt12Limits.X();
302 float highThreshold = fHVSt12Limits.Y();
304 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
305 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
306 if ( hvMin < 1 ) hvChannelON = kFALSE;
313 //_____________________________________________________________________________
315 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
316 Bool_t& hvChannelTooLow,
317 Bool_t& hvChannelTooHigh,
319 Bool_t& hvSwitchON) const
321 /// For a given PCB in a given DE, get the HV status (both the channel
323 /// Returns false if something goes wrong (in particular if
324 /// hv switch changed during the run).
328 Bool_t error = kFALSE;
329 hvChannelTooLow = kFALSE;
330 hvChannelTooHigh = kFALSE;
334 AliMpHVNamer hvNamer;
336 TString hvChannel(hvNamer.DCSHVChannelName(detElemId));
338 TMap* hvMap = fCalibrationData.HV();
340 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
343 AliError(Form("Did not find expected alias (%s) for DE %d",
344 hvChannel.Data(),detElemId));
349 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
352 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
357 // find out min and max value, and makes a cut
363 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
365 Float_t hv = val->GetFloat();
366 hvMin = TMath::Min(hv,hvMin);
367 hvMax = TMath::Max(hv,hvMax);
370 float lowThreshold = fHVSt345Limits.X();
371 float highThreshold = fHVSt345Limits.Y();
373 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
374 else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
375 if ( hvMin < 1 ) hvChannelON = kFALSE;
379 TString hvSwitch(hvNamer.DCSHVSwitchName(detElemId,pcbIndex));
380 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
383 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
384 hvSwitch.Data(),detElemId,pcbIndex));
389 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
392 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
397 // we'll count the number of ON/OFF for this pad, to insure
398 // consistency (i.e. if status changed during the run, we should
399 // at least notify this fact ;-) and hope it's not the norm)
405 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
407 if ( val->GetBool() )
417 if ( (nTrue>0 && nFalse>0) )
419 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
420 hvSwitch.Data(),nTrue,nFalse));
424 if ( nFalse ) hvSwitchON = kFALSE;
430 //_____________________________________________________________________________
432 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
434 /// Get HV status of one manu
438 if ( !fCalibrationData.HV() ) return kMissing;
440 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
444 return (Int_t)(lint - 1);
449 AliMpHVNamer hvNamer;
451 switch ( AliMpDEManager::GetStationType(detElemId) )
453 case AliMp::kStation1:
454 case AliMp::kStation2:
456 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
459 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
460 Bool_t error = HVSt12Status(detElemId,sector,
464 if ( error ) status |= kHVError;
465 if ( hvChannelTooLow ) status |= kHVTooLow;
466 if ( hvChannelTooHigh ) status |= kHVTooHigh;
467 if ( !hvChannelON ) status |= kHVChannelOFF;
468 // assign this status to all the other manus handled by the same HV channel
469 SetHVStatus(detElemId,sector,status);
473 case AliMp::kStation345:
475 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
478 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
479 Bool_t error = HVSt345Status(detElemId,pcbIndex,
480 hvChannelTooLow,hvChannelTooHigh,
481 hvChannelON,hvSwitchON);
482 if ( error ) status |= kHVError;
483 if ( hvChannelTooLow ) status |= kHVTooLow;
484 if ( hvChannelTooHigh ) status |= kHVTooHigh;
485 if ( !hvSwitchON ) status |= kHVSwitchOFF;
486 if ( !hvChannelON) status |= kHVChannelOFF;
487 // assign this status to all the other manus handled by the same HV channel
488 SetHVStatus(detElemId,pcbIndex,status);
499 //_____________________________________________________________________________
501 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
503 /// Get the neighbours parameters for a given manu
504 AliMUONVStore* neighbourStore = fCalibrationData.Neighbours();
505 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
508 //_____________________________________________________________________________
510 AliMUONPadStatusMaker::NeighboursStore() const
512 /// Return the store containing all the neighbours
513 return fCalibrationData.Neighbours();
516 //_____________________________________________________________________________
518 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
520 /// Compute the status of a given manu, using all available information,
521 /// i.e. pedestals, gains, and HV
523 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
526 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
528 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
530 Int_t hvStatus = HVStatus(detElemId,manuId);
532 Int_t otherStatus = OtherStatus(detElemId,manuId);
534 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
540 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
541 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
542 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
543 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
544 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
545 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
546 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
550 pedStatus = kPedMissing;
557 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
558 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
559 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
561 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
562 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
563 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
564 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
565 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
566 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
570 gainStatus = kGainMissing;
573 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,otherStatus);
575 param->SetValueAsIntFast(manuChannel,0,status);
581 //_____________________________________________________________________________
583 AliMUONPadStatusMaker::OtherStatus(Int_t detElemId, Int_t manuId) const
585 /// Get the "other" status for a given manu
588 Double_t occ = fTrackerData->Manu(detElemId,manuId,2);
589 if ( occ < fManuOccupancyLimits.X() )
591 return kManuOccupancyTooLow;
593 if ( occ > fManuOccupancyLimits.Y() )
595 return kManuOccupancyTooHigh;
601 //_____________________________________________________________________________
603 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
605 /// Get the status container for a given manu
607 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
610 // not already there, so compute it now
611 AliCodeTimerAuto("ComputeStatus");
612 param = ComputeStatus(detElemId,manuId);
617 //_____________________________________________________________________________
619 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
621 /// Get the status for a given channel
623 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
626 // not already there, so compute it now
627 param = ComputeStatus(detElemId,manuId);
629 return param->ValueAsInt(manuChannel,0);
632 //_____________________________________________________________________________
634 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
636 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
637 /// is different thing from St12 and St345)
641 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
643 const AliMpArrayI* manus = de->ManusForHV(index);
645 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
647 Int_t manuId = manus->GetValue(i);
648 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);