]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSegmentation.cxx
- Disentangle masks effect from trigger chamber efficiency estimation.
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSegmentation.cxx
CommitLineData
cf9a1555 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
490da820 16// $Id$
69417637 17// $MpId: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
490da820 18// Category: management
700013f0 19
3d1463c8 20//-----------------------------------------------------------------------------
69417637 21// Class AliMpSegmentation
490da820 22// -----------------------
69417637 23// Singleton container class for mapping segmentations
490da820 24// Authors: Ivana Hrivnacova, IPN Orsay
2c605e66 25// Laurent Aphecetche, SUBATECH
3d1463c8 26//-----------------------------------------------------------------------------
cf9a1555 27
69417637 28#include "AliMpSegmentation.h"
b802839b 29
228fd720 30#include "AliMpDataStreams.h"
cddd101e 31#include "AliMpDetElement.h"
24f9bd97 32#include "AliMpDEStore.h"
cf9a1555 33#include "AliMpDEManager.h"
69417637 34#include "AliMpDEIterator.h"
b802839b 35#include "AliMpExMap.h"
7a170a5c 36#include "AliMpFastSegmentation.h"
6e97fbb8 37//#include "AliMpFastSegmentationV2.h"
cf9a1555 38#include "AliMpSector.h"
39#include "AliMpSectorReader.h"
40#include "AliMpSectorSegmentation.h"
41#include "AliMpSlat.h"
cf9a1555 42#include "AliMpSlatSegmentation.h"
b802839b 43#include "AliMpSt345Reader.h"
cf9a1555 44#include "AliMpTrigger.h"
45#include "AliMpTriggerReader.h"
46#include "AliMpTriggerSegmentation.h"
cddd101e 47#include "AliMpCathodType.h"
dede1525 48#include "AliMpSlatMotifMap.h"
49
2c605e66 50
51#include "AliLog.h"
52
cf9a1555 53#include <Riostream.h>
cf9a1555 54#include <TMap.h>
b802839b 55#include <TObjString.h>
56#include <TSystem.h>
5f377a9a 57#include <TClass.h>
cf9a1555 58
630711ed 59#include <cassert>
60
13985652 61/// \cond CLASSIMP
69417637 62ClassImp(AliMpSegmentation)
13985652 63/// \endcond
cf9a1555 64
69417637 65AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
66
67//
68// static methods
69//
70
71//______________________________________________________________________________
5f377a9a 72AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
69417637 73{
5f377a9a 74/// Return its instance
69417637 75
5f377a9a 76 if ( ! fgInstance && warn ) {
77 AliWarningClass("Segmentation has not been loaded");
78 }
69417637 79
80 return fgInstance;
81}
82
5f377a9a 83//______________________________________________________________________________
ab167304 84AliMpSegmentation* AliMpSegmentation::ReadData(const AliMpDataStreams& dataStreams,
d2d10ee1 85 Bool_t warn)
5f377a9a 86{
87/// Load the sementation from ASCII data files
d2d10ee1 88/// and return its instance
5f377a9a 89
90 if ( fgInstance ) {
91 if ( warn )
92 AliWarningClass("Segmentation has been already loaded");
93 return fgInstance;
94 }
95
d2d10ee1 96 if ( dataStreams.GetReadFromFiles() )
97 AliInfoClass("Reading segmentation from ASCII files.");
5f377a9a 98
d2d10ee1 99 fgInstance = new AliMpSegmentation(dataStreams);
5f377a9a 100 return fgInstance;
101}
102
69417637 103//
104// ctors, dtor
105//
0cfc27d7 106
cf9a1555 107//______________________________________________________________________________
ab167304 108AliMpSegmentation::AliMpSegmentation(const AliMpDataStreams& dataStreams)
b802839b 109: TObject(),
7d5d0cc5 110 fkDataStreams(dataStreams),
24f9bd97 111 fDetElements(0),
183279c1 112 fMpSegmentations(true),
630711ed 113 fElCardsMap(),
183279c1 114 fSlatMotifMap(new AliMpSlatMotifMap)
cf9a1555 115{
5f377a9a 116/// Standard constructor - segmentation is loaded from ASCII data files
69417637 117
118 AliDebug(1,"");
24f9bd97 119
183279c1 120 fElCardsMap.SetOwner(kTRUE);
121
24f9bd97 122 // Load DE data
123 if ( ! AliMpDEStore::Instance(false) )
ab167304 124 AliMpDEStore::ReadData(dataStreams);
24f9bd97 125 fDetElements = AliMpDEStore::Instance();
d2d10ee1 126
69417637 127 // Create mapping segmentations for all detection elements
69417637 128 AliMpDEIterator it;
630711ed 129 for ( it.First(); ! it.IsDone(); it.Next() )
130 {
131 Int_t n(0);
132
133 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
134 {
135 if ( CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
f54f81ea 136 }
630711ed 137
138 if ( n == 2 && // should always be the case except when we play with the CreateMpSegmentation method...
139 AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker
140 {
141 // Fill el cards map for all detection elements
142 // of tracking chambers
143 FillElCardsMap(it.CurrentDEId());
144 }
145 }
cf9a1555 146}
147
cf9a1555 148//______________________________________________________________________________
630711ed 149AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
69417637 150: TObject(),
7d5d0cc5 151 fkDataStreams(ioCtor),
24f9bd97 152 fDetElements(0),
69417637 153 fMpSegmentations(),
630711ed 154 fElCardsMap(ioCtor),
dede1525 155 fSlatMotifMap(0)
69417637 156{
157/// Constructor for IO
158
cddd101e 159 AliDebug(1,"");
160
69417637 161 fgInstance = this;
162}
cf9a1555 163
69417637 164//______________________________________________________________________________
165AliMpSegmentation::~AliMpSegmentation()
cf9a1555 166{
167/// Destructor
168
b802839b 169 AliDebug(1,"");
490da820 170
24f9bd97 171 delete fDetElements;
172
69417637 173 // Segmentations are deleted with fMpSegmentations
174 // El cards arrays are deleted with fElCardsMap
490da820 175
183279c1 176 delete fSlatMotifMap;
177
69417637 178 fgInstance = 0;
490da820 179}
180
cf9a1555 181//
69417637 182// private methods
cf9a1555 183//
184
185//______________________________________________________________________________
186AliMpVSegmentation*
cddd101e 187AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
cf9a1555 188{
189/// Create mapping segmentation for given detElemId and cath
190/// or return it if it was already built
191
192 // Check detElemId & cath
cddd101e 193 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
cf9a1555 194
195 // If segmentation is already built, just return it
196 //
cddd101e 197 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
198 TString deSegName = detElement->GetSegName(cath);
199 TObject* object = fMpSegmentations.Get(deSegName);
cf9a1555 200 if ( object ) return (AliMpVSegmentation*)object;
201
0cfc27d7 202 AliDebugStream(3)
203 << "Creating segmentation for detElemId=" << detElemId
204 << " cath=" << cath << endl;
b802839b 205
cf9a1555 206 // Read mapping data and create segmentation
207 //
cddd101e 208 AliMp::StationType stationType = detElement->GetStationType();
209 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
210 TString deTypeName = detElement->GetSegType();
cf9a1555 211
212 AliMpVSegmentation* mpSegmentation = 0;
213
4e51cfd2 214 if ( stationType == AliMp::kStation12 ) {
215 AliMq::Station12Type station12Type = detElement->GetStation12Type();
7d5d0cc5 216 AliMpSectorReader reader(fkDataStreams, station12Type, planeType);
cf9a1555 217 AliMpSector* sector = reader.BuildSector();
7a170a5c 218 mpSegmentation = new AliMpFastSegmentation(new AliMpSectorSegmentation(sector, true));
cf9a1555 219 }
cddd101e 220 else if ( stationType == AliMp::kStation345 ) {
7d5d0cc5 221 AliMpSt345Reader reader(fkDataStreams,fSlatMotifMap);
f54f81ea 222 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
7a170a5c 223 mpSegmentation = new AliMpFastSegmentation(new AliMpSlatSegmentation(slat, true));
cf9a1555 224 }
cddd101e 225 else if ( stationType == AliMp::kStationTrigger ) {
7d5d0cc5 226 AliMpTriggerReader reader(fkDataStreams,fSlatMotifMap);
f54f81ea 227 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
69417637 228 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
cf9a1555 229 }
230 else
231 AliErrorStream() << "Unknown station type" << endl;
232
630711ed 233 if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
f54f81ea 234
1a3b5b04 235// StdoutToAliDebug(3, fSlatMotifMap.Print(););
f54f81ea 236
cf9a1555 237 return mpSegmentation;
238}
b802839b 239
240//_____________________________________________________________________________
69417637 241AliMpExMap*
242AliMpSegmentation::FillElCardsMap(Int_t detElemId)
b802839b 243{
69417637 244/// Fill the map of electronic cards IDs to segmentations for
245/// given detElemId
490da820 246
69417637 247 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
b802839b 248
630711ed 249 AliMpExMap* mde = new AliMpExMap;
69417637 250 mde->SetOwner(kFALSE);
251 fElCardsMap.Add(detElemId,mde);
252
253 const AliMpVSegmentation* seg[2];
254 TArrayI ecn[2];
255
cddd101e 256 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
b802839b 257 {
cddd101e 258 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
69417637 259 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
69417637 260 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
261 {
262 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
263 }
264 }
265
630711ed 266 assert( mde->GetSize() > 0 );
267
69417637 268 return mde;
630711ed 269
b802839b 270}
69417637 271
272//
273// public methods
274//
275
cf9a1555 276//______________________________________________________________________________
69417637 277const AliMpVSegmentation*
278AliMpSegmentation::GetMpSegmentation(
cddd101e 279 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
cf9a1555 280{
69417637 281/// Return mapping segmentation for given detElemId and cath
282
283 // Check detElemId & cath
cddd101e 284 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
69417637 285
286 if ( warn ) {
287 AliWarningStream()
cddd101e 288 << "Invalid detElemId " << detElemId << endl;
69417637 289 }
290 return 0;
291 }
292
cddd101e 293 // If segmentation is already built, just return it
294 //
295 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
296 TString deSegName = detElement->GetSegName(cath);
297 TObject* object = fMpSegmentations.Get(deSegName);
69417637 298 if ( ! object ) {
299 // Should never happen
300 AliErrorStream()
301 << "Segmentation for detElemId/cathod "
302 << detElemId << ", " << cath << " not defined" << endl;
303 return 0;
304 }
305
306 return static_cast<AliMpVSegmentation*>(object);
307}
cf9a1555 308
69417637 309//_____________________________________________________________________________
310const AliMpVSegmentation*
311AliMpSegmentation::GetMpSegmentationByElectronics(
312 Int_t detElemId, Int_t ecId, Bool_t warn) const
313{
314/// Return mapping segmentation for given detElemId and electronic card Id
315/// (motif position Id)
316
317 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
318
319 if (!m) {
320 // Should never happen
321 AliErrorStream()
322 << "Cannot find the el cards map for detElemId " << detElemId << endl;
323 return 0;
324 }
325
326 TObject* object = m->GetValue(ecId);
327 if ( ! object ) {
328 if ( warn ) {
329 AliErrorStream()
330 << "Segmentation for electronic card "
331 << ecId << " not found" << endl;
332 }
333 return 0;
334 }
335
336 return static_cast<AliMpVSegmentation*>(object);
337}
f3ed9a44 338
339//_____________________________________________________________________________
340const AliMpSector*
341AliMpSegmentation::GetSector(const AliMpVSegmentation* kSegmentation,
342 Bool_t warn) const
343{
344/// Return sector for given mapping segmentation.
345/// If segmentation is not of sector type, zero is returned
346/// and an Error is issued if warn is set true (default).
347
348 if ( ! kSegmentation ) return 0;
349
350 if ( kSegmentation->StationType() != AliMp::kStation12 ) {
351 if ( warn ) {
352 AliErrorStream()
353 << "Segmentation is not of sector type" << endl;
354 }
355 return 0;
356 }
7a170a5c 357
358 // If fast segmentation
359 const AliMpFastSegmentation* fseg
360 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
361 if ( fseg ) {
362 return
363 static_cast<const AliMpSectorSegmentation*>(fseg->GetHelper())->GetSector();
364 }
365
6e97fbb8 366 // If fast segmentation V2
367/*
368 const AliMpFastSegmentationV2* fsegV2
369 = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
370 if ( fsegV2 ) {
371 return
372 static_cast<const AliMpSectorSegmentation*>(fsegV2->GetHelper())->GetSector();
373 }
374*/
7a170a5c 375 // If sector segmentation
376 const AliMpSectorSegmentation* sseg
377 = dynamic_cast<const AliMpSectorSegmentation*>(kSegmentation);
378 if ( sseg ) {
379 return sseg->GetSector();
380 }
f3ed9a44 381
7a170a5c 382 // Should not get to this line
383 AliErrorStream() << "Segemntation type not identified." << endl;
384 return 0;
f3ed9a44 385}
386
387//_____________________________________________________________________________
388const AliMpSector*
389AliMpSegmentation::GetSector(Int_t detElemId, AliMp::CathodType cath,
390 Bool_t warn) const
391{
392/// Return sector for given detElemId and cath.
393/// If segmentation is not of sector type, zero is returned
394/// and an Error is issued if warn is set true (default).
395
396 return GetSector(GetMpSegmentation(detElemId, cath, warn), warn);
397}
398
399//_____________________________________________________________________________
400const AliMpSector*
401AliMpSegmentation::GetSectorByElectronics(Int_t detElemId, Int_t elCardID,
402 Bool_t warn) const
403{
404/// Return sector for given detElemId and elCardID.
405/// If segmentation is not of sector type, zero is returned
406/// and an Error is issued if warn is set true (default).
407
408 return GetSector(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
409}
410
411//_____________________________________________________________________________
412const AliMpSlat*
413AliMpSegmentation::GetSlat(const AliMpVSegmentation* kSegmentation,
414 Bool_t warn) const
415{
416/// Return slat for given mapping segmentation.
417/// If segmentation is not of slat type, zero is returned
418/// and an Error is issued if warn is set true (default).
419
420 if ( ! kSegmentation ) return 0;
421
422 if ( kSegmentation->StationType() != AliMp::kStation345 ) {
423 if ( warn ) {
424 AliErrorStream()
425 << "Segmentation is not of slat type" << endl;
426 }
427 return 0;
428 }
429
7a170a5c 430 // If fast segmentation
431 const AliMpFastSegmentation* fseg
432 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
433 if ( fseg ) {
434 return
435 static_cast<const AliMpSlatSegmentation*>(fseg->GetHelper())->Slat();
436 }
437
6e97fbb8 438 // If fast segmentation V2
439/*
440 const AliMpFastSegmentationV2* fsegV2
441 = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
442 if ( fsegV2 ) {
443 return
444 static_cast<const AliMpSlatSegmentation*>(fsegV2->GetHelper())->Slat();
445 }
446*/
7a170a5c 447 // If slat segmentation
448 const AliMpSlatSegmentation* sseg
449 = dynamic_cast<const AliMpSlatSegmentation*>(kSegmentation);
450
451 if ( sseg ) {
452 return sseg->Slat();
453 }
454
455 // Should not get to this line
456 AliErrorStream() << "Segemntation type not identified." << endl;
457 return 0;
f3ed9a44 458}
459
460//_____________________________________________________________________________
461const AliMpSlat*
462AliMpSegmentation::GetSlat(Int_t detElemId, AliMp::CathodType cath,
463 Bool_t warn) const
464{
465/// Return slat for given detElemId and cath.
466/// If segmentation is not of slat type, zero is returned
467/// and an Error is issued if warn is set true (default).
468
469 return GetSlat(GetMpSegmentation(detElemId, cath, warn), warn);
470}
471
472//_____________________________________________________________________________
473const AliMpSlat*
474AliMpSegmentation::GetSlatByElectronics(Int_t detElemId, Int_t elCardID,
475 Bool_t warn) const
476{
477/// Return slat for given detElemId and elCardID.
478/// If segmentation is not of slat type, zero is returned
479/// and an Error is issued if warn is set true (default).
480
481 return GetSlat(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
482}
483
484//_____________________________________________________________________________
485const AliMpTrigger*
486AliMpSegmentation::GetTrigger(const AliMpVSegmentation* kSegmentation,
487 Bool_t warn) const
488{
489/// Return trigger for given mapping segmentation.
490/// If segmentation is not of trigger type, zero is returned
491/// and an Error is issued if warn is set true (default).
492
493 if ( ! kSegmentation ) return 0;
494
495 if ( kSegmentation->StationType() != AliMp::kStationTrigger ) {
496 if ( warn ) {
497 AliErrorStream()
498 << "Segmentation is not of trigger type" << endl;
499 }
500 return 0;
501 }
502
7a170a5c 503 // If slat segmentation
504 const AliMpTriggerSegmentation* tseg
505 = dynamic_cast<const AliMpTriggerSegmentation*>(kSegmentation);
506 if ( tseg ) {
507 return tseg->Slat();
508 }
509
510 // If fast segmentation
511 const AliMpFastSegmentation* fseg
512 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
513
514 if ( fseg ) {
515 return
516 static_cast<const AliMpTriggerSegmentation*>(fseg->GetHelper())->Slat();
517 }
518
6e97fbb8 519 // If fast segmentation V2
520/*
521 const AliMpFastSegmentationV2* fsegV2
522 = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
523
524 if ( fsegV2 ) {
525 return
526 static_cast<const AliMpTriggerSegmentation*>(fsegV2->GetHelper())->Slat();
527 }
528*/
529
7a170a5c 530 // Should not get to this line
531 AliErrorStream() << "Segemntation type not identified." << endl;
532 return 0;
f3ed9a44 533}
534
535//_____________________________________________________________________________
536const AliMpTrigger*
537AliMpSegmentation::GetTrigger(Int_t detElemId, AliMp::CathodType cath,
538 Bool_t warn) const
539{
540/// Return trigger for given detElemId and cath.
541/// If segmentation is not of trigger type, zero is returned
542/// and an Error is issued if warn is set true (default).
543
544 return GetTrigger(GetMpSegmentation(detElemId, cath, warn), warn);
545}
546
547//_____________________________________________________________________________
548const AliMpTrigger*
549AliMpSegmentation::GetTriggerByElectronics(Int_t detElemId, Int_t elCardID,
550 Bool_t warn) const
551{
552/// Return trigger for given detElemId and elCardID.
553/// If segmentation is not of trigger type, zero is returned
554/// and an Error is issued if warn is set true (default).
555
556 return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
557}