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()
159 //_____________________________________________________________________________
161 AliMUONPadStatusMaker::AsString(Int_t status)
163 /// return a human readable version of the integer status
170 DecodeStatus(status,pedStatus,hvStatus,gainStatus,otherStatus);
174 if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
175 if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
176 if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
177 if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
178 if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
179 if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
181 if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
182 if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
183 if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
184 if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
185 if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
186 if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
187 if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
189 if ( hvStatus & kHVError ) s+="& HV is on error ";
190 if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
191 if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
192 if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
193 if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
194 if ( hvStatus & kHVMissing ) s+="& HV is missing ";
196 if ( otherStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
197 if ( otherStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
198 if ( otherStatus & kKilled ) s+="& killed";
200 if ( s[0] == '&' ) s[0] = ' ';
205 //_____________________________________________________________________________
207 AliMUONPadStatusMaker::AsCondition(Int_t mask)
209 /// return a human readable version of the mask's equivalent condition
211 TString s(AsString(mask));
213 s.ReplaceAll("&","|");
218 //_____________________________________________________________________________
220 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus,
225 /// Build a complete status from specific parts (ped,hv,gain)
227 return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) |
228 ( ( gainStatus & 0xFF ) << 16 ) |
229 ( ( otherStatus & 0xFF ) << 24 ) ;
232 //_____________________________________________________________________________
234 AliMUONPadStatusMaker::DecodeStatus(Int_t status,
240 /// Decode complete status into specific parts (ped,hv,gain)
242 otherStatus = ( status & 0xFF000000 ) >> 24;
243 gainStatus = ( status & 0xFF0000 ) >> 16;
244 pedStatus = ( status & 0xFF00 ) >> 8;
245 hvStatus = (status & 0xFF);
248 //_____________________________________________________________________________
250 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
251 Bool_t& hvChannelTooLow,
252 Bool_t& hvChannelTooHigh,
253 Bool_t& hvChannelON) const
255 /// Get HV status for one HV sector of St12
257 /// For a given PCB in a given DE, get the HV status (both the channel
259 /// Returns false if hv switch changed during the run.
263 Bool_t error = kFALSE;
264 hvChannelTooLow = kFALSE;
265 hvChannelTooHigh = kFALSE;
268 AliMpDCSNamer hvNamer("TRACKER");
270 TString hvChannel(hvNamer.DCSChannelName(detElemId,sector));
272 TMap* hvMap = fkCalibrationData.HV();
273 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
276 AliError(Form("Did not find expected alias (%s) for DE %d",
277 hvChannel.Data(),detElemId));
282 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
285 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
290 // find out min and max value, and makes a cut
296 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
298 Float_t hv = val->GetFloat();
299 hvMin = TMath::Min(hv,hvMin);
300 hvMax = TMath::Max(hv,hvMax);
303 float lowThreshold = fHVSt12Limits.X();
304 float highThreshold = fHVSt12Limits.Y();
306 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
307 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
308 if ( hvMin < 1 ) hvChannelON = kFALSE;
315 //_____________________________________________________________________________
317 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
318 Bool_t& hvChannelTooLow,
319 Bool_t& hvChannelTooHigh,
321 Bool_t& hvSwitchON) const
323 /// For a given PCB in a given DE, get the HV status (both the channel
325 /// Returns false if something goes wrong (in particular if
326 /// hv switch changed during the run).
330 Bool_t error = kFALSE;
331 hvChannelTooLow = kFALSE;
332 hvChannelTooHigh = kFALSE;
336 AliMpDCSNamer hvNamer("TRACKER");
338 TString hvChannel(hvNamer.DCSChannelName(detElemId));
340 TMap* hvMap = fkCalibrationData.HV();
342 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
345 AliError(Form("Did not find expected alias (%s) for DE %d",
346 hvChannel.Data(),detElemId));
351 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
354 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
359 // find out min and max value, and makes a cut
365 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
367 Float_t hv = val->GetFloat();
368 hvMin = TMath::Min(hv,hvMin);
369 hvMax = TMath::Max(hv,hvMax);
372 float lowThreshold = fHVSt345Limits.X();
373 float highThreshold = fHVSt345Limits.Y();
375 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
376 else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
377 if ( hvMin < 1 ) hvChannelON = kFALSE;
381 TString hvSwitch(hvNamer.DCSSwitchName(detElemId,pcbIndex));
382 TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
385 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
386 hvSwitch.Data(),detElemId,pcbIndex));
391 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
394 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
399 // we'll count the number of ON/OFF for this pad, to insure
400 // consistency (i.e. if status changed during the run, we should
401 // at least notify this fact ;-) and hope it's not the norm)
407 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
409 if ( val->GetBool() )
419 if ( (nTrue>0 && nFalse>0) )
421 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
422 hvSwitch.Data(),nTrue,nFalse));
426 if ( nFalse ) hvSwitchON = kFALSE;
432 //_____________________________________________________________________________
434 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
436 /// Get HV status of one manu
440 if ( !fkCalibrationData.HV() ) return kMissing;
442 Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
446 return (Int_t)(lint - 1);
451 AliMpDCSNamer hvNamer("TRACKER");
453 switch ( AliMpDEManager::GetStationType(detElemId) )
455 case AliMp::kStation12:
457 int sector = hvNamer.ManuId2Sector(detElemId,manuId);
460 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
461 Bool_t error = HVSt12Status(detElemId,sector,
465 if ( error ) status |= kHVError;
466 if ( hvChannelTooLow ) status |= kHVTooLow;
467 if ( hvChannelTooHigh ) status |= kHVTooHigh;
468 if ( !hvChannelON ) status |= kHVChannelOFF;
469 // assign this status to all the other manus handled by the same HV channel
470 SetHVStatus(detElemId,sector,status);
474 case AliMp::kStation345:
476 int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
479 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
480 Bool_t error = HVSt345Status(detElemId,pcbIndex,
481 hvChannelTooLow,hvChannelTooHigh,
482 hvChannelON,hvSwitchON);
483 if ( error ) status |= kHVError;
484 if ( hvChannelTooLow ) status |= kHVTooLow;
485 if ( hvChannelTooHigh ) status |= kHVTooHigh;
486 if ( !hvSwitchON ) status |= kHVSwitchOFF;
487 if ( !hvChannelON) status |= kHVChannelOFF;
488 // assign this status to all the other manus handled by the same HV channel
489 SetHVStatus(detElemId,pcbIndex,status);
500 //_____________________________________________________________________________
502 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
504 /// Get the neighbours parameters for a given manu
505 AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
506 return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
509 //_____________________________________________________________________________
511 AliMUONPadStatusMaker::NeighboursStore() const
513 /// Return the store containing all the neighbours
514 return fkCalibrationData.Neighbours();
517 //_____________________________________________________________________________
519 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
521 /// Compute the status of a given manu, using all available information,
522 /// i.e. pedestals, gains, and HV
524 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
527 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
529 AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
531 AliMUONVCalibParam* kill(0x0);
535 kill = static_cast<AliMUONVCalibParam*>(fKillMap->FindObject(detElemId,manuId));
538 Int_t hvStatus = HVStatus(detElemId,manuId);
540 Int_t otherStatus = OtherStatus(detElemId,manuId);
542 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
548 Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
549 Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
550 if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
551 else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
552 if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
553 else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
554 if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
558 pedStatus = kPedMissing;
565 Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
566 Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
567 Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
569 if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
570 else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
571 if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
572 else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
573 if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
574 else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
578 gainStatus = kGainMissing;
581 if ( kill && (kill->ValueAsInt(manuChannel,0) > 0) )
583 otherStatus |= kKilled;
586 Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,otherStatus);
588 param->SetValueAsIntFast(manuChannel,0,status);
594 //_____________________________________________________________________________
596 AliMUONPadStatusMaker::OtherStatus(Int_t detElemId, Int_t manuId) const
598 /// Get the "other" status for a given manu
601 Double_t occ = fTrackerData->Manu(detElemId,manuId,2);
602 if ( occ < fManuOccupancyLimits.X() )
604 return kManuOccupancyTooLow;
606 if ( occ > fManuOccupancyLimits.Y() )
608 return kManuOccupancyTooHigh;
614 //_____________________________________________________________________________
616 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
618 /// Get the status container for a given manu
620 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
623 // not already there, so compute it now
624 AliCodeTimerAuto("ComputeStatus");
625 param = ComputeStatus(detElemId,manuId);
630 //_____________________________________________________________________________
632 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
634 /// Get the status for a given channel
636 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
639 // not already there, so compute it now
640 param = ComputeStatus(detElemId,manuId);
642 return param->ValueAsInt(manuChannel,0);
645 //_____________________________________________________________________________
647 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
649 /// Assign status to all manus in a given HV "zone" (defined by index, meaning
650 /// is different thing from St12 and St345)
654 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
656 const AliMpArrayI* manus = de->ManusForHV(index);
658 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
660 Int_t manuId = manus->GetValue(i);
661 fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);