]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPadStatusMaker.cxx
Further fix to make the alignment task work on grid
[u/mrichter/AliRoot.git] / MUON / AliMUONPadStatusMaker.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
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 **************************************************************************/
15
16 // $Id$
17
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONPadStatusMaker
20 ///
21 /// Make a 2DStore of pad statuses, using different sources of information,
22 /// like pedestal values, gain values, and HV values.
23 ///
24 /// \author Laurent Aphecetche
25 //-----------------------------------------------------------------------------
26
27 #include "AliMUONPadStatusMaker.h"
28
29 #include "AliMUON2DMap.h"
30 #include "AliMUON2DStoreValidator.h"
31 #include "AliMUONCalibParamNI.h"
32 #include "AliMUONCalibrationData.h"
33 #include "AliMUONLogger.h"
34 #include "AliMUONRecoParam.h"
35 #include "AliMUONStringIntMap.h"
36 #include "AliMUONTrackerData.h"
37 #include "AliMUONVCalibParam.h"
38
39 #include "AliMpArea.h"
40 #include "AliMpArrayI.h"
41 #include "AliMpCDB.h"
42 #include "AliMpConstants.h"
43 #include "AliMpDDLStore.h"
44 #include "AliMpDEManager.h"
45 #include "AliMpDetElement.h"
46 #include "AliMpDCSNamer.h"
47 #include "AliMpManuIterator.h"
48 #include "AliMpManuUID.h"
49
50 #include "AliCDBEntry.h"
51 #include "AliCDBManager.h"
52 #include "AliCodeTimer.h"
53 #include "AliDCSValue.h"
54 #include "AliLog.h"
55
56 #include <Riostream.h>
57 #include <TArrayI.h>
58 #include <TExMap.h>
59 #include <TFile.h>
60 #include <TKey.h>
61 #include <TMap.h>
62 #include <TROOT.h>
63 #include <TString.h>
64 #include <TSystem.h>
65
66 /// \cond CLASSIMP
67 ClassImp(AliMUONPadStatusMaker)
68 /// \endcond
69
70 //_____________________________________________________________________________
71 AliMUONPadStatusMaker::AliMUONPadStatusMaker(const AliMUONCalibrationData& calibData)
72 : fkCalibrationData(calibData),
73 fGainA1Limits(0,1E30),
74 fGainA2Limits(-1E-30,1E30),
75 fGainThresLimits(0,4095),
76 fHVSt12Limits(0,5000),
77 fHVSt345Limits(0,5000),
78 fPedMeanLimits(0,4095),
79 fPedSigmaLimits(0,4095),
80 fManuOccupancyLimits(0,1.0),
81 fBuspatchOccupancyLimits(0,1.0),
82 fDEOccupancyLimits(0,1.0),
83 fStatus(new AliMUON2DMap(true)),
84 fHV(0x0),
85 fPedestals(calibData.Pedestals()),
86 fGains(calibData.Gains()),
87 fTrackerData(0x0)
88 {
89   /// ctor
90   if ( calibData.OccupancyMap() )
91   {
92     /// create a tracker data from the occupancy map
93     fTrackerData = new AliMUONTrackerData("OCC","OCC",*(calibData.OccupancyMap()));
94   }     
95   if ( calibData.HV() )
96   {
97     /// Only create the fHV internal store if there are some HV values available
98     fHV = new TExMap;
99   }
100 }
101
102 //_____________________________________________________________________________
103 AliMUONPadStatusMaker::~AliMUONPadStatusMaker()
104 {
105   /// dtor.
106  
107   delete fStatus;
108   delete fHV;
109   delete fTrackerData;
110 }
111
112 //_____________________________________________________________________________
113 TString
114 AliMUONPadStatusMaker::AsString(Int_t status)
115 {
116   /// return a human readable version of the integer status
117   
118   Int_t pedStatus;
119   Int_t gainStatus;
120   Int_t hvStatus;
121   Int_t occStatus;
122   
123   DecodeStatus(status,pedStatus,hvStatus,gainStatus,occStatus);
124   
125   TString s;
126   
127   if ( pedStatus & kPedMeanZero ) s += "& Ped Mean is Zero ";
128   if ( pedStatus & kPedMeanTooLow ) s += "& Ped Mean Too Low ";
129   if ( pedStatus & kPedMeanTooHigh ) s += "& Ped Mean Too High ";
130   if ( pedStatus & kPedSigmaTooLow ) s += "& Ped Sigma Too Low ";
131   if ( pedStatus & kPedSigmaTooHigh ) s += "& Ped Sigma Too High ";
132   if ( pedStatus & kPedMissing ) s += "& Ped is missing ";
133   
134         if ( gainStatus & kGainA1TooLow ) s+="& Gain A1 is Too Low ";
135         if ( gainStatus & kGainA1TooHigh ) s+="& Gain A1 is Too High ";
136         if ( gainStatus & kGainA2TooLow ) s+="& Gain A2 is Too Low ";
137         if ( gainStatus & kGainA2TooHigh ) s+="& Gain A2 is Too High ";
138         if ( gainStatus & kGainThresTooLow ) s+="& Gain Thres is Too Low ";
139         if ( gainStatus & kGainThresTooHigh ) s+="& Gain Thres is Too High ";
140         if ( gainStatus & kGainMissing ) s+="& Gain is missing ";
141         
142         if ( hvStatus & kHVError ) s+="& HV is on error ";
143         if ( hvStatus & kHVTooLow ) s+="& HV is Too Low ";
144         if ( hvStatus & kHVTooHigh ) s+="& HV is Too High ";
145         if ( hvStatus & kHVChannelOFF ) s+="& HV has channel OFF ";
146         if ( hvStatus & kHVSwitchOFF ) s+="& HV has switch OFF ";
147         if ( hvStatus & kHVMissing ) s+="& HV is missing ";
148
149   if ( occStatus & kManuOccupancyTooHigh ) s+="& manu occupancy too high ";
150   if ( occStatus & kManuOccupancyTooLow ) s+="& manu occupancy too low ";
151   if ( occStatus & kBusPatchOccupancyTooHigh ) s+="& bus patch occupancy too high ";
152   if ( occStatus & kBusPatchOccupancyTooLow ) s+="& bus patch occupancy too low ";
153   if ( occStatus & kDEOccupancyTooHigh ) s+="& DE occupancy too high ";
154   if ( occStatus & kDEOccupancyTooLow ) s+="& DE occupancy too low ";
155   
156   if ( s[0] == '&' ) s[0] = ' ';
157   
158   return s;
159 }
160
161 //_____________________________________________________________________________
162 TString
163 AliMUONPadStatusMaker::AsCondition(Int_t mask)
164 {
165   /// return a human readable version of the mask's equivalent condition
166   
167   TString s(AsString(mask));
168   
169   s.ReplaceAll("&","|");
170   
171   return s;
172 }
173
174 //_____________________________________________________________________________
175 Int_t
176 AliMUONPadStatusMaker::BuildStatus(Int_t pedStatus, 
177                                    Int_t hvStatus, 
178                                    Int_t gainStatus,
179                                    Int_t occStatus)
180 {
181   /// Build a complete status from specific parts (ped,hv,gain)
182   
183   return ( hvStatus & 0xFF ) | ( ( pedStatus & 0xFF ) << 8 ) | 
184   ( ( gainStatus & 0xFF ) << 16 ) |
185   ( ( occStatus & 0xFF ) << 24 ) ;
186 }
187
188 //_____________________________________________________________________________
189 void
190 AliMUONPadStatusMaker::DecodeStatus(Int_t status, 
191                                     Int_t& pedStatus, 
192                                     Int_t& hvStatus, 
193                                     Int_t& gainStatus,
194                                     Int_t& occStatus)
195 {
196   /// Decode complete status into specific parts (ped,hv,gain)
197   
198   occStatus = ( status & 0xFF000000 ) >> 24;
199   gainStatus = ( status & 0xFF0000 ) >> 16;
200   pedStatus = ( status & 0xFF00 ) >> 8;
201   hvStatus = (status & 0xFF);
202 }
203
204 //_____________________________________________________________________________
205 Bool_t 
206 AliMUONPadStatusMaker::HVSt12Status(Int_t detElemId, Int_t sector,
207                                     Bool_t& hvChannelTooLow,
208                                     Bool_t& hvChannelTooHigh,
209                                     Bool_t& hvChannelON) const
210 {
211   /// Get HV status for one HV sector of St12
212   
213   /// For a given PCB in a given DE, get the HV status (both the channel
214   /// and the switch).
215   /// Returns false if hv switch changed during the run.
216   
217   AliCodeTimerAuto("",0)
218   
219   if (!fHV) return kFALSE;
220   
221   Bool_t error = kFALSE;
222   hvChannelTooLow = kFALSE;
223   hvChannelTooHigh = kFALSE;
224   hvChannelON = kTRUE;
225
226   AliMpDCSNamer hvNamer("TRACKER");
227   
228   TString hvChannel(hvNamer.DCSChannelName(detElemId,sector));
229   
230   TMap* hvMap = fkCalibrationData.HV();
231   TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
232   if (!hvPair)
233   {
234     AliError(Form("Did not find expected alias (%s) for DE %d",
235                   hvChannel.Data(),detElemId));  
236     error = kTRUE;
237   }
238   else
239   {
240     TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
241     if (!values)
242     {
243       AliError(Form("Could not get values for alias %s",hvChannel.Data()));
244       error = kTRUE;
245     }
246     else
247     {
248       // find out min and max value, and makes a cut
249       Float_t hvMin(1E9);
250       Float_t hvMax(0);
251       TIter next(values);
252       AliDCSValue* val;
253       
254       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
255       {
256         Float_t hv = val->GetFloat();
257         hvMin = TMath::Min(hv,hvMin);
258         hvMax = TMath::Max(hv,hvMax);
259       }
260       
261       float lowThreshold = fHVSt12Limits.X();
262       float highThreshold = fHVSt12Limits.Y();
263             
264       if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
265       if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
266       if ( hvMin < 1 ) hvChannelON = kFALSE;
267     }
268   }
269   
270   return error;
271 }
272
273 //_____________________________________________________________________________
274 Float_t
275 AliMUONPadStatusMaker::SwitchValue(const TObjArray& dcsArray)
276 {
277   /// Loop over the dcs value for a single switch to decide whether
278   /// we should consider it on or off
279   
280   // we'll count the number of ON/OFF for this pad, to insure
281   // consistency (i.e. if status changed during the run, we should
282   // at least notify this fact ;-) and hope it's not the norm)
283   Int_t nTrue(0);
284   Int_t nFalse(0);
285   TIter next(&dcsArray);
286   AliDCSValue* val;
287   
288   while ( ( val = static_cast<AliDCSValue*>(next()) ) )
289   {
290     if ( val->GetBool() )
291     {
292       ++nTrue;
293     }
294     else
295     {
296       ++nFalse;
297     }
298   }
299   
300   if ( (nTrue>0 && nFalse>0) )
301   {
302     // change of state during the run, consider it off
303     return 0.0;
304   }
305   
306   if ( nFalse ) 
307   {
308     /// switch = FALSE means the HV was flowding up to the PCB.
309     /// i.e. switch = FALSE = ON
310     return 1.0;    
311   }
312   
313   return 0.0;
314 }
315
316 //_____________________________________________________________________________
317 Bool_t 
318 AliMUONPadStatusMaker::HVSt345Status(Int_t detElemId, Int_t pcbIndex,
319                                      Bool_t& hvChannelTooLow,
320                                      Bool_t& hvChannelTooHigh,
321                                      Bool_t& hvChannelON,
322                                      Bool_t& hvSwitchON) const
323 {
324   /// For a given PCB in a given DE, get the HV status (both the channel
325   /// and the switch).
326   /// Returns false if something goes wrong (in particular if 
327   /// hv switch changed during the run).
328   
329   AliCodeTimerAuto("",0)
330   
331   if (!fHV) return kFALSE;
332   
333   Bool_t error = kFALSE;
334   hvChannelTooLow = kFALSE;
335   hvChannelTooHigh = kFALSE;
336   hvSwitchON = kTRUE;
337   hvChannelON = kTRUE;
338   
339   AliMpDCSNamer hvNamer("TRACKER");
340   
341   TString hvChannel(hvNamer.DCSChannelName(detElemId));
342   
343   TMap* hvMap = fkCalibrationData.HV();
344   
345   TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(hvChannel.Data()));
346   if (!hvPair)
347   {
348     AliError(Form("Did not find expected alias (%s) for DE %d",
349                   hvChannel.Data(),detElemId));  
350     error = kTRUE;
351   }
352   else
353   {
354     TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
355     if (!values)
356     {
357       AliError(Form("Could not get values for alias %s",hvChannel.Data()));
358       error = kTRUE;
359     }
360     else
361     {
362       // find out min and max value, and makes a cut
363       Float_t hvMin(1E9);
364       Float_t hvMax(0);
365       TIter next(values);
366       AliDCSValue* val;
367       
368       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
369       {
370         Float_t hv = val->GetFloat();
371         hvMin = TMath::Min(hv,hvMin);
372         hvMax = TMath::Max(hv,hvMax);
373       }
374
375       float lowThreshold = fHVSt345Limits.X();
376       float highThreshold = fHVSt345Limits.Y();
377
378       if ( hvMin < lowThreshold ) hvChannelTooLow = kTRUE;
379       else if ( hvMax > highThreshold ) hvChannelTooHigh = kTRUE;
380       if ( hvMin < 1 ) hvChannelON = kFALSE;
381     }
382   }
383   
384   TString hvSwitch(hvNamer.DCSSwitchName(detElemId,pcbIndex));
385   TPair* switchPair = static_cast<TPair*>(hvMap->FindObject(hvSwitch.Data()));
386   if (!switchPair)
387   {
388     AliError(Form("Did not find expected alias (%s) for DE %d PCB %d",
389                   hvSwitch.Data(),detElemId,pcbIndex));
390     error = kTRUE;
391   }
392   else
393   {
394     TObjArray* values = static_cast<TObjArray*>(switchPair->Value());
395     if (!values)
396     {    
397       AliError(Form("Could not get values for alias %s",hvSwitch.Data()));
398       error = kTRUE;
399     }
400     else
401     {
402       Float_t sv = SwitchValue(*values);
403       if ( sv < 0.99 ) hvSwitchON = kFALSE;
404     }
405   }
406   return error;
407 }
408
409 //_____________________________________________________________________________
410 Int_t
411 AliMUONPadStatusMaker::HVStatus(Int_t detElemId, Int_t manuId) const
412 {
413   /// Get HV status of one manu
414   
415   AliCodeTimerAuto("",0)
416   
417   if ( !fHV ) return kMissing;
418
419   Long_t lint = fHV->GetValue(AliMpManuUID::BuildUniqueID(detElemId,manuId));
420   
421   if ( lint ) 
422   {
423     return (Int_t)(lint - 1);
424   }
425
426   Int_t status(0);
427   
428   AliMpDCSNamer hvNamer("TRACKER");
429   
430   switch ( AliMpDEManager::GetStationType(detElemId) )
431   {
432     case AliMp::kStation12:
433     {
434       int sector = hvNamer.ManuId2Sector(detElemId,manuId);
435       if ( sector >= 0 ) 
436       {
437         Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON;
438         Bool_t error = HVSt12Status(detElemId,sector,
439                                     hvChannelTooLow,
440                                     hvChannelTooHigh,
441                                     hvChannelON);
442         if ( error ) status |= kHVError;
443         if ( hvChannelTooLow ) status |= kHVTooLow;
444         if ( hvChannelTooHigh ) status |= kHVTooHigh; 
445         if ( !hvChannelON ) status |= kHVChannelOFF;
446         // assign this status to all the other manus handled by the same HV channel
447         SetHVStatus(detElemId,sector,status);
448       }
449     }
450       break;
451     case AliMp::kStation345:
452     {
453       int pcbIndex = hvNamer.ManuId2PCBIndex(detElemId,manuId);
454       if ( pcbIndex >= 0 ) 
455       {
456         Bool_t hvChannelTooLow, hvChannelTooHigh, hvChannelON,hvSwitchON;
457         Bool_t error = HVSt345Status(detElemId,pcbIndex,
458                                      hvChannelTooLow,hvChannelTooHigh,
459                                      hvChannelON,hvSwitchON);
460         if ( error ) status |= kHVError;
461         if ( hvChannelTooLow ) status |= kHVTooLow;
462         if ( hvChannelTooHigh ) status |= kHVTooHigh; 
463         if ( !hvSwitchON ) status |= kHVSwitchOFF; 
464         if ( !hvChannelON) status |= kHVChannelOFF;
465         // assign this status to all the other manus handled by the same HV channel
466         SetHVStatus(detElemId,pcbIndex,status);
467       }
468     }
469       break;
470     default:
471       break;
472   }
473   
474   return status;
475 }
476
477 //_____________________________________________________________________________
478 AliMUONVCalibParam* 
479 AliMUONPadStatusMaker::Neighbours(Int_t detElemId, Int_t manuId) const
480 {
481   /// Get the neighbours parameters for a given manu
482   AliMUONVStore* neighbourStore = fkCalibrationData.Neighbours();
483   return static_cast<AliMUONVCalibParam*>(neighbourStore->FindObject(detElemId,manuId));
484 }
485
486 //_____________________________________________________________________________
487 AliMUONVStore* 
488 AliMUONPadStatusMaker::NeighboursStore() const
489 {
490   /// Return the store containing all the neighbours
491   return fkCalibrationData.Neighbours();
492 }
493
494 //_____________________________________________________________________________
495 AliMUONVCalibParam*
496 AliMUONPadStatusMaker::ComputeStatus(Int_t detElemId, Int_t manuId) const
497 {
498   /// Compute the status of a given manu, using all available information,
499   /// i.e. pedestals, gains, and HV
500   
501   AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,-1);
502   fStatus->Add(param);
503
504   AliMUONVCalibParam* pedestals = static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemId,manuId));
505
506   AliMUONVCalibParam* gains = static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemId,manuId));
507   
508   Int_t hvStatus = HVStatus(detElemId,manuId);
509
510   Int_t occStatus = OccupancyStatus(detElemId,manuId);
511   
512   for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
513   {
514     Int_t pedStatus(0);
515     
516     if (pedestals) 
517     {
518       Float_t pedMean = pedestals->ValueAsFloatFast(manuChannel,0);
519       Float_t pedSigma = pedestals->ValueAsFloatFast(manuChannel,1);
520       if ( pedMean < fPedMeanLimits.X() ) pedStatus |= kPedMeanTooLow;
521       else if ( pedMean > fPedMeanLimits.Y() ) pedStatus |= kPedMeanTooHigh;
522       if ( pedSigma < fPedSigmaLimits.X() ) pedStatus |= kPedSigmaTooLow;
523       else if ( pedSigma > fPedSigmaLimits.Y() ) pedStatus |= kPedSigmaTooHigh;
524       if ( pedMean == 0 ) pedStatus |= kPedMeanZero;
525     }
526     else
527     {
528       pedStatus = kPedMissing;
529     }
530     
531     Int_t gainStatus(0);
532   
533     if ( gains ) 
534     {
535       Float_t a0 = gains->ValueAsFloatFast(manuChannel,0);
536       Float_t a1 = gains->ValueAsFloatFast(manuChannel,1);
537       Float_t thres = gains->ValueAsFloatFast(manuChannel,2);
538   
539       if ( a0 < fGainA1Limits.X() ) gainStatus |= kGainA1TooLow;
540       else if ( a0 > fGainA1Limits.Y() ) gainStatus |= kGainA1TooHigh;
541       if ( a1 < fGainA2Limits.X() ) gainStatus |= kGainA2TooLow;
542       else if ( a1 > fGainA2Limits.Y() ) gainStatus |= kGainA2TooHigh;
543       if ( thres < fGainThresLimits.X() ) gainStatus |= kGainThresTooLow;
544       else if ( thres > fGainThresLimits.Y() ) gainStatus |= kGainThresTooHigh;
545     }
546     else
547     {
548       gainStatus = kGainMissing;
549     }
550     
551     Int_t status = BuildStatus(pedStatus,hvStatus,gainStatus,occStatus);
552       
553     param->SetValueAsIntFast(manuChannel,0,status);
554   }
555   
556   return param;
557 }
558
559 //_____________________________________________________________________________
560 Int_t 
561 AliMUONPadStatusMaker::OccupancyStatus(Int_t detElemId, Int_t manuId) const
562 {
563   /// Get the "other" status for a given manu
564  
565   Int_t rv(0);
566   
567   if ( fTrackerData ) 
568   {
569     const Int_t occIndex = 2;
570     
571     Double_t occ = fTrackerData->DetectionElement(detElemId,occIndex);
572     
573     if ( occ <= fDEOccupancyLimits.X() )
574     {
575       rv |= kDEOccupancyTooLow;
576     } 
577     else if ( occ > fDEOccupancyLimits.Y() )
578     {
579       rv |= kDEOccupancyTooHigh;
580     }
581     
582     Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
583     
584     occ = fTrackerData->BusPatch(busPatchId,occIndex);
585
586     if ( occ <= fBuspatchOccupancyLimits.X() )
587     {
588       rv |= kBusPatchOccupancyTooLow;
589     } 
590     else if ( occ > fBuspatchOccupancyLimits.Y() )
591     {
592       rv |= kBusPatchOccupancyTooHigh;
593     }
594     
595     occ = fTrackerData->Manu(detElemId,manuId,occIndex);
596     
597     if ( occ <= fManuOccupancyLimits.X() )
598     {
599       rv |= kManuOccupancyTooLow;
600     } 
601     else if ( occ > fManuOccupancyLimits.Y() )
602     {
603       rv |= kManuOccupancyTooHigh;
604     }
605   }
606   return rv;
607 }
608
609 //_____________________________________________________________________________
610 AliMUONVCalibParam* 
611 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId) const
612 {
613   /// Get the status container for a given manu
614   
615   AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
616   if (!param)
617   {
618     // not already there, so compute it now
619     AliCodeTimerAuto("ComputeStatus",0);
620     param = ComputeStatus(detElemId,manuId);
621   }
622   return param;
623 }
624
625 //_____________________________________________________________________________
626 Int_t 
627 AliMUONPadStatusMaker::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
628 {
629   /// Get the status for a given channel
630   
631   AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->FindObject(detElemId,manuId));
632   if (!param)
633   {
634     // not already there, so compute it now
635     param = ComputeStatus(detElemId,manuId);
636   }
637   return param->ValueAsInt(manuChannel,0);
638 }
639
640 //_____________________________________________________________________________
641 void
642 AliMUONPadStatusMaker::SetHVStatus(Int_t detElemId, Int_t index, Int_t status) const
643 {
644   /// Assign status to all manus in a given HV "zone" (defined by index, meaning
645   /// is different thing from St12 and St345)
646   
647   AliCodeTimerAuto("",0)
648   
649   AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
650   
651   const AliMpArrayI* manus = de->ManusForHV(index);
652   
653   for ( Int_t i = 0; i < manus->GetSize(); ++ i ) 
654   {
655     Int_t manuId = manus->GetValue(i);
656     fHV->Add(AliMpManuUID::BuildUniqueID(detElemId,manuId),status + 1);
657   }
658 }
659
660 //_____________________________________________________________________________
661 void
662 AliMUONPadStatusMaker::SetLimits(const AliMUONRecoParam& recoParams) 
663 {
664   /// Set the limits from the recoparam
665   
666   SetHVSt12Limits(recoParams.HVSt12LowLimit(),recoParams.HVSt12HighLimit());
667   SetHVSt345Limits(recoParams.HVSt345LowLimit(),recoParams.HVSt345HighLimit());
668   
669   SetPedMeanLimits(recoParams.PedMeanLowLimit(),recoParams.PedMeanHighLimit());
670   SetPedSigmaLimits(recoParams.PedSigmaLowLimit(),recoParams.PedSigmaHighLimit());
671   
672   SetGainA1Limits(recoParams.GainA1LowLimit(),recoParams.GainA1HighLimit());
673   SetGainA2Limits(recoParams.GainA2LowLimit(),recoParams.GainA2HighLimit());
674   SetGainThresLimits(recoParams.GainThresLowLimit(),recoParams.GainThresHighLimit());
675   
676   SetManuOccupancyLimits(recoParams.ManuOccupancyLowLimit(),recoParams.ManuOccupancyHighLimit());
677   SetBuspatchOccupancyLimits(recoParams.BuspatchOccupancyLowLimit(),recoParams.BuspatchOccupancyHighLimit());
678   SetDEOccupancyLimits(recoParams.DEOccupancyLowLimit(),recoParams.DEOccupancyHighLimit());  
679 }
680
681 //_____________________________________________________________________________
682 void 
683 AliMUONPadStatusMaker::Report(UInt_t mask)
684 {
685   /// Report the number of bad pads, according to the mask,
686   /// and the various reasons why they are bad (with occurence rates)
687   
688   AliInfo("");
689   AliCodeTimerAuto("",0);
690
691   AliMUONLogger log(1064008);
692   
693   Int_t nBadPads(0);
694   Int_t nPads(0);
695   
696   AliMpManuIterator it;
697   
698   Int_t detElemId, manuId;
699   
700   while ( it.Next(detElemId,manuId) )
701   {
702     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
703     
704     for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
705     {
706       if ( de->IsConnectedChannel(manuId,i) ) 
707       {
708         ++nPads;
709         
710         Int_t status = PadStatus(detElemId,manuId,i);          
711         
712         if ( ( status & mask) || (!mask && status) )
713         {
714           ++nBadPads;
715           log.Log(AsString(status));
716         }
717       }
718     }
719   }
720   
721   TString msg;
722   Int_t ntimes;
723   
724   cout << Form("According to mask %x (human readable form below) %6d pads are bad (over a total of %6d, i.e. %7.2f %%)",
725                mask,nBadPads,nPads,nPads ? nBadPads*100.0/nPads : 0.0) << endl;
726   cout << AliMUONPadStatusMaker::AsCondition(mask) << endl;
727   cout << "--------" << endl;
728   
729   while ( log.Next(msg,ntimes) )
730   {
731     cout << Form("The message (%120s) occured %15d times (%7.4f %%)",msg.Data(),ntimes,ntimes*100.0/nPads) << endl;
732   }
733   
734 }
735