]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONCDB.C
Corrected GetNeighbours() (Laurent)
[u/mrichter/AliRoot.git] / MUON / MUONCDB.C
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 /// By Laurent Aphecetche
19
20 #if !defined(__CINT__) || defined(__MAKECINT__)
21
22 #include "MUONCDB.h"
23
24 #include "AliCDBEntry.h"
25 #include "AliCDBManager.h"
26 #include "AliDCSValue.h"
27 #include "AliMUON1DArray.h"
28 #include "AliMUON2DMap.h"
29 #include "AliMUON2DStoreValidator.h"
30 #include "AliMUONCalibParam1I.h"
31 #include "AliMUONCalibParam2F.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONHVNamer.h"
34 #include "AliMUONObjectPair.h"
35 #include "AliMUONTriggerEfficiencyCells.h"
36 #include "AliMUONTriggerLut.h"
37 #include "AliMUONV2DStore.h"
38 #include "AliMUONVCalibParam.h"
39 #include "AliMUONVCalibParam.h"
40 #include "AliMUONVDataIterator.h"
41 #include "AliMpDEIterator.h"
42 #include "AliMpDEManager.h"
43 #include "AliMpManuList.h"
44 #include "AliMpSegmentation.h"
45 #include "AliMpStationType.h"
46 #include "AliMpVSegmentation.h"
47 #include "Riostream.h"
48 #include "TArrayI.h"
49 #include "TH1F.h"
50 #include "TList.h"
51 #include "TMap.h"
52 #include "TObjString.h"
53 #include "TRandom.h"
54 #include "TStopwatch.h"
55 #include "TSystem.h"
56 #include <map>
57
58 #endif
59
60 //_____________________________________________________________________________
61 AliMUONV2DStore* diff(AliMUONV2DStore& store1, AliMUONV2DStore& store2, 
62                       const char* /* opt */)
63 {
64   // creates a store which contains store1-store2
65   // if opt="abs" the difference is absolute one,
66   // if opt="rel" then what is stored is (store1-store2)/store1
67   
68   AliMUONV2DStore* d = static_cast<AliMUONV2DStore*>(store1.Clone());
69
70   AliMUONVDataIterator* it = d->Iterator();
71   
72   AliMUONObjectPair* p;
73   
74   while ( ( p = dynamic_cast<AliMUONObjectPair*>(it->Next() ) ) )
75   {
76     AliMpIntPair* dm = dynamic_cast<AliMpIntPair*>(p->Key());
77     //FIXME: this might happen (if a full manu is missing, for instance)
78     //handle it.
79     assert(dm!=0);
80     AliMUONVCalibParam* param = dynamic_cast<AliMUONVCalibParam*>(p->Value());
81     //FIXMENOT: this should *not* happen
82     assert(param!=0);
83
84     AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.Get(dm->GetFirst(),dm->GetSecond()));
85     //FIXME: this might happen. Handle it.
86     assert(param2!=0);
87     
88     for ( Int_t i = 0; i < param->Size(); ++i )
89     {
90       for ( Int_t j = 0; j < param->Dimension(); ++j )
91       {
92         param->SetValueAsFloat(i,j,param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j));
93       }      
94     }
95   }
96   return d;
97 }
98
99 //_____________________________________________________________________________
100 void getBoundaries(const AliMUONV2DStore& store,
101                    Float_t& x0min, Float_t& x0max,
102                    Float_t& x1min, Float_t& x1max)
103 {
104   x0min=1E30;
105   x0max=-1E30;
106   x1min=1E30;
107   x1max=-1E30;
108   
109   TList* list = AliMpManuList::ManuList();
110   TIter next(list);
111   AliMpIntPair* p;
112   
113   while ( ( p = (AliMpIntPair*)next() ) )
114   {
115     Int_t detElemId = p->GetFirst();
116     Int_t manuId = p->GetSecond();
117         
118     const AliMpVSegmentation* seg = 
119       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
120           
121     AliMUONVCalibParam* value = 
122       dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
123     
124     if (!value) continue;
125
126     for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
127     {
128       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
129       if (!pad.IsValid()) continue;
130
131       Float_t x0 = value->ValueAsFloat(manuChannel,0);
132       
133       x0min = TMath::Min(x0min,x0);
134       x0max = TMath::Max(x0max,x0);
135       if ( value->Dimension()>1 )
136       {
137         Float_t x1 = value->ValueAsFloat(manuChannel,1);
138         x1min = TMath::Min(x1min,x1);
139         x1max = TMath::Max(x1max,x1);
140       }
141     }
142   }  
143   delete list;
144 }
145
146 //_____________________________________________________________________________
147 void plot(const AliMUONV2DStore& store, const char* name, Int_t nbins)
148 {
149   Float_t x0min, x0max, x1min, x1max;
150   
151   getBoundaries(store,x0min,x0max,x1min,x1max);
152   
153   if ( x0min > x0max ) 
154   {
155     cerr << Form("Something is wrong with boundaries : x0(min,max)=%e,%e",
156                  x0min,x0max) << endl;
157     return;
158   }
159
160   if ( TMath::Abs(x0min-x0max) < 1E-3 ) 
161   {
162     x0min -= 1;
163     x0max += 1;
164   }
165   
166   TH1* h0 = new TH1F(Form("%s_0",name),Form("%s_0",name),
167                     nbins,x0min,x0max);
168   
169   TH1* h1(0);
170   
171   if ( x1max > x1min )
172   {
173     h1 = new TH1F(Form("%s_1",name),Form("%s_1",name),
174                   nbins,x1min,x1max);
175   }
176   
177   TList* list = AliMpManuList::ManuList();
178   TIter next(list);
179   AliMpIntPair* p;
180   Int_t n(0);
181   Int_t nPerStation[7];
182   
183   for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0;
184   
185   while ( ( p = (AliMpIntPair*)next() ) )
186   {
187     Int_t detElemId = p->GetFirst();
188     Int_t manuId = p->GetSecond();
189     Int_t station = AliMpDEManager::GetChamberId(detElemId);
190     
191     const AliMpVSegmentation* seg = 
192       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
193     
194     AliMUONVCalibParam* value = 
195       dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
196     
197     if (value)
198     {
199       for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
200       {
201         AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
202         if (!pad.IsValid()) continue;
203
204         ++n;
205         ++nPerStation[station];
206         Float_t x = value->ValueAsFloat(manuChannel,0);
207         h0->Fill(x);
208         if (h1)
209         {
210           h1->Fill(value->ValueAsFloat(manuChannel,1));
211         }
212       }
213     }
214     else
215     {
216       cout << "Got a null value for DE=" << detElemId << " manuId="
217       << manuId << endl;
218     }
219   }
220   
221   cout << "Number of channels = " << n << endl;
222   for ( Int_t i = 0; i < 7; ++i )
223   {
224     cout << "Station " << (i+1) << " " << nPerStation[i] << endl;
225   }
226   
227   delete list;
228 }
229
230 //_____________________________________________________________________________
231 void testReadStore(const AliMUONV2DStore& store, Int_t n)
232 {
233   TList* list = AliMpManuList::ManuList();
234   TIter next(list);
235   AliMpIntPair* p;
236   
237   while ( ( p = (AliMpIntPair*)next() ) )
238   {
239     for ( Int_t i = 0; i < n; ++i )
240     {
241       store.Get(p->GetFirst(),p->GetSecond());
242     }
243   }
244   delete list;
245
246
247 //_____________________________________________________________________________
248 Int_t makeHVStore(TMap& aliasMap, Bool_t defaultValues)
249 {
250   AliMUONHVNamer hvNamer;
251   TRandom random;
252   
253   TObjArray* aliases = hvNamer.GenerateAliases();
254   
255   Int_t nSwitch(0);
256   Int_t nChannels(0);
257   
258   for ( Int_t i = 0; i < aliases->GetEntries(); ++i ) 
259   {
260     TObjString* alias = static_cast<TObjString*>(aliases->At(i));
261     TString& aliasName = alias->String();
262     if ( aliasName.Contains("sw") ) 
263     {
264       // HV Switch (St345 only)
265       TObjArray* valueSet = new TObjArray;
266       valueSet->SetOwner(kTRUE);
267       
268       Bool_t value = kTRUE;
269       
270       if (!defaultValues)
271       {
272         Float_t r = random.Uniform();
273         if ( r < 0.007 ) value = kFALSE;      
274       } 
275       
276       for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
277       {
278         AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
279         valueSet->Add(dcsValue);
280       }
281       aliasMap.Add(new TObjString(*alias),valueSet);
282       ++nSwitch;
283     }
284     else
285     {
286       TObjArray* valueSet = new TObjArray;
287       valueSet->SetOwner(kTRUE);
288       for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
289       {
290         Float_t value = 1500;
291         if (!defaultValues) value = random.Gaus(1750,62.5);
292         AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
293         valueSet->Add(dcsValue);
294       }
295       aliasMap.Add(new TObjString(*alias),valueSet);
296       ++nChannels;
297     }
298   }
299   
300   delete aliases;
301   
302   cout << nChannels << " HV channels and " << nSwitch << " switches" << endl;
303   
304   return nChannels+nSwitch;
305 }
306
307 //_____________________________________________________________________________
308 Int_t makePedestalStore(AliMUONV2DStore& pedestalStore, Bool_t defaultValues)
309 {
310   TList* list = AliMpManuList::ManuList();
311   TIter next(list);
312   
313   AliMpIntPair* p;
314   
315   Int_t nchannels(0);
316   Int_t nmanus(0);
317   
318   Bool_t replace = kFALSE;
319   
320   const Int_t nChannels(64);
321   const Float_t kPedestalMeanMean(150);
322   const Float_t kPedestalMeanSigma(10);
323   const Float_t kPedestalSigmaMean(1.0);
324   const Float_t kPedestalSigmaSigma(0.2);
325   
326   while ( ( p = (AliMpIntPair*)next() ) )
327   {
328     ++nmanus;
329     AliMUONVCalibParam* ped = new AliMUONCalibParam2F(nChannels,AliMUONVCalibParam::InvalidFloatValue());
330     
331     Int_t detElemId = p->GetFirst();
332         
333     Int_t manuId = p->GetSecond();
334     
335     const AliMpVSegmentation* seg = 
336       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
337     
338     for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
339     {
340       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
341       if (!pad.IsValid()) continue;
342       
343       ++nchannels;
344       
345       Float_t meanPedestal;
346       Float_t sigmaPedestal;
347       
348       if ( defaultValues ) 
349       {
350         meanPedestal = 0.0;
351         sigmaPedestal = 1.0;
352       }
353       else
354       {
355         meanPedestal = -1;
356         while ( meanPedestal < 0 )
357         {
358           meanPedestal = gRandom->Gaus(kPedestalMeanMean,kPedestalMeanSigma);
359         }
360         sigmaPedestal = -1;
361         while ( sigmaPedestal < 0 )
362         {
363           sigmaPedestal = gRandom->Gaus(kPedestalSigmaMean,kPedestalSigmaSigma);
364         }
365       }
366       ped->SetValueAsFloat(manuChannel,0,meanPedestal);
367       ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
368       
369     }
370     Bool_t ok = pedestalStore.Set(detElemId,manuId,ped,replace);
371     if (!ok)
372     {
373       cout << "Could not set DetElemId=" << detElemId << " manuId="
374       << manuId << endl;
375     }
376   }
377   
378   delete list;
379   cout << nmanus << " Manus and " << nchannels << " channels." << endl;
380   return nchannels;
381   
382 }
383
384 //_____________________________________________________________________________
385 Int_t makeGainStore(AliMUONV2DStore& gainStore, Bool_t defaultValues)
386 {  
387   TList* list = AliMpManuList::ManuList();
388   TIter next(list);
389   
390   AliMpIntPair* p;
391   
392   Int_t nchannels(0);
393   Int_t nmanus(0);
394   
395   Bool_t replace = kFALSE;
396   
397   const Int_t nChannels(64);
398   const Double_t kSaturation(3000);
399   const Double_t kGainMean(1.0);
400   const Double_t kGainSigma(0.05);
401   
402   while ( ( p = (AliMpIntPair*)next() ) )
403   {
404     ++nmanus;
405     AliMUONVCalibParam* gain = new AliMUONCalibParam2F(nChannels,AliMUONVCalibParam::InvalidFloatValue());
406
407     Int_t detElemId = p->GetFirst();
408     Int_t manuId = p->GetSecond();
409
410     const AliMpVSegmentation* seg = 
411       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
412
413     for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
414     {
415       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
416       if (!pad.IsValid()) continue;
417       
418       ++nchannels;
419       
420       Float_t meanGain;
421       Float_t saturation(kSaturation);
422     
423       if ( defaultValues ) 
424       {
425         meanGain = 1.0;
426       }
427       else
428       {
429         meanGain = -1;
430         while ( meanGain < 0 )
431         {
432           meanGain = gRandom->Gaus(kGainMean,kGainSigma);
433         }
434       }
435       gain->SetValueAsFloat(manuChannel,0,meanGain);
436       gain->SetValueAsFloat(manuChannel,1,saturation);
437       
438     }
439     Bool_t ok = gainStore.Set(detElemId,manuId,gain,replace);
440     if (!ok)
441     {
442       cout << "Could not set DetElemId=" << detElemId << " manuId="
443         << manuId << endl;
444     }
445   }
446   
447   delete list;
448   cout << nmanus << " Manus and " << nchannels << " channels." << endl;
449   return nchannels;
450 }
451
452 //_____________________________________________________________________________
453 void testMakeStores(Int_t readLoop)
454 {
455   AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
456   AliMUONV2DStore* gainStore = new AliMUON2DMap;
457   
458   TStopwatch timer;
459   
460   cout << "Creating" << endl;
461   
462   Bool_t defaultValues = kTRUE;
463   
464   timer.Start(kTRUE);
465   makePedestalStore(*pedestalStore,defaultValues);
466   makeGainStore(*gainStore,defaultValues);
467   timer.Print();
468   
469   cout << "Reading..." << endl;
470   timer.Start(kTRUE);
471   testReadStore(*pedestalStore,readLoop);
472   testReadStore(*gainStore,readLoop);
473   cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop 
474     <<" samples." << endl;
475   
476   delete pedestalStore;
477   delete gainStore;
478 }
479
480 //_____________________________________________________________________________
481 void generateTrigger(const char* cdbpath)
482 {
483   // 
484   // Generate trigger related conditions :
485   //
486   // - trigger masks for board (locals, regionals, global)
487   // - trigger lut
488   // - trigger efficiency
489   // - trigger switches (to be implemented FIXME)
490   //
491   const Int_t nlboards = 234;
492   AliMUONV1DStore* localBoardMasks = new AliMUON1DArray(nlboards+1);
493   
494   // Generate fake mask values for 234 localboards and put that into
495   // one single container (localBoardMasks)
496   for ( Int_t i = 1; i <= nlboards; ++i )
497   {
498     AliMUONVCalibParam* localBoard = new AliMUONCalibParam1I(8);
499     for ( Int_t x = 0; x < 2; ++x )
500     {
501       for ( Int_t y = 0; y < 4; ++y )
502       {
503         Int_t index = x*4+y;
504         localBoard->SetValueAsInt(index,0,0xFFFF);
505       }
506     }
507     localBoardMasks->Set(i,localBoard,kFALSE);
508   }
509   
510   // Generate values for regional boards
511   const Int_t nrboards = 16;
512   AliMUONV1DStore* regionalBoardMasks = new AliMUON1DArray(16);
513   
514   for ( Int_t i = 0; i < nrboards; ++i )
515   {
516     AliMUONVCalibParam* regionalBoard = new AliMUONCalibParam1I(16);
517     for ( Int_t j = 0; j < 16; ++j )
518     {
519       regionalBoard->SetValueAsInt(j,0,0x3F);
520     }
521     regionalBoardMasks->Set(i,regionalBoard,kFALSE);
522   }
523   
524   // Generate values for global board
525   AliMUONVCalibParam* globalBoardMasks = new AliMUONCalibParam1I(16);
526   
527   for ( Int_t j = 0; j < 16; ++j )
528   {
529     globalBoardMasks->SetValueAsInt(j,0,0xFFF);
530   }
531     
532   AliMUONTriggerLut lut;
533   lut.ReadFromFile("$(ALICE_ROOT)/MUON/data/lutAptLpt1Hpt1p7.root");
534   
535   AliMUONTriggerEfficiencyCells cells("$ALICE_ROOT/MUON/data/efficiencyCells.dat");
536   
537   //--------------------------------------------
538   // Store the resulting containers into the CDB
539   Int_t ever = 99999999;
540   
541   AliCDBId id("MUON/Calib/LocalTriggerBoardMasks",0,ever);
542   
543   AliCDBMetaData md;
544   md.SetBeamPeriod(1);
545   md.SetAliRootVersion(gROOT->GetVersion());
546   md.SetComment("Test with default values");
547   md.SetResponsible("Rachid Guernane");
548   
549   AliCDBManager* man = AliCDBManager::Instance();
550   man->SetDefaultStorage(cdbpath);
551   man->Put(localBoardMasks,id,&md);
552   
553   id.SetPath("MUON/Calib/RegionalTriggerBoardMasks");
554   
555   man->Put(regionalBoardMasks,id,(AliCDBMetaData*)md.Clone());
556   
557   id.SetPath("MUON/Calib/GlobalTriggerBoardMasks");
558   
559   man->Put(globalBoardMasks,id,(AliCDBMetaData*)md.Clone());
560
561   id.SetPath("MUON/Calib/TriggerLut");
562   
563   man->Put(&lut,id,(AliCDBMetaData*)md.Clone());
564   
565   id.SetPath("MUON/Calib/TriggerEfficiency");
566   md.SetResponsible("Diego Stocco");
567   
568   man->Put(&cells,id,(AliCDBMetaData*)md.Clone());
569   
570   delete localBoardMasks;
571   delete regionalBoardMasks;
572   delete globalBoardMasks;
573 }
574
575
576 //_____________________________________________________________________________
577 void writeToCDB(const char* cdbpath, const char* calibpath, TObject* object, 
578                 Int_t startRun, Int_t endRun, Bool_t defaultValues)
579 {
580   AliCDBId id(calibpath,startRun,endRun);
581   AliCDBMetaData md;
582   md.SetBeamPeriod(1);
583   md.SetAliRootVersion(gROOT->GetVersion());
584   if ( defaultValues )
585   {
586     md.SetComment("Test with default values");
587   }
588   else
589   {
590     md.SetComment("Test with random values");
591   }
592   md.SetResponsible("Laurent Aphecetche");
593   
594   AliCDBManager* man = AliCDBManager::Instance();
595   man->SetDefaultStorage(cdbpath);
596   man->Put(object,id,&md);
597 }
598
599 //_____________________________________________________________________________
600 void writeHV(const char* cdbpath, Bool_t defaultValues,
601              Int_t startRun, Int_t endRun)
602 {
603   /// generate HV values (either cste = 1500 V) if defaultValues=true or random
604   /// if defaultValues=false, see makeHVStore) and
605   /// store them into CDB located at cdbpath, with a validity period
606   /// ranging from startRun to endRun
607   
608   TMap* hvStore = new TMap;
609   Int_t ngenerated = makeHVStore(*hvStore,defaultValues);
610   cout << "Ngenerated = " << ngenerated << endl;
611   
612   writeToCDB(cdbpath,"MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
613   
614   delete hvStore;
615 }
616
617 //_____________________________________________________________________________
618 void writePedestals(const char* cdbpath, Bool_t defaultValues,
619                     Int_t startRun, Int_t endRun)
620 {
621   /// generate pedestal values (either 0 if defaultValues=true or random
622   /// if defaultValues=false, see makePedestalStore) and
623   /// store them into CDB located at cdbpath, with a validity period
624   /// ranging from startRun to endRun
625   
626   AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
627   Int_t ngenerated = makePedestalStore(*pedestalStore,defaultValues);
628   cout << "Ngenerated = " << ngenerated << endl;
629   
630   writeToCDB(cdbpath,"MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
631   delete pedestalStore;
632 }
633
634 //_____________________________________________________________________________
635 void writeGains(const char* cdbpath, Bool_t defaultValues,
636                     Int_t startRun, Int_t endRun)
637 {
638   /// generate gain values (either 1 if defaultValues=true or random
639   /// if defaultValues=false, see makePedestalStore) and
640   /// store them into CDB located at cdbpath, with a validity period
641   /// ranging from startRun to endRun
642   
643   AliMUONV2DStore* gainStore = new AliMUON2DMap;
644   Int_t ngenerated = makeGainStore(*gainStore,defaultValues);
645   cout << "Ngenerated = " << ngenerated << endl;
646   
647   writeToCDB(cdbpath,"MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
648   delete gainStore;
649 }
650
651 //_____________________________________________________________________________
652 Bool_t check1I(const AliMUONVCalibParam& calib, Int_t channel)
653 {
654   /// 
655   
656   return ( calib.ValueAsInt(channel) == 0);
657 }
658
659 //_____________________________________________________________________________
660 void validate1I(const AliMUONV2DStore& store)
661 {
662   AliMUON2DStoreValidator validator;
663   
664   TObjArray* a = validator.Validate(store,check1I);
665   
666   if (a) a->Print();
667   
668   TList lines;
669   
670   validator.Report(lines);
671   
672   lines.Print();
673 }
674
675 //_____________________________________________________________________________
676 void validate2F(const AliMUONV2DStore& store)
677 {
678   AliMUON2DStoreValidator validator;
679   
680   TObjArray* a = validator.Validate(store,AliMUONCalibParam2F::InvalidFloatValue());
681   
682   if (a) a->Print();
683   
684   TList lines;
685   
686   validator.Report(lines);
687   
688   lines.Print();
689 }
690
691 //_____________________________________________________________________________
692 void dump(const TArrayI& a, const char* what)
693 {
694   cout << what << " " << a.GetSize() << " manus" << endl;
695   for ( Int_t i = 0; i < a.GetSize(); ++i ) 
696   {
697     cout << Form(" %5d ",a[i]);
698   }
699   cout << endl;
700 }
701
702 //_____________________________________________________________________________
703 void countManus()
704 {
705   AliMpDEIterator it;
706   
707   it.First();
708   
709   Int_t b(0);
710   Int_t nb(0);
711   
712   while (!it.IsDone())
713   {
714     Int_t detElemId = it.CurrentDEId();
715     AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
716     if ( stationType != AliMp::kStationTrigger ) 
717     {
718       const AliMpVSegmentation* seg0 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0);
719       const AliMpVSegmentation* seg1 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1);
720       TArrayI a1;
721       TArrayI a0;
722       seg0->GetAllElectronicCardIDs(a0);
723       seg1->GetAllElectronicCardIDs(a1);
724       
725       cout << Form("DE %5d B %4d NB %4d Total %5d",detElemId,
726                    a0.GetSize(),a1.GetSize(),a0.GetSize()+a1.GetSize())            
727         << endl;
728       
729       b += a0.GetSize();
730       nb += a1.GetSize();
731       
732       if ( detElemId == 500 ) 
733       {
734         dump(a0,"B");
735         dump(a1,"NB");
736       }
737     }
738     it.Next();
739   }
740   
741   cout << Form("B %5d NB %5d Total %5d",b,nb,b+nb) << endl;
742 }
743
744 //_____________________________________________________________________________
745 void count(const AliMUONV2DStore& store)
746 {
747   AliMUONVDataIterator* it = store.Iterator();
748   AliMUONObjectPair* pair;
749   std::map<int,std::pair<int,int> > demap;
750   
751   while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
752   {
753     AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
754     
755     Int_t detElemId = ip->GetFirst();
756     
757     Int_t manuId = ip->GetSecond();
758     
759     const AliMpVSegmentation* seg = 
760       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
761     
762     if ( seg->PlaneType() == AliMp::kNonBendingPlane ) 
763     {
764       demap[detElemId].second++;
765     }
766     else
767     {
768       demap[detElemId].first++;
769     }    
770   }
771   
772   std::map<int,std::pair<int,int> >::const_iterator mit;
773   
774   Int_t b(0);
775   Int_t nb(0);
776   
777   for ( mit = demap.begin(); mit != demap.end(); ++mit ) 
778   {
779     cout << Form("DE %5d B %4d NB %4d Total %5d",mit->first,
780                  mit->second.first,mit->second.second,
781                  mit->second.first+mit->second.second) << endl;
782     b += mit->second.first;
783     nb += mit->second.second;    
784   }
785   
786   cout << Form("B %5d NB %5d Total %5d",b,nb,b+nb) << endl;  
787 }
788
789