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 **************************************************************************/
17 /// \class AliMUONPadStatusMaker
19 /// Make a 2DStore of pad statuses, using different sources of information,
20 /// like pedestal values, gain values, and HV values.
23 // Author Laurent Aphecetche
25 #include "AliMUONPadStatusMaker.h"
27 #include "AliMUON2DMap.h"
28 #include "AliMUONCalibParam1I.h"
29 #include "AliMUONCalibrationData.h"
30 #include "AliMUONHVNamer.h"
31 #include "AliMUONObjectPair.h"
32 #include "AliMUONVCalibParam.h"
33 #include "AliMUONVDataIterator.h"
35 #include "AliMpArea.h"
36 #include "AliMpDEIterator.h"
37 #include "AliMpDEManager.h"
38 #include "AliMpIntPair.h"
39 #include "AliMpManuList.h"
40 #include "AliMpMotifMap.h"
41 #include "AliMpMotifPosition.h"
44 #include "AliMpSector.h"
45 #include "AliMpSectorSegmentation.h"
46 #include "AliMpSegmentation.h"
47 #include "AliMpSlat.h"
48 #include "AliMpSlatSegmentation.h"
49 #include "AliMpStationType.h"
50 #include "AliMpVPadIterator.h"
51 #include "AliMUON2DStoreValidator.h"
52 #include "AliCDBManager.h"
53 #include "AliCDBEntry.h"
54 #include "AliDCSValue.h"
57 #include "Riostream.h"
59 #include "TStopwatch.h"
64 ClassImp(AliMUONPadStatusMaker)
66 //_____________________________________________________________________________
67 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
68 : fCalibrationData(calibData),
69 fPedMeanLimits(0,4095),
70 fPedSigmaLimits(0,4095),
71 fHVSt12Limits(0,5000),
72 fHVSt345Limits(0,5000)
77 //_____________________________________________________________________________
78 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
83 //_____________________________________________________________________________
85 AliMUONPadStatusMaker::Combine(const AliMUONV2DStore& store1,
86 const AliMUONV2DStore& store2,
89 /// Combine two status containers into one, shifting store2 status bits
90 /// to the left by binShift before making an OR with store1.
95 AliMUONV2DStore* combined = static_cast<AliMUONV2DStore*>(store1.Clone());
97 AliMUONVDataIterator* it = store1.Iterator();
98 AliMUONObjectPair* pair;
100 while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
102 AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
103 Int_t detElemId = ip->GetFirst();
104 Int_t manuId = ip->GetSecond();
105 AliMUONVCalibParam* param1 = static_cast<AliMUONVCalibParam*>(store1.Get(detElemId,manuId));
106 AliMUONVCalibParam* param2 = static_cast<AliMUONVCalibParam*>(store2.Get(detElemId,manuId));
109 AliWarning(Form("Could not get statuses for store2 for DE %d ManuId %d. Marking as missing.",
111 param2 = static_cast<AliMUONVCalibParam*>(param1->Clone());
112 for ( Int_t manuChannel = 0; manuChannel < param2->Size(); ++manuChannel )
114 param2->SetValueAsInt(manuChannel,0,kMissing);
117 AliMUONVCalibParam* paramCombined = static_cast<AliMUONVCalibParam*>(combined->Get(detElemId,manuId));
120 paramCombined = static_cast<AliMUONVCalibParam*>(param2->Clone());
121 combined->Set(detElemId,manuId,paramCombined,kFALSE);
124 for ( Int_t manuChannel = 0; manuChannel < param1->Size(); ++manuChannel )
126 if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
128 Int_t status1(param1->ValueAsInt(manuChannel));
129 Int_t status2(param2->ValueAsInt(manuChannel));
131 Int_t status = status1 | (status2 << binShift);
133 paramCombined->SetValueAsInt(manuChannel,0,status);
141 StdoutToAliInfo(timer.Print(););
146 //_____________________________________________________________________________
148 AliMUONPadStatusMaker::GeneratePadStatus(Int_t value)
150 /// Generate a "fake" store, with all (detElemId,manuId) present,
151 /// and containing all the same value
153 AliMUONCalibParam1I param(64,value);
155 return AliMUON2DMap::Generate(param);
158 //_____________________________________________________________________________
160 AliMUONPadStatusMaker::GetSt12Status(const TMap& hvMap,
161 Int_t detElemId, Int_t sector,
162 Bool_t& hvChannelTooLow,
163 Bool_t& hvChannelTooHigh,
164 Bool_t& hvChannelON) const
166 /// Get HV status for one HV sector of St12
168 /// For a given PCB in a given DE, get the HV status (both the channel
170 /// Returns false if hv switch changed during the run.
172 Bool_t error = kFALSE;
173 hvChannelTooLow = kFALSE;
174 hvChannelTooHigh = kFALSE;
177 AliMUONHVNamer hvNamer;
179 TString hvChannel(hvNamer.DCSHVChannelName(detElemId,sector));
181 TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
184 AliError(Form("Did not find expected alias (%s) for DE %d",
185 hvChannel.Data(),detElemId));
190 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
193 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
198 // find out min and max value, and makes a cut
204 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
206 Float_t hv = val->GetFloat();
207 hvMin = TMath::Min(hv,hvMin);
208 hvMax = TMath::Max(hv,hvMax);
211 float lowThreshold = fHVSt12Limits.X();
212 float highThreshold = fHVSt12Limits.Y();
214 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
215 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
216 if ( hvMin < 1 ) hvChannelON = kFALSE;
223 //_____________________________________________________________________________
225 AliMUONPadStatusMaker::GetSt345Status(const TMap& hvMap,
226 Int_t detElemId, Int_t pcbIndex,
227 Bool_t& hvChannelTooLow,
228 Bool_t& hvChannelTooHigh,
230 Bool_t& hvSwitchON) const
232 /// For a given PCB in a given DE, get the HV status (both the channel
234 /// Returns false if something goes wrong (in particular if
235 /// hv switch changed during the run).
237 Bool_t error = kFALSE;
238 hvChannelTooLow = kFALSE;
239 hvChannelTooHigh = kFALSE;
243 AliMUONHVNamer hvNamer;
245 TString hvChannel(hvNamer.DCSHVChannelName(detElemId));
247 TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
250 AliError(Form("Did not find expected alias (%s) for DE %d",
251 hvChannel.Data(),detElemId));
256 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
259 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
264 // find out min and max value, and makes a cut
270 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
272 Float_t hv = val->GetFloat();
273 hvMin = TMath::Min(hv,hvMin);
274 hvMax = TMath::Max(hv,hvMax);
277 float lowThreshold = fHVSt345Limits.X();
278 float highThreshold = fHVSt345Limits.Y();
280 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
281 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
282 if ( hvMin < 1 ) hvChannelON = kFALSE;
286 TString hvSwitch(hvNamer.DCSHVSwitchName(detElemId,pcbIndex));
287 TPair* switchPair = static_cast<TPair*>(hvMap.FindObject(hvSwitch.Data()));
290 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
291 hvSwitch.Data(),detElemId,pcbIndex));
296 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
299 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
304 // we'll count the number of ON/OFF for this pad, to insure
305 // consistency (i.e. if status changed during the run, we should
306 // at least notify this fact ;-) and hope it's not the norm)
312 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
314 if ( val->GetBool() )
324 if ( (nTrue>0 && nFalse>0) )
326 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
327 hvSwitch.Data(),nTrue,nFalse));
331 if ( nFalse ) hvSwitchON = kFALSE;
337 //_____________________________________________________________________________
339 AliMUONPadStatusMaker::MakeGainStatus(const AliMUONV2DStore& /*gainValues*/) const
341 /// FIXME: to be implemented
342 AliWarning("Not implemented yet");
346 //_____________________________________________________________________________
348 AliMUONPadStatusMaker::MakeHVStatus(const TMap& hvValues) const
350 /// Scrutinize HV values and deduce an HV status for each pad
352 TStopwatch timerSt12;
353 TStopwatch timerSt345;
355 timerSt12.Start(kTRUE);
357 timerSt345.Start(kTRUE);
360 AliMUONHVNamer hvNamer;
362 AliMpDEIterator deIt;
366 AliMUONV2DStore* hv = new AliMUON2DMap(kTRUE);
368 while ( !deIt.IsDone() )
370 Int_t detElemId = deIt.CurrentDEId();
372 switch ( AliMpDEManager::GetStationType(detElemId) )
374 case AliMp::kStation1:
375 case AliMp::kStation2:
376 timerSt12.Start(kFALSE);
377 for ( int sector = 0; sector < 3; ++sector)
379 AliDebug(1,Form("detElemId %5d sector %d",detElemId,sector));
381 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
382 Bool_t error = GetSt12Status(hvValues,
384 hvChannelTooLow,hvChannelTooHigh,
387 if ( error ) status |= kHVError;
388 if ( hvChannelTooLow ) status |= kHVTooLow;
389 if ( hvChannelTooHigh ) status |= kHVTooHigh;
390 if ( !hvChannelON ) status |= kHVChannelOFF;
391 SetStatusSt12(*hv,detElemId,sector,status);
396 case AliMp::kStation345:
398 timerSt345.Start(kFALSE);
399 for ( Int_t pcbIndex = 0; pcbIndex < hvNamer.NumberOfPCBs(detElemId); ++pcbIndex)
401 AliDebug(1,Form("detElemId %5d pcbIndex %d",detElemId,pcbIndex));
402 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
403 Bool_t error = GetSt345Status(hvValues,
405 hvChannelTooLow,hvChannelTooHigh,
406 hvChannelON,hvSwitchON);
408 if ( error ) status |= kHVError;
409 if ( hvChannelTooLow ) status |= kHVTooLow;
410 if ( hvChannelTooHigh ) status |= kHVTooHigh;
411 if ( !hvSwitchON ) status |= kHVSwitchOFF;
412 if ( !hvChannelON) status |= kHVChannelOFF;
413 SetStatusSt345(*hv,detElemId,pcbIndex,status);
424 AliInfo("St12 timer:");
425 StdoutToAliInfo(timerSt12.Print(););
426 AliInfo("St345 timer:");
427 StdoutToAliInfo(timerSt345.Print(););
432 //_____________________________________________________________________________
434 AliMUONPadStatusMaker::MakePedestalStatus(const AliMUONV2DStore& pedValues) const
436 /// Assign a pedestal status to each pad
442 AliMUONV2DStore* pedStatuses = new AliMUON2DMap(kTRUE);
444 AliMUONVDataIterator* it = pedValues.Iterator();
445 AliMUONObjectPair* pair;
448 while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
450 AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
451 Int_t detElemId = ip->GetFirst();
452 Int_t manuId = ip->GetSecond();
453 AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(pair->Second());
455 for ( Int_t manuChannel = 0; manuChannel < pedestals->Size(); ++manuChannel )
458 if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
460 Float_t pedMean = pedestals->ValueAsFloat(manuChannel,0);
461 Float_t pedSigma = pedestals->ValueAsFloat(manuChannel,1);
462 if ( pedMean < fPedMeanLimits.X() ) status |= kPedMeanTooLow;
463 if ( pedMean > fPedMeanLimits.Y() ) status |= kPedMeanTooHigh;
464 if ( pedSigma < fPedSigmaLimits.X() ) status |= kPedSigmaTooLow;
465 if ( pedSigma > fPedSigmaLimits.Y() ) status |= kPedSigmaTooHigh;
466 if ( pedMean == 0 ) status |= kPedMeanZero;
468 AliMUONVCalibParam* vStatus =
469 static_cast<AliMUONVCalibParam*>(pedStatuses->Get(detElemId,manuId));
472 vStatus = new AliMUONCalibParam1I(64,0);
473 pedStatuses->Set(detElemId,manuId,vStatus,false);
475 vStatus->SetValueAsInt(manuChannel,0,status);
480 AliInfo(Form("%d manus checked in :",nofManus));
481 StdoutToAliInfo(timer.Print(););
485 //_____________________________________________________________________________
487 AliMUONPadStatusMaker::MakeStatus() const
489 /// Read ped, gains and hv values from CDB, apply some Q&A and produces
490 /// a combined status for each pad.
492 TMap* hvValues = fCalibrationData.HV();
493 AliMUONV2DStore* hvStatus(0x0);
497 AliError("Could not get HV values from CDB. Will create dummy ones and mark those as missing");
498 AliMUONCalibParam1I param(64,kHVMissing);
499 hvStatus = AliMUON2DMap::Generate(param);
503 hvStatus = MakeHVStatus(*hvValues);
506 AliMUONV2DStore* pedValues = fCalibrationData.Pedestals();
507 AliMUONV2DStore* pedStatus(0x0);
511 AliError("Could not get pedestals values from CDB. Will create dummy ones and mark those as missing");
512 AliMUONCalibParam1I param(64,kPedMissing);
513 pedStatus = AliMUON2DMap::Generate(param);
517 pedStatus = MakePedestalStatus(*pedValues);
520 // FIXME: should do the same for gains as for hv and ped.
522 AliMUONV2DStore* status = Combine(*hvStatus,*pedStatus,8);
527 // Insure we get all channels there (some or even all can be bad, but they
528 // must be there somehow).
530 AliMUON2DStoreValidator validator;
532 TObjArray* a = validator.Validate(*status);
536 // this should not happen.
537 AliError("Status store not complete. Crash to follow soon...");
538 StdoutToAliError(a->Print(););
539 AliFatal("this should not happen at all!");
547 //_____________________________________________________________________________
549 AliMUONPadStatusMaker::SetStatusSt12(AliMUONV2DStore& hvStatus,
554 /// Flag all pads of detElemId (for St12) as bad.
556 // FIXME: need a way to iterator on pads over a given HV sector for St12...
557 // we currently suppose that one sector is about a third of the chamber...
558 // FIXME !! This has to be checked very carefully...
560 const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
562 for ( Int_t icathode = 0; icathode < 2; ++icathode )
564 const AliMpSectorSegmentation* seg =
565 static_cast<const AliMpSectorSegmentation*>(AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
566 const AliMpSector* sector = seg->GetSector();
567 AliMpMotifMap* mMap = sector->GetMotifMap();
570 mMap->GetAllMotifPositionsIDs(a);
572 TVector2 dim = seg->Dimensions();
573 Double_t x = dim.X()*2;
574 Double_t xmin = isector*x/3.0;
575 Double_t xmax = xmin + x/3.0;
577 for ( Int_t i = 0; i < a.GetSize(); ++i )
579 AliMpMotifPosition* pos = mMap->FindMotifPosition(a[i]);
580 Int_t manuId = pos->GetID();
581 TVector2 position = pos->Position();
582 if ( position.X() >= xmin && position.X() <= xmax)
584 AliMUONVCalibParam* dead =
585 static_cast<AliMUONVCalibParam*>(hvStatus.Get(detElemId,manuId));
588 dead = new AliMUONCalibParam1I(64,status);
589 hvStatus.Set(detElemId,manuId,dead,false);
593 // FIXME: this should really not happen, if we'd know really the
594 // relationship between manuId and HV sector...
595 // For the time being, let's leave it like that, for testing
596 // purposes only. For production, this will have to be fixed.
597 AliWarning("Please fixme.");
604 //_____________________________________________________________________________
606 AliMUONPadStatusMaker::SetStatusSt345(AliMUONV2DStore& hvStatus,
607 Int_t detElemId, Int_t pcbIndex,
610 /// Flag all pads of pcbIndex-th PCB of detElemId (for St345) as bad.
612 const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
614 for ( Int_t icathode = 0; icathode < 2; ++icathode )
616 const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
617 (AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
618 const AliMpSlat* slat = seg->Slat();
619 const AliMpPCB* pcb = slat->GetPCB(pcbIndex);
621 for ( Int_t i = 0; i < pcb->GetSize(); ++i )
623 AliMpMotifPosition* pos = pcb->GetMotifPosition(i);
624 Int_t manuId = pos->GetID();
625 AliMUONVCalibParam* dead =
626 static_cast<AliMUONVCalibParam*>(hvStatus.Get(detElemId,manuId));
629 AliError(Form("dead is not null as expected from DE %d manuId %d",
634 dead = new AliMUONCalibParam1I(64,status);
635 hvStatus.Set(detElemId,manuId,dead,false);