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 "AliCDBEntry.h"
30 #include "AliCDBManager.h"
31 #include "AliDCSValue.h"
33 #include "AliMUON2DMap.h"
34 #include "AliMUON2DStoreValidator.h"
35 #include "AliMUONCalibParamNI.h"
36 #include "AliMUONCalibrationData.h"
37 #include "AliMUONHVNamer.h"
38 #include "AliMUONVCalibParam.h"
39 #include "AliMpArea.h"
40 #include "AliMpConstants.h"
41 #include "AliMpDEIterator.h"
42 #include "AliMpDEManager.h"
43 #include "AliMpIntPair.h"
44 #include "AliMpManuList.h"
45 #include "AliMpMotifMap.h"
46 #include "AliMpMotifPosition.h"
49 #include "AliMpSector.h"
50 #include "AliMpSectorSegmentation.h"
51 #include "AliMpSegmentation.h"
52 #include "AliMpSlat.h"
53 #include "AliMpSlatSegmentation.h"
54 #include "AliMpStationType.h"
55 #include "AliMpVPadIterator.h"
56 #include <Riostream.h>
58 #include <TStopwatch.h>
63 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 AliMUONVStore& store1,
86 const AliMUONVStore& 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 AliMUONVStore* combined = static_cast<AliMUONVStore*>(store1.Clone());
97 TIter next(store1.CreateIterator());
98 AliMUONVCalibParam* param1;
100 while ( ( param1 = static_cast<AliMUONVCalibParam*>(next()) ) )
102 Int_t detElemId = param1->ID0();
103 Int_t manuId = param1->ID1();
104 AliMUONVCalibParam* param2 = static_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
107 AliWarning(Form("Could not get statuses for store2 for DE %d ManuId %d. Marking as missing.",
109 param2 = static_cast<AliMUONVCalibParam*>(param1->Clone());
110 for ( Int_t manuChannel = 0; manuChannel < param2->Size(); ++manuChannel )
112 param2->SetValueAsInt(manuChannel,0,kMissing);
115 AliMUONVCalibParam* paramCombined = static_cast<AliMUONVCalibParam*>(combined->FindObject(detElemId,manuId));
118 paramCombined = static_cast<AliMUONVCalibParam*>(param2->Clone());
119 combined->Add(paramCombined);
122 for ( Int_t manuChannel = 0; manuChannel < param1->Size(); ++manuChannel )
124 if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
126 Int_t status1(param1->ValueAsInt(manuChannel));
127 Int_t status2(param2->ValueAsInt(manuChannel));
129 Int_t status = status1 | (status2 << binShift);
131 paramCombined->SetValueAsInt(manuChannel,0,status);
137 StdoutToAliInfo(timer.Print(););
142 //_____________________________________________________________________________
144 AliMUONPadStatusMaker::GeneratePadStatus(Int_t value)
146 /// Generate a "fake" store, with all (detElemId,manuId) present,
147 /// and containing all the same value
149 AliMUONVStore* store = new AliMUON2DMap(true);
151 TList* list = AliMpManuList::ManuList();
157 while ( ( pair = static_cast<AliMpIntPair*>(next()) ) )
159 Int_t detElemId = pair->GetFirst();
160 Int_t manuId = pair->GetSecond();
161 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,value);
170 //_____________________________________________________________________________
172 AliMUONPadStatusMaker::GetSt12Status(const TMap& hvMap,
173 Int_t detElemId, Int_t sector,
174 Bool_t& hvChannelTooLow,
175 Bool_t& hvChannelTooHigh,
176 Bool_t& hvChannelON) const
178 /// Get HV status for one HV sector of St12
180 /// For a given PCB in a given DE, get the HV status (both the channel
182 /// Returns false if hv switch changed during the run.
184 Bool_t error = kFALSE;
185 hvChannelTooLow = kFALSE;
186 hvChannelTooHigh = kFALSE;
189 AliMUONHVNamer hvNamer;
191 TString hvChannel(hvNamer.DCSHVChannelName(detElemId,sector));
193 TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
196 AliError(Form("Did not find expected alias (%s) for DE %d",
197 hvChannel.Data(),detElemId));
202 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
205 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
210 // find out min and max value, and makes a cut
216 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
218 Float_t hv = val->GetFloat();
219 hvMin = TMath::Min(hv,hvMin);
220 hvMax = TMath::Max(hv,hvMax);
223 float lowThreshold = fHVSt12Limits.X();
224 float highThreshold = fHVSt12Limits.Y();
226 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
227 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
228 if ( hvMin < 1 ) hvChannelON = kFALSE;
235 //_____________________________________________________________________________
237 AliMUONPadStatusMaker::GetSt345Status(const TMap& hvMap,
238 Int_t detElemId, Int_t pcbIndex,
239 Bool_t& hvChannelTooLow,
240 Bool_t& hvChannelTooHigh,
242 Bool_t& hvSwitchON) const
244 /// For a given PCB in a given DE, get the HV status (both the channel
246 /// Returns false if something goes wrong (in particular if
247 /// hv switch changed during the run).
249 Bool_t error = kFALSE;
250 hvChannelTooLow = kFALSE;
251 hvChannelTooHigh = kFALSE;
255 AliMUONHVNamer hvNamer;
257 TString hvChannel(hvNamer.DCSHVChannelName(detElemId));
259 TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
262 AliError(Form("Did not find expected alias (%s) for DE %d",
263 hvChannel.Data(),detElemId));
268 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
271 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
276 // find out min and max value, and makes a cut
282 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
284 Float_t hv = val->GetFloat();
285 hvMin = TMath::Min(hv,hvMin);
286 hvMax = TMath::Max(hv,hvMax);
289 float lowThreshold = fHVSt345Limits.X();
290 float highThreshold = fHVSt345Limits.Y();
292 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
293 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
294 if ( hvMin < 1 ) hvChannelON = kFALSE;
298 TString hvSwitch(hvNamer.DCSHVSwitchName(detElemId,pcbIndex));
299 TPair* switchPair = static_cast<TPair*>(hvMap.FindObject(hvSwitch.Data()));
302 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
303 hvSwitch.Data(),detElemId,pcbIndex));
308 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
311 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
316 // we'll count the number of ON/OFF for this pad, to insure
317 // consistency (i.e. if status changed during the run, we should
318 // at least notify this fact ;-) and hope it's not the norm)
324 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
326 if ( val->GetBool() )
336 if ( (nTrue>0 && nFalse>0) )
338 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
339 hvSwitch.Data(),nTrue,nFalse));
343 if ( nFalse ) hvSwitchON = kFALSE;
349 //_____________________________________________________________________________
351 AliMUONPadStatusMaker::MakeGainStatus(const AliMUONVStore& /*gainValues*/) const
353 /// FIXME: to be implemented
354 AliWarning("Not implemented yet");
358 //_____________________________________________________________________________
360 AliMUONPadStatusMaker::MakeHVStatus(const TMap& hvValues) const
362 /// Scrutinize HV values and deduce an HV status for each pad
364 TStopwatch timerSt12;
365 TStopwatch timerSt345;
367 timerSt12.Start(kTRUE);
369 timerSt345.Start(kTRUE);
372 AliMUONHVNamer hvNamer;
374 AliMpDEIterator deIt;
378 AliMUONVStore* hv = new AliMUON2DMap(kTRUE);
380 while ( !deIt.IsDone() )
382 Int_t detElemId = deIt.CurrentDEId();
384 switch ( AliMpDEManager::GetStationType(detElemId) )
386 case AliMp::kStation1:
387 case AliMp::kStation2:
388 timerSt12.Start(kFALSE);
389 for ( int sector = 0; sector < 3; ++sector)
391 AliDebug(1,Form("detElemId %5d sector %d",detElemId,sector));
393 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
394 Bool_t error = GetSt12Status(hvValues,
396 hvChannelTooLow,hvChannelTooHigh,
399 if ( error ) status |= kHVError;
400 if ( hvChannelTooLow ) status |= kHVTooLow;
401 if ( hvChannelTooHigh ) status |= kHVTooHigh;
402 if ( !hvChannelON ) status |= kHVChannelOFF;
403 SetStatusSt12(*hv,detElemId,sector,status);
408 case AliMp::kStation345:
410 timerSt345.Start(kFALSE);
411 for ( Int_t pcbIndex = 0; pcbIndex < hvNamer.NumberOfPCBs(detElemId); ++pcbIndex)
413 AliDebug(1,Form("detElemId %5d pcbIndex %d",detElemId,pcbIndex));
414 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
415 Bool_t error = GetSt345Status(hvValues,
417 hvChannelTooLow,hvChannelTooHigh,
418 hvChannelON,hvSwitchON);
420 if ( error ) status |= kHVError;
421 if ( hvChannelTooLow ) status |= kHVTooLow;
422 if ( hvChannelTooHigh ) status |= kHVTooHigh;
423 if ( !hvSwitchON ) status |= kHVSwitchOFF;
424 if ( !hvChannelON) status |= kHVChannelOFF;
425 SetStatusSt345(*hv,detElemId,pcbIndex,status);
436 AliInfo("St12 timer:");
437 StdoutToAliInfo(timerSt12.Print(););
438 AliInfo("St345 timer:");
439 StdoutToAliInfo(timerSt345.Print(););
444 //_____________________________________________________________________________
446 AliMUONPadStatusMaker::MakePedestalStatus(const AliMUONVStore& pedValues) const
448 /// Assign a pedestal status to each pad
454 AliMUONVStore* pedStatuses = new AliMUON2DMap(kTRUE);
456 TIter next(pedValues.CreateIterator());
457 AliMUONVCalibParam* pedestals;
460 while ( ( pedestals = static_cast<AliMUONVCalibParam*>(next() ) ) )
462 Int_t detElemId = pedestals->ID0();
463 Int_t manuId = pedestals->ID1();
465 for ( Int_t manuChannel = 0; manuChannel < pedestals->Size(); ++manuChannel )
468 if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
470 Float_t pedMean = pedestals->ValueAsFloat(manuChannel,0);
471 Float_t pedSigma = pedestals->ValueAsFloat(manuChannel,1);
472 if ( pedMean < fPedMeanLimits.X() ) status |= kPedMeanTooLow;
473 if ( pedMean > fPedMeanLimits.Y() ) status |= kPedMeanTooHigh;
474 if ( pedSigma < fPedSigmaLimits.X() ) status |= kPedSigmaTooLow;
475 if ( pedSigma > fPedSigmaLimits.Y() ) status |= kPedSigmaTooHigh;
476 if ( pedMean == 0 ) status |= kPedMeanZero;
478 AliMUONVCalibParam* vStatus =
479 static_cast<AliMUONVCalibParam*>(pedStatuses->FindObject(detElemId,manuId));
482 vStatus = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0);
483 pedStatuses->Add(vStatus);
485 vStatus->SetValueAsInt(manuChannel,0,status);
490 AliInfo(Form("%d manus checked in :",nofManus));
491 StdoutToAliInfo(timer.Print(););
495 //_____________________________________________________________________________
497 AliMUONPadStatusMaker::MakeStatus() const
499 /// Read ped, gains and hv values from CDB, apply some Q&A and produces
500 /// a combined status for each pad.
502 TMap* hvValues = fCalibrationData.HV();
503 AliMUONVStore* hvStatus(0x0);
507 AliError("Could not get HV values from CDB. Will create dummy ones and mark those as missing");
508 hvStatus = GeneratePadStatus(kHVMissing);
512 hvStatus = MakeHVStatus(*hvValues);
515 AliMUONVStore* pedValues = fCalibrationData.Pedestals();
516 AliMUONVStore* pedStatus(0x0);
520 AliError("Could not get pedestals values from CDB. Will create dummy ones and mark those as missing");
521 pedStatus = GeneratePadStatus(kPedMissing);
525 pedStatus = MakePedestalStatus(*pedValues);
528 // FIXME: should do the same for gains as for hv and ped.
530 AliMUONVStore* status = Combine(*hvStatus,*pedStatus,8);
535 // Insure we get all channels there (some or even all can be bad, but they
536 // must be there somehow).
538 AliMUON2DStoreValidator validator;
540 TObjArray* a = validator.Validate(*status);
544 // this should not happen.
545 AliError("Status store not complete. Crash to follow soon...");
546 StdoutToAliError(a->Print(););
547 AliFatal("this should not happen at all!");
555 //_____________________________________________________________________________
557 AliMUONPadStatusMaker::SetStatusSt12(AliMUONVStore& hvStatus,
562 /// Flag all pads of detElemId (for St12) as bad.
564 // FIXME: need a way to iterator on pads over a given HV sector for St12...
565 // we currently suppose that one sector is about a third of the chamber...
566 // FIXME !! This has to be checked very carefully...
568 const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
570 for ( Int_t icathode = 0; icathode < 2; ++icathode )
572 const AliMpSectorSegmentation* seg =
573 static_cast<const AliMpSectorSegmentation*>(AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
574 const AliMpSector* sector = seg->GetSector();
575 AliMpMotifMap* mMap = sector->GetMotifMap();
578 mMap->GetAllMotifPositionsIDs(a);
580 TVector2 dim = seg->Dimensions();
581 Double_t x = dim.X()*2;
582 Double_t xmin = isector*x/3.0;
583 Double_t xmax = xmin + x/3.0;
585 for ( Int_t i = 0; i < a.GetSize(); ++i )
587 AliMpMotifPosition* pos = mMap->FindMotifPosition(a[i]);
588 Int_t manuId = pos->GetID();
589 TVector2 position = pos->Position();
590 if ( position.X() >= xmin && position.X() <= xmax)
592 AliMUONVCalibParam* dead =
593 static_cast<AliMUONVCalibParam*>(hvStatus.FindObject(detElemId,manuId));
596 dead = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,status);
601 // FIXME: this should really not happen, if we'd know really the
602 // relationship between manuId and HV sector...
603 // For the time being, let's leave it like that, for testing
604 // purposes only. For production, this will have to be fixed.
605 AliWarning("Please fixme.");
612 //_____________________________________________________________________________
614 AliMUONPadStatusMaker::SetStatusSt345(AliMUONVStore& hvStatus,
615 Int_t detElemId, Int_t pcbIndex,
618 /// Flag all pads of pcbIndex-th PCB of detElemId (for St345) as bad.
620 const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
622 for ( Int_t icathode = 0; icathode < 2; ++icathode )
624 const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
625 (AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
626 const AliMpSlat* slat = seg->Slat();
627 const AliMpPCB* pcb = slat->GetPCB(pcbIndex);
629 for ( Int_t i = 0; i < pcb->GetSize(); ++i )
631 AliMpMotifPosition* pos = pcb->GetMotifPosition(i);
632 Int_t manuId = pos->GetID();
633 AliMUONVCalibParam* dead =
634 static_cast<AliMUONVCalibParam*>(hvStatus.FindObject(detElemId,manuId));
637 AliError(Form("dead is not null as expected from DE %d manuId %d",
642 dead = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,status);