1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 /// \class AliMUONSegmentTree
21 /// Implementation of a segment tree, which is used to make contour
22 /// merging (see AliMUONContourMaker)
24 /// \author Laurent Aphecetche, Subatech
27 #include "AliMUONSegmentTree.h"
30 #include "AliMUONNode.h"
31 #include "Riostream.h"
36 ClassImp(AliMUONSegmentTree)
39 //_____________________________________________________________________________
40 AliMUONSegmentTree::AliMUONSegmentTree(const TArrayD& values)
41 : fRoot(0x0), fStack()
43 /// Values should be sorted and have at least 2 elements.
45 fStack.SetOwner(kTRUE);
47 if ( values.GetSize() < 2 )
49 AliFatal("cannot build a segmenttree with less than 2 values !");
52 fRoot = Build(values,0,values.GetSize()-1);
55 //_____________________________________________________________________________
56 AliMUONSegmentTree::~AliMUONSegmentTree()
62 //_____________________________________________________________________________
64 AliMUONSegmentTree::Build(const TArrayD& values, Int_t i, Int_t j)
66 /// Build the segment tree from a list of values
68 double midpoint(TMath::Sqrt(-1.0));
71 if ( mid != i && mid != j ) midpoint = values[mid];
73 AliMUONNode* node = new AliMUONNode(values[i],values[j],midpoint);
75 if ( j - i == 1 ) return node;
77 node->LeftNode(Build(values,i,(i+j)/2));
78 node->RightNode(Build(values,(i+j)/2,j));
83 //_____________________________________________________________________________
85 AliMUONSegmentTree::Contribution(double b, double e)
87 /// Compute the contribution of edge (b,e)
88 fRoot->Contribution(b,e,fStack);
91 //_____________________________________________________________________________
93 AliMUONSegmentTree::InsertInterval(double b, double e)
95 /// Insert interval (b,e)
96 fRoot->InsertInterval(b,e,fStack);
99 //_____________________________________________________________________________
101 AliMUONSegmentTree::DeleteInterval(double b, double e)
103 /// Delete interval (b,e)
104 fRoot->DeleteInterval(b,e,fStack);
107 //_____________________________________________________________________________
109 AliMUONSegmentTree::Print(Option_t*) const
115 cout << "Empty binary tree" << endl;