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 /// \class AliMUONPadStatusMaker
20 /// Make a 2DStore of pad statuses, using different sources of information,
21 /// like pedestal values, gain values, and HV values.
23 /// \author Laurent Aphecetche
25 #include "AliMUONPadStatusMaker.h"
27 #include "AliCDBEntry.h"
28 #include "AliCDBManager.h"
29 #include "AliDCSValue.h"
31 #include "AliMUON2DMap.h"
32 #include "AliMUON2DStoreValidator.h"
33 #include "AliMUONCalibParamNI.h"
34 #include "AliMUONCalibrationData.h"
35 #include "AliMUONHVNamer.h"
36 #include "AliMUONVCalibParam.h"
37 #include "AliMpArea.h"
38 #include "AliMpConstants.h"
39 #include "AliMpDEIterator.h"
40 #include "AliMpDEManager.h"
41 #include "AliMpIntPair.h"
42 #include "AliMpManuList.h"
43 #include "AliMpMotifMap.h"
44 #include "AliMpMotifPosition.h"
47 #include "AliMpSector.h"
48 #include "AliMpSectorSegmentation.h"
49 #include "AliMpSegmentation.h"
50 #include "AliMpSlat.h"
51 #include "AliMpSlatSegmentation.h"
52 #include "AliMpStationType.h"
53 #include "AliMpVPadIterator.h"
54 #include <Riostream.h>
56 #include <TStopwatch.h>
61 ClassImp(AliMUONPadStatusMaker)
64 //_____________________________________________________________________________
65 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
66 : fCalibrationData(calibData),
67 fPedMeanLimits(0,4095),
68 fPedSigmaLimits(0,4095),
69 fHVSt12Limits(0,5000),
70 fHVSt345Limits(0,5000)
75 //_____________________________________________________________________________
76 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
81 //_____________________________________________________________________________
83 AliMUONPadStatusMaker::Combine(const AliMUONVStore& store1,
84 const AliMUONVStore& store2,
87 /// Combine two status containers into one, shifting store2 status bits
88 /// to the left by binShift before making an OR with store1.
93 AliMUONVStore* combined = static_cast<AliMUONVStore*>(store1.Clone());
95 TIter next(store1.CreateIterator());
96 AliMUONVCalibParam* param1;
98 while ( ( param1 = static_cast<AliMUONVCalibParam*>(next()) ) )
100 Int_t detElemId = param1->ID0();
101 Int_t manuId = param1->ID1();
102 AliMUONVCalibParam* param2 = static_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
105 AliWarning(Form("Could not get statuses for store2 for DE %d ManuId %d. Marking as missing.",
107 param2 = static_cast<AliMUONVCalibParam*>(param1->Clone());
108 for ( Int_t manuChannel = 0; manuChannel < param2->Size(); ++manuChannel )
110 param2->SetValueAsInt(manuChannel,0,kMissing);
113 AliMUONVCalibParam* paramCombined = static_cast<AliMUONVCalibParam*>(combined->FindObject(detElemId,manuId));
116 paramCombined = static_cast<AliMUONVCalibParam*>(param2->Clone());
117 combined->Add(paramCombined);
120 for ( Int_t manuChannel = 0; manuChannel < param1->Size(); ++manuChannel )
122 if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
124 Int_t status1(param1->ValueAsInt(manuChannel));
125 Int_t status2(param2->ValueAsInt(manuChannel));
127 Int_t status = status1 | (status2 << binShift);
129 paramCombined->SetValueAsInt(manuChannel,0,status);
135 StdoutToAliInfo(timer.Print(););
140 //_____________________________________________________________________________
142 AliMUONPadStatusMaker::GeneratePadStatus(Int_t value)
144 /// Generate a "fake" store, with all (detElemId,manuId) present,
145 /// and containing all the same value
147 AliMUONVStore* store = new AliMUON2DMap(true);
149 TList* list = AliMpManuList::ManuList();
155 while ( ( pair = static_cast<AliMpIntPair*>(next()) ) )
157 Int_t detElemId = pair->GetFirst();
158 Int_t manuId = pair->GetSecond();
159 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,value);
168 //_____________________________________________________________________________
170 AliMUONPadStatusMaker::GetSt12Status(const TMap& hvMap,
171 Int_t detElemId, Int_t sector,
172 Bool_t& hvChannelTooLow,
173 Bool_t& hvChannelTooHigh,
174 Bool_t& hvChannelON) const
176 /// Get HV status for one HV sector of St12
178 /// For a given PCB in a given DE, get the HV status (both the channel
180 /// Returns false if hv switch changed during the run.
182 Bool_t error = kFALSE;
183 hvChannelTooLow = kFALSE;
184 hvChannelTooHigh = kFALSE;
187 AliMUONHVNamer hvNamer;
189 TString hvChannel(hvNamer.DCSHVChannelName(detElemId,sector));
191 TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
194 AliError(Form("Did not find expected alias (%s) for DE %d",
195 hvChannel.Data(),detElemId));
200 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
203 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
208 // find out min and max value, and makes a cut
214 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
216 Float_t hv = val->GetFloat();
217 hvMin = TMath::Min(hv,hvMin);
218 hvMax = TMath::Max(hv,hvMax);
221 float lowThreshold = fHVSt12Limits.X();
222 float highThreshold = fHVSt12Limits.Y();
224 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
225 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
226 if ( hvMin < 1 ) hvChannelON = kFALSE;
233 //_____________________________________________________________________________
235 AliMUONPadStatusMaker::GetSt345Status(const TMap& hvMap,
236 Int_t detElemId, Int_t pcbIndex,
237 Bool_t& hvChannelTooLow,
238 Bool_t& hvChannelTooHigh,
240 Bool_t& hvSwitchON) const
242 /// For a given PCB in a given DE, get the HV status (both the channel
244 /// Returns false if something goes wrong (in particular if
245 /// hv switch changed during the run).
247 Bool_t error = kFALSE;
248 hvChannelTooLow = kFALSE;
249 hvChannelTooHigh = kFALSE;
253 AliMUONHVNamer hvNamer;
255 TString hvChannel(hvNamer.DCSHVChannelName(detElemId));
257 TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel.Data()));
260 AliError(Form("Did not find expected alias (%s) for DE %d",
261 hvChannel.Data(),detElemId));
266 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
269 AliError(Form("Could not get values for alias %s",hvChannel.Data()));
274 // find out min and max value, and makes a cut
280 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
282 Float_t hv = val->GetFloat();
283 hvMin = TMath::Min(hv,hvMin);
284 hvMax = TMath::Max(hv,hvMax);
287 float lowThreshold = fHVSt345Limits.X();
288 float highThreshold = fHVSt345Limits.Y();
290 if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
291 if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
292 if ( hvMin < 1 ) hvChannelON = kFALSE;
296 TString hvSwitch(hvNamer.DCSHVSwitchName(detElemId,pcbIndex));
297 TPair* switchPair = static_cast<TPair*>(hvMap.FindObject(hvSwitch.Data()));
300 AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
301 hvSwitch.Data(),detElemId,pcbIndex));
306 TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
309 AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
314 // we'll count the number of ON/OFF for this pad, to insure
315 // consistency (i.e. if status changed during the run, we should
316 // at least notify this fact ;-) and hope it's not the norm)
322 while ( ( val = static_cast<AliDCSValue*>(next()) ) )
324 if ( val->GetBool() )
334 if ( (nTrue>0 && nFalse>0) )
336 AliWarning(Form("Status of HV Switch %s changed during this run nTrue=%d nFalse=%d! Will consider it OFF",
337 hvSwitch.Data(),nTrue,nFalse));
341 if ( nFalse ) hvSwitchON = kFALSE;
347 //_____________________________________________________________________________
349 AliMUONPadStatusMaker::MakeGainStatus(const AliMUONVStore& /*gainValues*/) const
351 /// FIXME: to be implemented
352 AliWarning("Not implemented yet");
356 //_____________________________________________________________________________
358 AliMUONPadStatusMaker::MakeHVStatus(const TMap& hvValues) const
360 /// Scrutinize HV values and deduce an HV status for each pad
362 TStopwatch timerSt12;
363 TStopwatch timerSt345;
365 timerSt12.Start(kTRUE);
367 timerSt345.Start(kTRUE);
370 AliMUONHVNamer hvNamer;
372 AliMpDEIterator deIt;
376 AliMUONVStore* hv = new AliMUON2DMap(kTRUE);
378 while ( !deIt.IsDone() )
380 Int_t detElemId = deIt.CurrentDEId();
382 switch ( AliMpDEManager::GetStationType(detElemId) )
384 case AliMp::kStation1:
385 case AliMp::kStation2:
386 timerSt12.Start(kFALSE);
387 for ( int sector = 0; sector < 3; ++sector)
389 AliDebug(1,Form("detElemId %5d sector %d",detElemId,sector));
391 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
392 Bool_t error = GetSt12Status(hvValues,
394 hvChannelTooLow,hvChannelTooHigh,
397 if ( error ) status |= kHVError;
398 if ( hvChannelTooLow ) status |= kHVTooLow;
399 if ( hvChannelTooHigh ) status |= kHVTooHigh;
400 if ( !hvChannelON ) status |= kHVChannelOFF;
401 SetStatusSt12(*hv,detElemId,sector,status);
406 case AliMp::kStation345:
408 timerSt345.Start(kFALSE);
409 for ( Int_t pcbIndex = 0; pcbIndex < hvNamer.NumberOfPCBs(detElemId); ++pcbIndex)
411 AliDebug(1,Form("detElemId %5d pcbIndex %d",detElemId,pcbIndex));
412 Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
413 Bool_t error = GetSt345Status(hvValues,
415 hvChannelTooLow,hvChannelTooHigh,
416 hvChannelON,hvSwitchON);
418 if ( error ) status |= kHVError;
419 if ( hvChannelTooLow ) status |= kHVTooLow;
420 if ( hvChannelTooHigh ) status |= kHVTooHigh;
421 if ( !hvSwitchON ) status |= kHVSwitchOFF;
422 if ( !hvChannelON) status |= kHVChannelOFF;
423 SetStatusSt345(*hv,detElemId,pcbIndex,status);
434 AliInfo("St12 timer:");
435 StdoutToAliInfo(timerSt12.Print(););
436 AliInfo("St345 timer:");
437 StdoutToAliInfo(timerSt345.Print(););
442 //_____________________________________________________________________________
444 AliMUONPadStatusMaker::MakePedestalStatus(const AliMUONVStore& pedValues) const
446 /// Assign a pedestal status to each pad
452 AliMUONVStore* pedStatuses = new AliMUON2DMap(kTRUE);
454 TIter next(pedValues.CreateIterator());
455 AliMUONVCalibParam* pedestals;
458 while ( ( pedestals = static_cast<AliMUONVCalibParam*>(next() ) ) )
460 Int_t detElemId = pedestals->ID0();
461 Int_t manuId = pedestals->ID1();
463 for ( Int_t manuChannel = 0; manuChannel < pedestals->Size(); ++manuChannel )
466 if ( AliMpManuList::DoesChannelExist(detElemId, manuId, manuChannel) )
468 Float_t pedMean = pedestals->ValueAsFloat(manuChannel,0);
469 Float_t pedSigma = pedestals->ValueAsFloat(manuChannel,1);
470 if ( pedMean < fPedMeanLimits.X() ) status |= kPedMeanTooLow;
471 if ( pedMean > fPedMeanLimits.Y() ) status |= kPedMeanTooHigh;
472 if ( pedSigma < fPedSigmaLimits.X() ) status |= kPedSigmaTooLow;
473 if ( pedSigma > fPedSigmaLimits.Y() ) status |= kPedSigmaTooHigh;
474 if ( pedMean == 0 ) status |= kPedMeanZero;
476 AliMUONVCalibParam* vStatus =
477 static_cast<AliMUONVCalibParam*>(pedStatuses->FindObject(detElemId,manuId));
480 vStatus = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0);
481 pedStatuses->Add(vStatus);
483 vStatus->SetValueAsInt(manuChannel,0,status);
488 AliInfo(Form("%d manus checked in :",nofManus));
489 StdoutToAliInfo(timer.Print(););
493 //_____________________________________________________________________________
495 AliMUONPadStatusMaker::MakeStatus() const
497 /// Read ped, gains and hv values from CDB, apply some Q&A and produces
498 /// a combined status for each pad.
500 TMap* hvValues = fCalibrationData.HV();
501 AliMUONVStore* hvStatus(0x0);
505 AliError("Could not get HV values from CDB. Will create dummy ones and mark those as missing");
506 hvStatus = GeneratePadStatus(kHVMissing);
510 hvStatus = MakeHVStatus(*hvValues);
513 AliMUONVStore* pedValues = fCalibrationData.Pedestals();
514 AliMUONVStore* pedStatus(0x0);
518 AliError("Could not get pedestals values from CDB. Will create dummy ones and mark those as missing");
519 pedStatus = GeneratePadStatus(kPedMissing);
523 pedStatus = MakePedestalStatus(*pedValues);
526 // FIXME: should do the same for gains as for hv and ped.
528 AliMUONVStore* status = Combine(*hvStatus,*pedStatus,8);
533 // Insure we get all channels there (some or even all can be bad, but they
534 // must be there somehow).
536 AliMUON2DStoreValidator validator;
538 TObjArray* a = validator.Validate(*status);
542 // this should not happen.
543 AliError("Status store not complete. Crash to follow soon...");
544 StdoutToAliError(a->Print(););
545 AliFatal("this should not happen at all!");
553 //_____________________________________________________________________________
555 AliMUONPadStatusMaker::SetStatusSt12(AliMUONVStore& hvStatus,
560 /// Flag all pads of detElemId (for St12) as bad.
562 // FIXME: need a way to iterator on pads over a given HV sector for St12...
563 // we currently suppose that one sector is about a third of the chamber...
564 // FIXME !! This has to be checked very carefully...
566 const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
568 for ( Int_t icathode = 0; icathode < 2; ++icathode )
570 const AliMpSectorSegmentation* seg =
571 static_cast<const AliMpSectorSegmentation*>(AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
572 const AliMpSector* sector = seg->GetSector();
573 AliMpMotifMap* mMap = sector->GetMotifMap();
576 mMap->GetAllMotifPositionsIDs(a);
578 TVector2 dim = seg->Dimensions();
579 Double_t x = dim.X()*2;
580 Double_t xmin = isector*x/3.0;
581 Double_t xmax = xmin + x/3.0;
583 for ( Int_t i = 0; i < a.GetSize(); ++i )
585 AliMpMotifPosition* pos = mMap->FindMotifPosition(a[i]);
586 Int_t manuId = pos->GetID();
587 TVector2 position = pos->Position();
588 if ( position.X() >= xmin && position.X() <= xmax)
590 AliMUONVCalibParam* dead =
591 static_cast<AliMUONVCalibParam*>(hvStatus.FindObject(detElemId,manuId));
594 dead = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,status);
599 // FIXME: this should really not happen, if we'd know really the
600 // relationship between manuId and HV sector...
601 // For the time being, let's leave it like that, for testing
602 // purposes only. For production, this will have to be fixed.
603 AliWarning("Please fixme.");
610 //_____________________________________________________________________________
612 AliMUONPadStatusMaker::SetStatusSt345(AliMUONVStore& hvStatus,
613 Int_t detElemId, Int_t pcbIndex,
616 /// Flag all pads of pcbIndex-th PCB of detElemId (for St345) as bad.
618 const AliMp::CathodType kCathodes[] = { AliMp::kCath0, AliMp::kCath1 };
620 for ( Int_t icathode = 0; icathode < 2; ++icathode )
622 const AliMpSlatSegmentation* seg = static_cast<const AliMpSlatSegmentation*>
623 (AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,kCathodes[icathode]));
624 const AliMpSlat* slat = seg->Slat();
625 const AliMpPCB* pcb = slat->GetPCB(pcbIndex);
627 for ( Int_t i = 0; i < pcb->GetSize(); ++i )
629 AliMpMotifPosition* pos = pcb->GetMotifPosition(i);
630 Int_t manuId = pos->GetID();
631 AliMUONVCalibParam* dead =
632 static_cast<AliMUONVCalibParam*>(hvStatus.FindObject(detElemId,manuId));
635 AliError(Form("dead is not null as expected from DE %d manuId %d",
640 dead = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,status);