]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/flow/AliFMDFlowSplitter.cxx
coverity 15108 fixed
[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>
b09247a2 28#include <cstdlib>
9b98d361 29#include <iostream>
30
31//____________________________________________________________________
32Bool_t
33AliFMDFlowSplitter::Select(ULong_t) const
34{
35 // Decide whether entry should go in A or B sub-event.
36 // Parameters:
37 // entry The entry number
38 // Return
39 // true if this should go in sub-event A
133f1578 40 // return (Float_t(rand()) / RAND_MAX > 0.5);
41 return fRandom.Uniform(0,1);
9b98d361 42}
43
44
45//____________________________________________________________________
46void
47AliFMDFlowShuffle::Event(Double_t*, Double_t*, ULong_t n)
48{
49 // Prepare for an event
50 // Parameters
51 // phis List of phis.
52 // xs List of bin variable
53 // n Number of entries in @a phis and @a n
54 // Return
55 fN = n;
56 Shuffle();
57}
58
59//____________________________________________________________________
60Bool_t
61AliFMDFlowShuffle::Select(ULong_t entry) const
62{
63 // Decide whether entry should go in A or B sub-event.
64 // Parameters:
65 // entry The entry number
66 // Return
67 // true if this should go in sub-event A
68 if (entry >= fN || Int_t(entry) >= fIdx.fN) return false;
69 ULong_t n = fIdx[entry];
70 return (n < fN/2);
71}
72
73//____________________________________________________________________
74void
75AliFMDFlowShuffle::Shuffle()
76{
77 // Suffle index
78 if (fIdx.fN < Int_t(fN)) fIdx.Set(fN);
79 for (ULong_t i = 0; i < fN; i++) fIdx[i] = i;
80 for (ULong_t i = 0; i < fN; i++) {
81 // Swap 2 random locations
82 ULong_t j = ULong_t(gRandom->Rndm()*(fN-1));
83 ULong_t k = fIdx[j];
84 fIdx[j] = fIdx[i];
85 fIdx[i] = k;
86 }
87}
88
89//____________________________________________________________________
90//
91// EOF
92//