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 "AliMpDCSNamer.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 : fkCalibrationData(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()),
84 fKillMap(calibData.KillMap())
87 AliDebug(1,Form("ped store %s gain store %s",
88 fPedestals->ClassName(),
89 fGains->ClassName()));
91 TString qaFileName(AliQAv1::GetQADataFileName("MUON",calibData.RunNumber()));
93 // search the QA file in memory first.
94 TFile* f = static_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(qaFileName.Data()));
98 // then tries to open it
99 if ( gSystem->AccessPathName(qaFileName.Data()) == kFALSE )
101 f = TFile::Open(qaFileName.Data());
104 AliDebug(1,Form("Got %s from disk",qaFileName.Data()));
110 AliDebug(1,Form("Got %s from memory",qaFileName.Data()));
115 TDirectory* d = gDirectory;
119 TIter next(gDirectory->GetListOfKeys());
122 while ( ( key = static_cast<TKey*>(next()) ) && !fTrackerData )
124 TString name(key->GetName());
126 if ( name.Contains("CALZ") )
128 fTrackerData = dynamic_cast<AliMUONVTrackerData*>(key->ReadObj());
137 AliInfo(Form("Will make a cut on MANU occupancy from TrackerData=%s",fTrackerData->GetName()));
141 AliWarning(Form("Found a QA file = %s, but could not get the expected TrackerData in there... (probably not a serious problem though)",
147 AliWarning("Did not find QA file, so will not use manu occupancy as a criteria");
151 //_____________________________________________________________________________
152 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
160 //_____________________________________________________________________________
162 AliMUONPadStatusMaker::AsString(Int_t status)
164 /// return a human readable version of the integer status
171 DecodeStatus(status,pedStatus,hvStatus,gainStatus,otherStatus);
175 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
176 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
177 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
178 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
179 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
180 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
182 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
183 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
184 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
185 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
186 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
187 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
188 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
190 if ( hvStatus & kHVError ) s+="& HV is on error ";
191 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
192 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
193 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
194 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
195 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
197 if ( otherStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
198 if ( otherStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
199 if ( otherStatus & kKilled ) s+="& killed";
201 if ( s[0] == '&' ) s[0] = ' ';
206 //_____________________________________________________________________________
208 AliMUONPadStatusMaker::AsCondition(Int_t mask)
210 /// return a human readable version of the mask's equivalent condition
212 TString s(AsString(mask));
214 s.ReplaceAll("&","|");
219 //_____________________________________________________________________________
221 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
226 /// Build a complete status from specific parts (ped,hv,gain)
228 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
229 ( ( gainStatus & 0xFF ) << 16 ) |
230 ( ( otherStatus & 0xFF ) << 24 ) ;
233 //_____________________________________________________________________________
235 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
241 /// Decode complete status into specific parts (ped,hv,gain)
243 otherStatus = ( status & 0xFF000000 ) >> 24;
244 gainStatus = ( status & 0xFF0000 ) >> 16;
245 pedStatus = ( status & 0xFF00 ) >> 8;
246 hvStatus = (status & 0xFF);
249 //_____________________________________________________________________________
251 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
252 Bool_t& hvChannelTooLow,
253 Bool_t& hvChannelTooHigh,
254 Bool_t& hvChannelON) const
256 /// Get HV status for one HV sector of St12
258 /// For a given PCB in a given DE, get the HV status (both the channel
260 /// Returns false if hv switch changed during the run.
264 Bool_t error = kFALSE;
265 hvChannelTooLow = kFALSE;
266 hvChannelTooHigh = kFALSE;
269 AliMpDCSNamer hvNamer("TRACKER");
271 TString hvChannel(hvNamer.DCSChannelName(detElemId,sector));
273 TMap* hvMap = fkCalibrationData.HV();
274 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
277 AliError(Form("Did not find expected alias (%s) for DE %d",
278 hvChannel.Data(),detElemId));
283 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
286 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
291 // find out min and max value, and makes a cut
297 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
299 Float_t hv = val->GetFloat();
300 hvMin = TMath::Min(hv,hvMin);
301 hvMax = TMath::Max(hv,hvMax);
304 float lowThreshold = fHVSt12Limits.X();
305 float highThreshold = fHVSt12Limits.Y();
307 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
308 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
309 if ( hvMin < 1 ) hvChannelON = kFALSE;
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).
331 Bool_t error = kFALSE;
332 hvChannelTooLow = kFALSE;
333 hvChannelTooHigh = kFALSE;
337 AliMpDCSNamer hvNamer("TRACKER");
339 TString hvChannel(hvNamer.DCSChannelName(detElemId));
341 TMap* hvMap = fkCalibrationData.HV();
343 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
346 AliError(Form("Did not find expected alias (%s) for DE %d",
347 hvChannel.Data(),detElemId));
352 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
355 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
360 // find out min and max value, and makes a cut
366 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
368 Float_t hv = val->GetFloat();
369 hvMin = TMath::Min(hv,hvMin);
370 hvMax = TMath::Max(hv,hvMax);
373 float lowThreshold = fHVSt345Limits.X();
374 float highThreshold = fHVSt345Limits.Y();
376 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
377 else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
378 if ( hvMin < 1 ) hvChannelON = kFALSE;
382 TString hvSwitch(hvNamer.DCSSwitchName(detElemId,pcbIndex));
383 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
386 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
387 hvSwitch.Data(),detElemId,pcbIndex));
392 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
395 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
400 // we'll count the number of ON/OFF for this pad, to insure
401 // consistency (i.e. if status changed during the run, we should
402 // at least notify this fact ;-) and hope it's not the norm)
408 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
410 if ( val->GetBool() )
420 if ( (nTrue>0 && nFalse>0) )
422 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
423 hvSwitch.Data(),nTrue,nFalse));
427 if ( nFalse ) hvSwitchON = kFALSE;
433 //_____________________________________________________________________________
435 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
437 /// Get HV status of one manu
441 if ( !fkCalibrationData.HV() ) return kMissing;
443 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
447 return (Int_t)(lint - 1);
452 AliMpDCSNamer hvNamer("TRACKER");
454 switch ( AliMpDEManager::GetStationType(detElemId) )
456 case AliMp::kStation12:
458 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
461 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
462 Bool_t error = HVSt12Status(detElemId,sector,
466 if ( error ) status |= kHVError;
467 if ( hvChannelTooLow ) status |= kHVTooLow;
468 if ( hvChannelTooHigh ) status |= kHVTooHigh;
469 if ( !hvChannelON ) status |= kHVChannelOFF;
470 // assign this status to all the other manus handled by the same HV channel
471 SetHVStatus(detElemId,sector,status);
475 case AliMp::kStation345:
477 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
480 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
481 Bool_t error = HVSt345Status(detElemId,pcbIndex,
482 hvChannelTooLow,hvChannelTooHigh,
483 hvChannelON,hvSwitchON);
484 if ( error ) status |= kHVError;
485 if ( hvChannelTooLow ) status |= kHVTooLow;
486 if ( hvChannelTooHigh ) status |= kHVTooHigh;
487 if ( !hvSwitchON ) status |= kHVSwitchOFF;
488 if ( !hvChannelON) status |= kHVChannelOFF;
489 // assign this status to all the other manus handled by the same HV channel
490 SetHVStatus(detElemId,pcbIndex,status);
501 //_____________________________________________________________________________
503 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
505 /// Get the neighbours parameters for a given manu
506 AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
507 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
510 //_____________________________________________________________________________
512 AliMUONPadStatusMaker::NeighboursStore() const
514 /// Return the store containing all the neighbours
515 return fkCalibrationData.Neighbours();
518 //_____________________________________________________________________________
520 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
522 /// Compute the status of a given manu, using all available information,
523 /// i.e. pedestals, gains, and HV
525 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
528 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
530 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
532 AliMUONVCalibParam* kill(0x0);
536 kill = static_cast<AliMUONVCalibParam*>(fKillMap->FindObject(detElemId,manuId));
539 Int_t hvStatus = HVStatus(detElemId,manuId);
541 Int_t otherStatus = OtherStatus(detElemId,manuId);
543 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
549 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
550 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
551 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
552 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
553 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
554 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
555 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
559 pedStatus = kPedMissing;
566 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
567 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
568 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
570 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
571 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
572 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
573 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
574 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
575 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
579 gainStatus = kGainMissing;
582 if ( kill && (kill->ValueAsInt(manuChannel,0) > 0) )
584 otherStatus |= kKilled;
587 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,otherStatus);
589 param->SetValueAsIntFast(manuChannel,0,status);
595 //_____________________________________________________________________________
597 AliMUONPadStatusMaker::OtherStatus(Int_t detElemId, Int_t manuId) const
599 /// Get the "other" status for a given manu
602 Double_t occ = fTrackerData->Manu(detElemId,manuId,2);
603 if ( occ < fManuOccupancyLimits.X() )
605 return kManuOccupancyTooLow;
607 if ( occ > fManuOccupancyLimits.Y() )
609 return kManuOccupancyTooHigh;
615 //_____________________________________________________________________________
617 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
619 /// Get the status container for a given manu
621 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
624 // not already there, so compute it now
625 AliCodeTimerAuto("ComputeStatus");
626 param = ComputeStatus(detElemId,manuId);
631 //_____________________________________________________________________________
633 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
635 /// Get the status for a given channel
637 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
640 // not already there, so compute it now
641 param = ComputeStatus(detElemId,manuId);
643 return param->ValueAsInt(manuChannel,0);
646 //_____________________________________________________________________________
648 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
650 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
651 /// is different thing from St12 and St345)
655 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
657 const AliMpArrayI* manus = de->ManusForHV(index);
659 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
661 Int_t manuId = manus->GetValue(i);
662 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);