]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/flow/AliFMDFlowSplitter.cxx
merging post-CVS changes into SVN:
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowSplitter.cxx
CommitLineData
9b98d361 1/* Copyright (C) 2007 Christian Holm Christensen <cholm@nbi.dk>
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 2.1 of
6 * the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
16 * USA
17 */
18//____________________________________________________________________
19//
20// Object used by AliFMDFlowBinned1D to split an event into sub-events.
21// Default is to split randomly.
22// User defined derived classes can do other stuff.
23//
24#include "flow/AliFMDFlowSplitter.h"
25#include "flow/AliFMDFlowAxis.h"
26#include <TRandom.h>
27#include <cmath>
28#include <iostream>
29
30//____________________________________________________________________
31Bool_t
32AliFMDFlowSplitter::Select(ULong_t) const
33{
34 // Decide whether entry should go in A or B sub-event.
35 // Parameters:
36 // entry The entry number
37 // Return
38 // true if this should go in sub-event A
39 return (Float_t(rand()) / RAND_MAX > 0.5);
40}
41
42
43//____________________________________________________________________
44void
45AliFMDFlowShuffle::Event(Double_t*, Double_t*, ULong_t n)
46{
47 // Prepare for an event
48 // Parameters
49 // phis List of phis.
50 // xs List of bin variable
51 // n Number of entries in @a phis and @a n
52 // Return
53 fN = n;
54 Shuffle();
55}
56
57//____________________________________________________________________
58Bool_t
59AliFMDFlowShuffle::Select(ULong_t entry) const
60{
61 // Decide whether entry should go in A or B sub-event.
62 // Parameters:
63 // entry The entry number
64 // Return
65 // true if this should go in sub-event A
66 if (entry >= fN || Int_t(entry) >= fIdx.fN) return false;
67 ULong_t n = fIdx[entry];
68 return (n < fN/2);
69}
70
71//____________________________________________________________________
72void
73AliFMDFlowShuffle::Shuffle()
74{
75 // Suffle index
76 if (fIdx.fN < Int_t(fN)) fIdx.Set(fN);
77 for (ULong_t i = 0; i < fN; i++) fIdx[i] = i;
78 for (ULong_t i = 0; i < fN; i++) {
79 // Swap 2 random locations
80 ULong_t j = ULong_t(gRandom->Rndm()*(fN-1));
81 ULong_t k = fIdx[j];
82 fIdx[j] = fIdx[i];
83 fIdx[i] = k;
84 }
85}
86
87//____________________________________________________________________
88//
89// EOF
90//