=operator implemented (R. Shahoyan)
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerData.cxx
CommitLineData
0145e89a 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#include "AliMUONTrackerData.h"
19
8741815f 20#include "AliCodeTimer.h"
21#include "AliLog.h"
22#include "AliMUON1DArray.h"
23#include "AliMUON1DMap.h"
24#include "AliMUON2DMap.h"
0145e89a 25#include "AliMUONCalibParamND.h"
8741815f 26#include "AliMUONSparseHisto.h"
0145e89a 27#include "AliMUONVStore.h"
28#include "AliMpBusPatch.h"
8741815f 29#include "AliMpConstants.h"
0145e89a 30#include "AliMpDDLStore.h"
0145e89a 31#include "AliMpDEIterator.h"
8741815f 32#include "AliMpDEManager.h"
0145e89a 33#include "AliMpDetElement.h"
34#include "AliMpHVNamer.h"
8741815f 35#include "AliMpManuIterator.h"
0145e89a 36#include <Riostream.h>
37#include <TMath.h>
38#include <TObjArray.h>
39#include <TObjString.h>
40#include <TString.h>
41#include <TVector2.h>
42#include <float.h>
43
44/// \class AliMUONTrackerData
45///
46/// Implementation of AliMUONVTrackerData class
47///
48/// \author Laurent Aphecetche, Subatech
49
50///\cond CLASSIMP
51ClassImp(AliMUONTrackerData)
52///\endcond
53
54const Int_t AliMUONTrackerData::fgkExtraDimension = 2;
55const Int_t AliMUONTrackerData::fgkVirtualExtraDimension = 1;
56
57//_____________________________________________________________________________
58AliMUONTrackerData::AliMUONTrackerData(const char* name, const char* title,
59 Int_t dimension,
60 Bool_t runnable)
61: AliMUONVTrackerData(name,title),
62fChannelValues(0x0),
63fManuValues(0x0),
64fBusPatchValues(0x0),
65fDEValues(0x0),
66fChamberValues(0x0),
67fPCBValues(0x0),
68fDimension(dimension*2+fgkExtraDimension),
69fNevents(0x0),
70fDimensionNames(new TObjArray(fDimension+fgkVirtualExtraDimension)),
8741815f 71fExternalDimensionNames(new TObjArray(dimension)),
0145e89a 72fExternalDimension(dimension),
8741815f 73fIsRunnable(runnable),
74fHistogramming(new Int_t[fExternalDimension]),
10eb3d17 75fChannelHistos(0x0),
76fXmin(0.0),
77fXmax(0.0)
0145e89a 78{
79 /// ctor
10eb3d17 80 memset(fHistogramming,0,sizeof(Int_t)); // histogramming is off by default. Use MakeHistogramForDimension to turn it on.
8741815f 81 fExternalDimensionNames->SetOwner(kTRUE);
0145e89a 82 fDimensionNames->SetOwner(kTRUE);
83 fDimensionNames->AddAt(new TObjString("occ"),IndexOfOccupancyDimension());
84 fDimensionNames->AddAt(new TObjString("N"),IndexOfNumberDimension());
85 fDimensionNames->AddAt(new TObjString("n"),NumberOfDimensions()-fgkVirtualExtraDimension);
86 Clear();
87}
88
89//_____________________________________________________________________________
90AliMUONTrackerData::~AliMUONTrackerData()
91{
92 /// dtor
93 delete fChannelValues;
94 delete fManuValues;
95 delete fBusPatchValues;
96 delete fDEValues;
97 delete fChamberValues;
98 delete fPCBValues;
99 delete fDimensionNames;
8741815f 100 delete fExternalDimensionNames;
101 delete[] fHistogramming;
102 delete fChannelHistos;
0145e89a 103}
104
105//_____________________________________________________________________________
106Bool_t
7b6684fe 107AliMUONTrackerData::Add(const AliMUONVStore& store, Int_t numberOfEvents)
0145e89a 108{
8741815f 109 /// Add the given external store to our internal store
0145e89a 110
8741815f 111 AliCodeTimerAuto(GetName());
112
7b6684fe 113 fNevents += numberOfEvents;
8741815f 114 NumberOfEventsChanged();
0145e89a 115
8741815f 116 if (!fChannelValues)
117 {
7b6684fe 118 fChannelValues = new AliMUON2DMap(kTRUE);
119 fManuValues = new AliMUON2DMap(kTRUE);
120 fPCBValues = new AliMUON2DMap(kFALSE);
8741815f 121 fBusPatchValues = new AliMUON1DMap;
122 fDEValues = new AliMUON1DMap;
123 fChamberValues = new AliMUON1DArray;
124 }
0145e89a 125
126 TIter next(store.CreateIterator());
127 AliMUONVCalibParam* external;
128
0145e89a 129 while ( ( external = static_cast<AliMUONVCalibParam*>(next()) ) )
130 {
8741815f 131 if ( external->Dimension() != ExternalDimension() )
132 {
133 AliError(Form("Incompatible dimensions %d vs %d",
134 external->Dimension(),ExternalDimension()));
135 return kFALSE;
136 }
0145e89a 137
8741815f 138
139 AliMUONVCalibParam* chamber, *de, *busPatch, *pcb, *manu, *channel;
140 AliMpDetElement* mpde;
0145e89a 141
8741815f 142 Int_t manuId = GetParts(external,chamber,de,busPatch,pcb,manu,channel,mpde);
0145e89a 143
7b6684fe 144 if ( manuId < 0 ) continue;
145
8741815f 146 Int_t detElemId = mpde->GetId();
147
148 Double_t value[] = { 0.0, 0.0 };
149
150 Int_t nch = mpde->NofChannelsInManu(manuId);
0145e89a 151
152 for ( Int_t i = 0; i < external->Size(); ++i )
153 {
8741815f 154 Bool_t existingChannel = ( nch == AliMpConstants::ManuNofChannels() ? kTRUE
155 : mpde->IsConnectedChannel(manuId,i));
156 // note we only use IsConnectedChannel method when really needed, as
157 // it costs (some) CPU time...
0145e89a 158
8741815f 159 if ( existingChannel )
0145e89a 160 {
8741815f 161 Bool_t validChannel(kFALSE);
0145e89a 162
8741815f 163 for ( Int_t j = 0; j < external->Dimension(); ++j )
164 {
165 Double_t vext = external->IsDoublePrecision() ?
166 external->ValueAsDoubleFast(i,j) :
167 external->ValueAsFloatFast(i,j);
168
169 if ( vext >= AliMUONVCalibParam::InvalidFloatValue() ) continue;
170
171 validChannel = kTRUE;
172
173 Int_t ix = External2Internal(j);
174
175 value[0] = vext;
176 value[1] = vext*vext;
177
178 if ( IsHistogrammed(j) )
179 {
180 FillChannel(detElemId,manuId,i,j,vext);
181 }
182
183 for ( Int_t k = 0; k < 2; ++k )
184 {
185 channel->SetValueAsDoubleFast(i,ix+k,channel->ValueAsDoubleFast(i,ix+k)+value[k]);
186
187 manu->SetValueAsDoubleFast(0,ix+k,manu->ValueAsDoubleFast(0,ix+k)+value[k]);
188
189 busPatch->SetValueAsDoubleFast(0,ix+k,busPatch->ValueAsDoubleFast(0,ix+k)+value[k]);
190
191 de->SetValueAsDoubleFast(0,ix+k,de->ValueAsDoubleFast(0,ix+k)+value[k]);
192
193 chamber->SetValueAsDoubleFast(0,ix+k,chamber->ValueAsDoubleFast(0,ix+k)+value[k]);
194
195 if ( pcb )
196 {
197 pcb->SetValueAsDoubleFast(0,ix+k,pcb->ValueAsDoubleFast(0,ix+k)+value[k]);
198 }
199 }
200 }
0145e89a 201
8741815f 202 if ( validChannel )
203 {
204 channel->SetValueAsDoubleFast(i,IndexOfOccupancyDimension(),
205 channel->ValueAsDoubleFast(i,IndexOfOccupancyDimension())+1.0);
206 manu->SetValueAsDoubleFast(0,IndexOfOccupancyDimension(),
207 manu->ValueAsDoubleFast(0,IndexOfOccupancyDimension())+1.0);
208 busPatch->SetValueAsDoubleFast(0,IndexOfOccupancyDimension(),
209 busPatch->ValueAsDoubleFast(0,IndexOfOccupancyDimension())+1.0);
210 de->SetValueAsDoubleFast(0,IndexOfOccupancyDimension(),
211 de->ValueAsDoubleFast(0,IndexOfOccupancyDimension())+1.0);
212 chamber->SetValueAsDoubleFast(0,IndexOfOccupancyDimension(),
213 chamber->ValueAsDoubleFast(0,IndexOfOccupancyDimension())+1.0);
214 if ( pcb )
215 {
216 pcb->SetValueAsDoubleFast(0,IndexOfOccupancyDimension(),
217 pcb->ValueAsDoubleFast(0,IndexOfOccupancyDimension())+1.0);
218 }
219 }
0145e89a 220 }
221 }
222 }
223
0145e89a 224 return kTRUE;
225}
226
227//_____________________________________________________________________________
228Double_t
229AliMUONTrackerData::BusPatch(Int_t busPatchId, Int_t dim) const
230{
231 /// Return the value of a given buspatch for a given dimension
232 /// or 0 if not existing
233 AliMUONVCalibParam* param = BusPatchParam(busPatchId);
234 return param ? Value(*param,0,dim) : 0.0;
235}
236
237//_____________________________________________________________________________
238AliMUONVCalibParam*
8741815f 239AliMUONTrackerData::BusPatchParam(Int_t busPatchId, Bool_t create) const
0145e89a 240{
241 /// Return (if it exist), the VCalibParam for a given busPatch
8741815f 242
243 AliMUONVCalibParam* busPatch = fBusPatchValues ? static_cast<AliMUONVCalibParam*>
244 (fBusPatchValues->FindObject(busPatchId)) : 0x0;
245
246 if (!busPatch && create && fBusPatchValues)
247 {
248 busPatch = CreateBusPatchParam(busPatchId);
249 fBusPatchValues->Add(busPatch);
250 }
251
252 return busPatch;
253}
254
255//_____________________________________________________________________________
256AliMUONVCalibParam*
257AliMUONTrackerData::CreateBusPatchParam(Int_t busPatchId) const
258{
259 /// Create storage for one bus patch
260
261 AliCodeTimerAuto("");
262
263 AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
264
265 if (!bp)
266 {
267 AliError(Form("Got an invalid buspatchId = %d",busPatchId));
268 return 0x0;
269 }
270
271 AliMUONVCalibParam* busPatch = new AliMUONCalibParamND(Dimension(),1,busPatchId,0,0.0);
272
273 // set the number of channels in that buspatch
274
275 Int_t nchannels(0);
276
277 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
278
279 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
280
281 for ( Int_t i = 0; i < bp->GetNofManus(); ++i )
282 {
283 Int_t manuId = bp->GetManuId(i);
284 nchannels += de->NofChannelsInManu(manuId);
285 }
286
287 busPatch->SetValueAsDouble(0,IndexOfNumberDimension(),nchannels);
288
289 return busPatch;
0145e89a 290}
291
292//_____________________________________________________________________________
293Double_t
294AliMUONTrackerData::Chamber(Int_t chamberId, Int_t dim) const
295{
296 /// Return the value fo a given chamber for a given dimension,
297 /// or zero if not existing
298 AliMUONVCalibParam* param = ChamberParam(chamberId);
299 return param ? Value(*param,0,dim) : 0.0;
300}
301
302//_____________________________________________________________________________
303AliMUONVCalibParam*
8741815f 304AliMUONTrackerData::ChamberParam(Int_t chamberId, Bool_t create) const
0145e89a 305{
306 /// Return (if it exist) the VCalibParam for a given chamber
8741815f 307
308 AliMUONVCalibParam* chamber = fChamberValues ? static_cast<AliMUONVCalibParam*>
0145e89a 309 (fChamberValues->FindObject(chamberId)) : 0x0;
8741815f 310
311 if (!chamber && create && fChamberValues)
312 {
313 chamber = CreateChamberParam(chamberId);
314 fChamberValues->Add(chamber);
315 }
316
317 return chamber;
318}
319
320//_____________________________________________________________________________
321AliMUONVCalibParam*
322AliMUONTrackerData::CreateChamberParam(Int_t chamberId) const
323{
324 /// Create storage for one chamber
325
326 AliCodeTimerAuto("");
327
328 AliMUONVCalibParam* chamber = new AliMUONCalibParamND(Dimension(),1,chamberId,0,0.0);
329
330 // set the number of channels in that chamber
331
332 Int_t nchannels(0);
333
334 AliMpDEIterator it;
335
336 it.First(chamberId);
337
338 while ( !it.IsDone() )
339 {
340 AliMpDetElement* det = it.CurrentDE();
341
342 for ( Int_t i = 0; i < det->GetNofBusPatches(); ++i )
343 {
344 Int_t busPatchId = det->GetBusPatchId(i);
345 AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
346 for ( Int_t j = 0; j < bp->GetNofManus(); ++j )
347 {
348 Int_t manuId = bp->GetManuId(j);
349 nchannels += det->NofChannelsInManu(manuId);
350 }
351 }
352
353 it.Next();
354 }
355
356 chamber->SetValueAsDouble(0,IndexOfNumberDimension(),nchannels);
357
358 return chamber;
0145e89a 359}
360
361//_____________________________________________________________________________
362Double_t
363AliMUONTrackerData::Channel(Int_t detElemId, Int_t manuId,
364 Int_t manuChannel, Int_t dim) const
365{
366 /// Return the value for a given channel for a given dimension
367
368 AliMUONVCalibParam* param = ChannelParam(detElemId,manuId);
369
370 return param ? Value(*param,manuChannel,dim) : 0.0;
371}
372
373//_____________________________________________________________________________
374AliMUONVCalibParam*
8741815f 375AliMUONTrackerData::ChannelParam(Int_t detElemId, Int_t manuId,
376 AliMUONVCalibParam* external) const
0145e89a 377{
378 /// Return (if it exist) the VCalibParam for a given manu
8741815f 379
380 AliMUONVCalibParam* param = fChannelValues ? static_cast<AliMUONVCalibParam*>
381 (fChannelValues->FindObject(detElemId,manuId)) : 0x0 ;
382
383 if (!param && external && fChannelValues)
384 {
7b6684fe 385 param = CreateDouble(*external,detElemId,manuId);
8741815f 386 fChannelValues->Add(param);
387 }
388
389 return param;
0145e89a 390}
391
0145e89a 392//_____________________________________________________________________________
393void
394AliMUONTrackerData::Clear(Option_t*)
395{
396 /// Clear all the values
397 if ( fChannelValues ) fChannelValues->Clear();
398 if ( fManuValues ) fManuValues->Clear();
399 if ( fBusPatchValues) fBusPatchValues->Clear();
400 if ( fPCBValues ) fPCBValues->Clear();
401 if ( fDEValues) fDEValues->Clear();
8741815f 402 if ( fChamberValues ) fChamberValues->Clear();
403 if ( fChannelHistos ) fChannelHistos->Clear();
0145e89a 404 fNevents = 0;
405 NumberOfEventsChanged();
406}
407
408//_____________________________________________________________________________
409Double_t
410AliMUONTrackerData::Count(Int_t detElemId, Int_t manuId,
411 Int_t manuChannel) const
412{
413 /// Return the number of times a given channel had data
0145e89a 414
8741815f 415 return Channel(detElemId,manuId,manuChannel,IndexOfNumberDimension());
0145e89a 416}
417
418//_____________________________________________________________________________
419AliMUONVCalibParam*
7b6684fe 420AliMUONTrackerData::CreateDouble(const AliMUONVCalibParam& param,
421 Int_t detElemId, Int_t manuId) const
0145e89a 422{
423 /// Create a double version of VCalibParam, for internal use
8741815f 424
425 AliCodeTimerAuto("");
426
427 AliMUONVCalibParam* c = new AliMUONCalibParamND(Dimension(),
428 param.Size(),
7b6684fe 429 detElemId,
430 manuId,
8741815f 431 0.0);
0145e89a 432
7b6684fe 433 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId,manuId);
434
0145e89a 435 for ( Int_t i = 0; i < c->Size(); ++i )
436 {
7b6684fe 437 Double_t value(0.0);
438
439 if ( de->IsConnectedChannel(manuId,i) ) value = 1.0;
440
441 c->SetValueAsDouble(i,IndexOfNumberDimension(),value);
0145e89a 442 }
443
444 return c;
445}
446
447//_____________________________________________________________________________
448Double_t
449AliMUONTrackerData::DetectionElement(Int_t detElemId, Int_t dim) const
450{
451 /// Return the value for a given detection element for a given dimension
452 AliMUONVCalibParam* param = DetectionElementParam(detElemId);
453 return param ? Value(*param,0,dim) : 0.0;
454
455}
456
457//_____________________________________________________________________________
458AliMUONVCalibParam*
8741815f 459AliMUONTrackerData::DetectionElementParam(Int_t detElemId, Bool_t create) const
0145e89a 460{
461 /// Return (if it exist) the VCalibParam for a given detection element
8741815f 462
463 AliMUONVCalibParam* de = fDEValues ? static_cast<AliMUONVCalibParam*>
464 (fDEValues->FindObject(detElemId)) : 0x0 ;
465
466 if (!de && create && fDEValues)
467 {
468 de = CreateDetectionElementParam(detElemId);
469 fDEValues->Add(de);
470 }
471
472 return de;
473
474}
475
476//_____________________________________________________________________________
477AliMUONVCalibParam*
478AliMUONTrackerData::CreateDetectionElementParam(Int_t detElemId) const
479{
480 /// Create storage for one detection element
481
482 AliCodeTimerAuto("");
483
484 AliMUONVCalibParam* de = new AliMUONCalibParamND(Dimension(),1,detElemId,0,0.0);
485
486 AliMpDetElement* det = AliMpDDLStore::Instance()->GetDetElement(detElemId);
487 Int_t nchannels(0);
488
489 for ( Int_t i = 0; i < det->GetNofBusPatches(); ++i )
490 {
491 Int_t busPatchId = det->GetBusPatchId(i);
492 AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
493 for ( Int_t j = 0; j < bp->GetNofManus(); ++j )
494 {
495 Int_t manuId = bp->GetManuId(j);
496 nchannels += det->NofChannelsInManu(manuId);
497 }
498 }
499
500 de->SetValueAsDouble(0,IndexOfNumberDimension(),nchannels);
501
502 return de;
0145e89a 503}
504
505//_____________________________________________________________________________
506TString
507AliMUONTrackerData::DimensionName(Int_t dim) const
508{
509 /// Get the name of a given dimension
510 TObjString* value = static_cast<TObjString*>(fDimensionNames->At(dim));
511 if ( value )
512 {
513 return value->String();
514 }
515 else
516 {
517 return TString("Invalid");
518 }
519}
520
521//_____________________________________________________________________________
8741815f 522TString
523AliMUONTrackerData::ExternalDimensionName(Int_t dim) const
0145e89a 524{
8741815f 525 /// Get the name of a given external dimension
526
527 TObjString* value = static_cast<TObjString*>(fExternalDimensionNames->At(dim));
528 if ( value )
529 {
530 return value->String();
531 }
532 else
533 {
534 return TString("Invalid");
535 }
0145e89a 536}
537
538//_____________________________________________________________________________
8741815f 539void
540AliMUONTrackerData::FillChannel(Int_t detElemId, Int_t manuId, Int_t manuChannel,
541 Int_t dim, Double_t value)
0145e89a 542{
8741815f 543 /// Fill histogram of a given channel
544
10eb3d17 545 AliMUONSparseHisto* h = GetChannelSparseHisto(detElemId, manuId, manuChannel,dim);
8741815f 546
547 h->Fill(static_cast<Int_t>(TMath::Nint(value)));
0145e89a 548}
549
550//_____________________________________________________________________________
10eb3d17 551AliMUONSparseHisto*
552AliMUONTrackerData::GetChannelSparseHisto(Int_t detElemId, Int_t manuId,
553 Int_t manuChannel, Int_t dim) const
8741815f 554{
10eb3d17 555 /// Get histogram of a given channel
8741815f 556
10eb3d17 557 if (!fChannelHistos) return 0x0;
8741815f 558
10eb3d17 559 AliMUON1DMap* m = static_cast<AliMUON1DMap*>(fChannelHistos->FindObject(detElemId,manuId));
560 if (!m) return 0x0;
8741815f 561
10eb3d17 562 UInt_t uid = ( manuChannel << 16 ) | dim;
8741815f 563
10eb3d17 564 AliMUONSparseHisto* h = static_cast<AliMUONSparseHisto*>(m->FindObject(uid));
8741815f 565
566 return h;
567}
0145e89a 568
8741815f 569//_____________________________________________________________________________
570AliMUONSparseHisto*
10eb3d17 571AliMUONTrackerData::GetChannelSparseHisto(Int_t detElemId, Int_t manuId,
572 Int_t manuChannel, Int_t dim)
8741815f 573{
10eb3d17 574 /// Get histogram of a given channel. Create it if necessary
8741815f 575
576 if (!fChannelHistos) fChannelHistos = new AliMUON2DMap(kTRUE);
577
10eb3d17 578 AliMUON1DMap* m = static_cast<AliMUON1DMap*>(fChannelHistos->FindObject(detElemId,manuId));
579 if (!m)
8741815f 580 {
10eb3d17 581 m = new AliMUON1DMap(AliMpConstants::ManuNofChannels()); // start with only 1 dim
582 m->SetUniqueID( ( manuId << 16 ) | detElemId );
583 fChannelHistos->Add(m);
8741815f 584 }
585
10eb3d17 586 UInt_t uid = ( manuChannel << 16 ) | dim;
8741815f 587
10eb3d17 588 AliMUONSparseHisto* h = static_cast<AliMUONSparseHisto*>(m->FindObject(uid));
8741815f 589 if (!h)
590 {
10eb3d17 591 h = new AliMUONSparseHisto(fXmin,fXmax);
592
593 h->SetUniqueID(uid);
594
595 m->Add(h);
8741815f 596 }
0145e89a 597
8741815f 598 return h;
599}
0145e89a 600
8741815f 601//_____________________________________________________________________________
602Int_t
603AliMUONTrackerData::GetParts(AliMUONVCalibParam* external,
604 AliMUONVCalibParam*& chamber,
605 AliMUONVCalibParam*& de,
606 AliMUONVCalibParam*& busPatch,
607 AliMUONVCalibParam*& pcb,
608 AliMUONVCalibParam*& manu,
609 AliMUONVCalibParam*& channel,
610 AliMpDetElement*& mpde)
611{
612 /// Get containers at all levels
613
614 AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
615
7b6684fe 616 Int_t detElemId;
617 Int_t manuId;
8741815f 618
7b6684fe 619 if ( external->ID1() <= 0 )
620 {
621 // we get a manu serial number
622 Int_t serial = external->ID0();
623 AliMpIntPair pair = ddlStore->GetDetElemIdManu(serial);
624 detElemId = pair.GetFirst();
625 manuId = pair.GetSecond();
626 if ( !detElemId )
627 {
628 AliError(Form("DE %d manuId %d from serial %d is not correct !",
629 detElemId,manuId,serial));
630 return -1;
631 }
632 }
633 else
634 {
635 // we get a (de,manu) pair
636 detElemId = external->ID0();
637 manuId = external->ID1();
638 }
639
8741815f 640 mpde = ddlStore->GetDetElement(detElemId);
7b6684fe 641
642 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
643
8741815f 644 Int_t busPatchId = ddlStore->GetBusPatchId(detElemId,manuId);
645
646 Int_t pcbIndex = -1;
647
648 AliMp::StationType stationType = mpde->GetStationType();
649
650 if ( stationType == AliMp::kStation345 )
651 {
652 AliMpHVNamer namer;
653 pcbIndex = namer.ManuId2PCBIndex(detElemId,manuId);
654 }
655
656 channel = ChannelParam(detElemId,manuId,external);
657
658 manu = ManuParam(detElemId,manuId,kTRUE);
659
660 busPatch = BusPatchParam(busPatchId,kTRUE);
661
662 de = DetectionElementParam(detElemId,kTRUE);
663
664 chamber = ChamberParam(chamberId,kTRUE);
665
666 pcb = 0x0;
667
668 if ( pcbIndex >= 0 )
669 {
670 pcb = PCBParam(detElemId,pcbIndex,kTRUE);
0145e89a 671 }
8741815f 672
673 return manuId;
674}
0145e89a 675
8741815f 676//_____________________________________________________________________________
677Bool_t
678AliMUONTrackerData::HasBusPatch(Int_t busPatchId) const
679{
680 /// Whether we have data for a given buspatch
681 return ( BusPatchParam(busPatchId) != 0 );
682}
683
684//_____________________________________________________________________________
685Bool_t
686AliMUONTrackerData::HasChamber(Int_t chamberId) const
687{
688 /// Whether we have data for a given chamber
689 return ( ChamberParam(chamberId) != 0 );
690}
691
692//_____________________________________________________________________________
693Bool_t
694AliMUONTrackerData::HasDetectionElement(Int_t detElemId) const
695{
696 /// Whether we have data for a given detection element
697 return ( DetectionElementParam(detElemId) != 0 );
698}
699
700//_____________________________________________________________________________
701Bool_t
702AliMUONTrackerData::HasManu(Int_t detElemId, Int_t manuId) const
703{
704 /// Whether we have data for a given manu
705 return ( ManuParam(detElemId,manuId) != 0 );
706}
707
708//_____________________________________________________________________________
709Bool_t
710AliMUONTrackerData::HasPCB(Int_t detElemId, Int_t pcbIndex) const
711{
712 /// Whether we have data for a given pcb
713 return ( PCBParam(detElemId,pcbIndex) != 0 );
0145e89a 714}
715
716//_____________________________________________________________________________
717Double_t
718AliMUONTrackerData::Manu(Int_t detElemId, Int_t manuId, Int_t dim) const
719{
9016a84e 720 /// Return the value for a given manu and a given dimension
721
0145e89a 722 AliMUONVCalibParam* param = ManuParam(detElemId,manuId);
723 return param ? Value(*param,0,dim) : 0.0;
724}
725
726//_____________________________________________________________________________
727AliMUONVCalibParam*
8741815f 728AliMUONTrackerData::ManuParam(Int_t detElemId, Int_t manuId, Bool_t create) const
0145e89a 729{
9016a84e 730 /// Get the VCalibParam for a given manu
8741815f 731
732 AliMUONVCalibParam* manu = fManuValues ? static_cast<AliMUONVCalibParam*>
733 (fManuValues->FindObject(detElemId,manuId)) : 0x0 ;
734
735 if (!manu && create && fManuValues)
736 {
737 manu = CreateManuParam(detElemId,manuId);
738 fManuValues->Add(manu);
739 }
740
741 return manu;
742}
743
744//_____________________________________________________________________________
745AliMUONVCalibParam*
746AliMUONTrackerData::CreateManuParam(Int_t detElemId, Int_t manuId) const
747{
748 /// Create storage for one manu
749
750 AliCodeTimerAuto("");
751
752 AliMUONVCalibParam* manu = new AliMUONCalibParamND(Dimension(),1,detElemId,manuId,0.0);
753
754 // set the number of channels in that manu
755
756 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
757
758 manu->SetValueAsDouble(0,IndexOfNumberDimension(),de->NofChannelsInManu(manuId));
759
760 return manu;
0145e89a 761}
762
763//_____________________________________________________________________________
7b6684fe 764Long64_t
4a3224ff 765AliMUONTrackerData::Merge(TCollection*)
7b6684fe 766{
767 /// Merge all tracker data objects from li into a single one.
768
769 AliError("Not implemented yet");
770
771 return 0;
772}
773
774//_____________________________________________________________________________
0145e89a 775Int_t
776AliMUONTrackerData::NumberOfDimensions() const
777{
778 /// Number of dimensions we're dealing with
779
780 return fDimension + fgkVirtualExtraDimension;
781}
782
783//_____________________________________________________________________________
784Double_t
785AliMUONTrackerData::PCB(Int_t detElemId, Int_t pcbIndex, Int_t dim) const
786{
787 /// Return the value of a given pcb for a given dimension
788
789 AliMUONVCalibParam* param = PCBParam(detElemId,pcbIndex);
790
791 return param ? Value(*param,pcbIndex,dim) : 0.0;
792}
793
794//_____________________________________________________________________________
795AliMUONVCalibParam*
8741815f 796AliMUONTrackerData::PCBParam(Int_t detElemId, Int_t pcbIndex, Bool_t create) const
0145e89a 797{
798 /// Return (if it exist) the VCalibParam for a given pcb
8741815f 799
800 AliMUONVCalibParam* pcb = fPCBValues ? static_cast<AliMUONVCalibParam*>
801 (fPCBValues->FindObject(detElemId,pcbIndex)) : 0x0 ;
802
803 if (create && fPCBValues && !pcb)
804 {
805 pcb = CreatePCBParam(detElemId,pcbIndex);
806 fPCBValues->Add(pcb);
807 }
808
809 return pcb;
810}
811
812//_____________________________________________________________________________
813AliMUONVCalibParam*
814AliMUONTrackerData::CreatePCBParam(Int_t detElemId, Int_t pcbIndex) const
815{
816 /// Create storage for one PCB (station345 only)
817
818 AliCodeTimerAuto("");
819
820 AliMpHVNamer namer;
821
822 AliMUONVCalibParam* pcb = new AliMUONCalibParamND(Dimension(),
823 namer.NumberOfPCBs(detElemId),
824 detElemId,
825 pcbIndex,
826 0.0);
827 return pcb;
0145e89a 828}
829
830//_____________________________________________________________________________
831void
832AliMUONTrackerData::Print(Option_t* wildcard, Option_t* opt) const
833{
834 /// Printout
835
836 TNamed::Print(opt);
837
838 if ( fIsRunnable )
839 {
840 cout << " Nevents=" << fNevents << endl;
841 }
8741815f 842
843 for ( Int_t i = 0; i <= fExternalDimensionNames->GetLast(); ++i )
844 {
845 TObjString* name = static_cast<TObjString*>(fExternalDimensionNames->At(i));
846 cout << Form("External Dimension %2d Name %s %s",i,
847 ( name ? name->String().Data() : "null"),
848 ( IsHistogrammed(i) ? "(histogrammed)" : "")) << endl;
849 }
0145e89a 850
851 for ( Int_t i = 0; i <= fDimensionNames->GetLast(); ++i )
852 {
853 TObjString* name = static_cast<TObjString*>(fDimensionNames->At(i));
8741815f 854 cout << Form("Internal Dimension %2d Name %s",i,
0145e89a 855 ( name ? name->String().Data() : "null")) << endl;
856 }
8741815f 857
0145e89a 858 TString sopt(opt);
859 sopt.ToUpper();
860
861 if ( sopt.Contains("CHANNEL") && fChannelValues )
862 {
863 fChannelValues->Print(wildcard,opt);
864 }
865
866 if ( sopt.Contains("MANU") && fManuValues )
867 {
868 fManuValues->Print(wildcard,opt);
869 }
870
871 if ( sopt.Contains("BUSPATCH") && fBusPatchValues )
872 {
873 fBusPatchValues->Print(wildcard,opt);
874 }
875
876 if ( sopt.Contains("DE") && fDEValues )
877 {
878 fDEValues->Print(wildcard,opt);
879 }
880
881 if ( sopt.Contains("CHAMBER") && fChamberValues )
882 {
883 fChamberValues->Print(wildcard,opt);
884 }
885
886}
887
888//_____________________________________________________________________________
889void
890AliMUONTrackerData::SetDimensionName(Int_t index, const char* name)
891{
892 /// Set the name of a given dimension
893
894 if ( index >= fExternalDimension )
895 {
896 AliError(Form("Index out of bounds : %d / %d",index,fExternalDimension));
897 return;
898 }
899
900 Int_t ix = External2Internal(index);
901
902 const char* prefix[] = { "mean", "sigma" };
903
904 for ( Int_t i = 0; i < 2; ++i )
905 {
906 Int_t j = ix+i;
907
908 SetInternalDimensionName(j,Form("%s of %s",prefix[i],name));
909 }
8741815f 910
911 SetExternalDimensionName(index,name);
912}
913
914//_____________________________________________________________________________
915void
10eb3d17 916AliMUONTrackerData::MakeHistogramForDimension(Int_t index, Bool_t value, Double_t xmin, Double_t xmax)
8741815f 917{
918 /// decide to make histos for a given dimension
919 if ( index >= ExternalDimension() )
920 {
921 AliError(Form("Index out of bounds : %d / %d",index,ExternalDimension()));
922 return;
923 }
924
925 fHistogramming[index] = value;
10eb3d17 926 fXmin = xmin;
927 fXmax = xmax;
0145e89a 928}
929
930//_____________________________________________________________________________
931void
932AliMUONTrackerData::SetInternalDimensionName(Int_t index, const char* value)
933{
934 /// Set the name of a given internal dimension
935 if ( index >= fDimension )
936 {
937 AliError(Form("Index out of bounds : %d / %d",index,fDimension));
938 return;
939 }
940
941 TObjString* ovalue = static_cast<TObjString*>(fDimensionNames->At(index));
942
943 if ( ovalue )
944 {
945 fDimensionNames->Remove(ovalue);
946 delete ovalue;
947 }
948 fDimensionNames->AddAt(new TObjString(value),index);
949}
950
951//_____________________________________________________________________________
8741815f 952void
953AliMUONTrackerData::SetExternalDimensionName(Int_t index, const char* value)
954{
955 /// Set the name of a given external dimension
956 if ( index >= fExternalDimension )
957 {
958 AliError(Form("Index out of bounds : %d / %d",index,fExternalDimension));
959 return;
960 }
961
962 TObjString* ovalue = static_cast<TObjString*>(fExternalDimensionNames->At(index));
963
964 if ( ovalue )
965 {
966 fExternalDimensionNames->Remove(ovalue);
967 delete ovalue;
968 }
969 fExternalDimensionNames->AddAt(new TObjString(value),index);
970}
971
972//_____________________________________________________________________________
0145e89a 973Double_t
974AliMUONTrackerData::Value(const AliMUONVCalibParam& param, Int_t i, Int_t dim) const
975{
976 /// Compute the value for a given dim, using the internal information we have
977 /// Basically we're converting sum of weights and sum of squares of weights
978 /// into means and sigmas, and number of events into occupancy number.
979
980 Double_t n = param.ValueAsDouble(i,IndexOfNumberDimension());
981
982 if ( dim == IndexOfNumberDimension() ) return n; // the number of channels in any given element does not depend on the number of events
983
984 Double_t occ = param.ValueAsDouble(i,IndexOfOccupancyDimension());
985
986 if ( dim >= fDimension )
987 {
988 return occ;
989 }
990
991 if ( dim == IndexOfOccupancyDimension() ) return occ/n/NumberOfEvents();
992
993 Double_t value = param.ValueAsDouble(i,dim);
994
995 if ( value >= AliMUONVCalibParam::InvalidFloatValue() ) return AliMUONVCalibParam::InvalidFloatValue();
996
997 if ( TMath::Even(dim) )
998 {
999 return value/occ;
1000 }
1001 else
1002 {
41992c50 1003 Double_t n = occ;
0145e89a 1004
41992c50 1005 Double_t mean = param.ValueAsDouble(i,dim-1)/n;
b0565451 1006
41992c50 1007 return TMath::Sqrt(TMath::Abs((value-n*mean*mean)/(n-1.0)));
0145e89a 1008 }
1009
1010 AliError("Why am I here ?");
1011 return 0.0;
1012}
1013