Logo ROOT  
Reference Guide
RooBlindTools.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$Id$
5 * Authors: *
6 * AR, Aaron Roodman, Stanford University, roodman@slac.stanford.edu *
7 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/** \class RooBlindTools
18 \ingroup Roofit
19
20**/
21
22#include "RooFit.h"
23
24#include "RooBlindTools.h"
25
26#include "RooErrorHandler.h"
27#include "Riostream.h"
28#include <fstream>
29#include <math.h>
30#include <string.h>
31#include <ctype.h>
32
33using namespace std;
34
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor
39
41 Double_t centralValue, Double_t sigmaOffset, Bool_t s2bMode) :
42
43 _PrecisionOffsetScale(sigmaOffset),
44 _PrecisionCentralValue(centralValue),
45 _mode(Mode),
46 _s2bMode(s2bMode)
47{
48 setup(stSeedIn);
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Constructor
53
55 _PrecisionOffsetScale(blindTool.getPrecisionOffsetScale()),
56 _PrecisionCentralValue(blindTool.getPrecisionCentralValue()),
57 _mode(blindTool.mode()),
58 _s2bMode(blindTool._s2bMode)
59{
60 setup(blindTool.stSeed());
61}
62
63////////////////////////////////////////////////////////////////////////////////
64
65void RooBlindTools::setup(const char *stSeedIn)
66{
67 _stSeed = stSeedIn;
68
69 _DeltaZScale = 1.56;
70
71 _DeltaZOffset = _DeltaZScale*MakeOffset("abcdefghijklmnopqrstuvwxyz");
72
73 _DeltaZSignFlip = MakeSignFlip("ijklmnopqrstuvwxyzabcdefgh");
74
75 _AsymOffset = MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
76
77 _AsymSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
78
79 _DeltaMScale = 0.1;
80
81 _DeltaMOffset = _DeltaMScale*MakeOffset("opqrstuvwxyzabcdefghijklmn");
82
83 _MysteryPhase = 3.14159 *
84 MakeOffset("wxyzabcdefghijklmnopqrstuv");
85
86 if (_s2bMode) {
87 _PrecisionSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
88 } else {
89 _PrecisionSignFlip = MakeSignFlip("klmnopqrstuvwxyzabcdefghij");
90 }
91
92 _PrecisionOffset = _PrecisionOffsetScale*MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
93
94 _PrecisionUniform = _PrecisionOffsetScale*MakeOffset("jihgfedcbazyxwvutsrqponmlk");
95
96 _STagConstant = Randomizer("fghijklmnopqrstuvwxyzabcde");
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Destructor
101
103
104////////////////////////////////////////////////////////////////////////////////
105
107 Int_t sTag = SignOfTag(STag);
108 Double_t DeltaZPrime = _DeltaZSignFlip*DeltaZ*sTag + _DeltaZOffset;
109
110 return DeltaZPrime;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114
116 Int_t sTag = SignOfTag(STag);
117 Double_t DeltaZPrime = _DeltaZSignFlip*(DeltaZ - PdG)*sTag + _DeltaZOffset;
118
119 return DeltaZPrime;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123
125 Int_t sTag = SignOfTag(STag);
126 Double_t DeltaZ = (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
127
128 return DeltaZ;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132
134 Int_t sTag = SignOfTag(STag);
135 Double_t DeltaZ = PdG + (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
136
137 return DeltaZ;
138}
139
140////////////////////////////////////////////////////////////////////////////////
141
143 if(mode()==dataonly) return AsymPrime;
144
145 Double_t Asym = (AsymPrime - _AsymOffset)/_AsymSignFlip;
146
147 return Asym;
148}
149
150////////////////////////////////////////////////////////////////////////////////
151
153 if(mode()==dataonly) return Asym;
154
155 Double_t AsymPrime = Asym*_AsymSignFlip + _AsymOffset;
156
157 return AsymPrime;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161
163 if(mode()==dataonly) return DeltaMPrime;
164
165 Double_t DeltaM = DeltaMPrime - _DeltaMOffset;
166
167 return DeltaM;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171
173 if(mode()==dataonly) return DeltaM;
174
175 Double_t DeltaMPrime = DeltaM + _DeltaMOffset;
176
177 return DeltaMPrime;
178}
179
180////////////////////////////////////////////////////////////////////////////////
181
183 if(mode()==dataonly) return AsymPrime;
184
185 Double_t Asym = PdG + (AsymPrime - _AsymOffset)/_AsymSignFlip;
186
187 return Asym;
188}
189
190////////////////////////////////////////////////////////////////////////////////
191
193 if(mode()==dataonly) return 0.0;
194
195 return _MysteryPhase;
196}
197
198////////////////////////////////////////////////////////////////////////////////
199
201 if(mode()==dataonly) return Asym;
202
203 Double_t AsymPrime = (Asym - PdG)*_AsymSignFlip + _AsymOffset;
204
205 return AsymPrime;
206}
207
208////////////////////////////////////////////////////////////////////////////////
209
211 if(mode()==dataonly) return PrecisionPrime;
212
214
215 if (_PrecisionSignFlip>0) {
216 Precision = PrecisionPrime - _PrecisionOffset;
217 }
218 else {
219 Precision = 2.0*_PrecisionCentralValue - PrecisionPrime + _PrecisionOffset;
220 }
221
222
223 return Precision;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227
229 if(mode()==dataonly) return Precision;
230
231 Double_t PrecisionPrime(0.);
232
233 if (_PrecisionSignFlip>0) {
234 PrecisionPrime = Precision + _PrecisionOffset;
235 }
236 else {
237 PrecisionPrime = 2.0*_PrecisionCentralValue - Precision + _PrecisionOffset;
238 }
239
240 return PrecisionPrime;
241}
242
243////////////////////////////////////////////////////////////////////////////////
244
246 if(mode()==dataonly) return PrecisionPrime;
247
248 return PrecisionPrime - _PrecisionOffset;
249}
250
251////////////////////////////////////////////////////////////////////////////////
252
254 if(mode()==dataonly) return Precision;
255
257}
258
259////////////////////////////////////////////////////////////////////////////////
260
262 if(mode()==dataonly) return PrecisionPrime;
263
264 return PrecisionPrime - _PrecisionUniform;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268
270 if(mode()==dataonly) return Precision;
271
273}
274
275////////////////////////////////////////////////////////////////////////////////
276
278 Int_t Seed = EventNumber % 7997 + 2;
279 Double_t r = PseudoRandom(Seed);
280 Double_t STagPrime(0.0);
281
282 if (r < _STagConstant){
283 STagPrime = STag;
284 } else {
285 STagPrime = -1.0 * STag ;
286 }
287
288 return STagPrime;
289
290}
291
292////////////////////////////////////////////////////////////////////////////////
293
294Double_t RooBlindTools::Randomizer(const char *StringAlphabet) const{
295 char lowerseed[1024] ;
296 strlcpy(lowerseed,_stSeed,1024) ;
297
298 Int_t lengthSeed = strlen(lowerseed);
299
300 for (Int_t j=0; j<lengthSeed; j++){
301 lowerseed[j] =tolower(_stSeed[j]);
302 }
303 Int_t sumSeed = 0;
304 for (Int_t i=0; i<lengthSeed; i++){
305 for (Int_t iAlphabet=0; iAlphabet<26; iAlphabet++){
306 if ( lowerseed[i] == StringAlphabet[iAlphabet] ){
307 if (_s2bMode) {
308 sumSeed = (iAlphabet<<(5*(i%3)))^sumSeed;
309 } else {
310 sumSeed = sumSeed + iAlphabet ;
311 }
312 }
313 }
314 }
315
316 if (lengthSeed<5 || ((sumSeed<1 || sumSeed>8000)&&!_s2bMode)) {
317 cout<< "RooBlindTools::Randomizer: Your String Seed is Bad: '" << _stSeed << "'" << endl ;
319 }
320
321 Int_t ia = 8121;
322 Int_t ic = 28411;
323 Int_t im = 134456;
324 UInt_t jRan = (sumSeed*ia + ic) % im;
325
326 jRan = (jRan*ia + ic) % im;
327 jRan = (jRan*ia + ic) % im;
328 jRan = (jRan*ia + ic) % im;
329
330 Double_t theRan = (float) jRan / (float) im;
331
332 return theRan; //theRan is between 0.0 - 1.0
333
334}
335
336////////////////////////////////////////////////////////////////////////////////
337
339 if (Seed<1 || Seed>8000 ) {
340 cout<< "RooBlindTools::PseudoRandom: Your integer Seed is Bad" <<endl;
341 }
342
343 Int_t ia = 8121;
344 Int_t ic = 28411;
345 Int_t im = 134456;
346 UInt_t jRan = (Seed*ia + ic) % im;
347
348 jRan = (jRan*ia + ic) % im;
349 jRan = (jRan*ia + ic) % im;
350 jRan = (jRan*ia + ic) % im;
351
352 Double_t theRan = (float) jRan / (float) im;
353
354 return theRan; //theRan is between 0.0 - 1.0
355
356}
357
358////////////////////////////////////////////////////////////////////////////////
359
360Double_t RooBlindTools::MakeOffset(const char *StringAlphabet) const{
361 Double_t theRan = Randomizer(StringAlphabet);
362
363 Double_t theOffset = (2.0)*theRan - (1.0);
364
365 return theOffset; //theOffset lies between -1.0 and 1.0
366}
367
368////////////////////////////////////////////////////////////////////////////////
369
370Double_t RooBlindTools::MakeGaussianOffset(const char *StringAlphabet) const{
371 Double_t theRan1 = Randomizer(StringAlphabet);
372 Double_t theRan2 = Randomizer("cdefghijklmnopqrstuvwxyzab");
373
374 if (theRan1==0.0 || theRan1==1.0){
375 theRan1 = 0.5;
376 }
377 if (theRan2==0.0 || theRan2==1.0){
378 theRan2 = 0.5;
379 }
380
381 Double_t theOffset = sin(2.0*3.14159*theRan1)*sqrt(-2.0*log(theRan2));
382
383 return theOffset; //theOffset is Gaussian with mean 0, sigma 1
384}
385
386////////////////////////////////////////////////////////////////////////////////
387
388Double_t RooBlindTools::MakeSignFlip(const char *StringAlphabet) const{
389 Double_t theRan = Randomizer(StringAlphabet);
390
391 Double_t theSignFlip = 1.0;
392 if (theRan>0.5){
393 theSignFlip = 1.0;
394 } else {
395 theSignFlip = -1.0;
396 }
397
398 return theSignFlip; //theSignFlip is = +1 or -1
399}
400
401////////////////////////////////////////////////////////////////////////////////
402
404 Int_t sTag;
405 if (STag < 0.0){
406 sTag = -1;
407 }
408 else if (STag > 0.0) {
409 sTag = 1;
410 }
411 else {
412 sTag = 1;
413 }
414
415 return sTag;
416
417}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define ClassImp(name)
Definition: Rtypes.h:361
double sqrt(double)
double sin(double)
double log(double)
Double_t _DeltaMScale
Double_t HiAsPdG(Double_t Asym, Double_t PdG) const
Double_t _DeltaMOffset
Double_t _MysteryPhase
virtual ~RooBlindTools()
Destructor.
Double_t HiDelZPdG(Double_t DeltaZ, Double_t STag, Double_t PdG) const
Double_t RandomizeTag(Double_t STag, Int_t EventNumber) const
Double_t PseudoRandom(Int_t Seed) const
Double_t MakeSignFlip(const char *StringAlphabet) const
Double_t HideDeltaM(Double_t DeltaM) const
Double_t MysteryPhase() const
Double_t _DeltaZOffset
Double_t _PrecisionCentralValue
Double_t _PrecisionOffset
Double_t HideAsym(Double_t Asym) const
Double_t _PrecisionSignFlip
Double_t _DeltaZScale
void setup(const char *stSeed)
Double_t HideDeltaZ(Double_t DeltaZ, Double_t STag) const
Double_t MakeOffset(const char *StringAlphabet) const
Double_t UnHiAsPdG(Double_t AsymPrime, Double_t PdG) const
Double_t UnHideUniform(Double_t PrecisionBlind) const
Double_t _AsymOffset
Double_t UnHiDelZPdG(Double_t DeltaZPrime, Double_t STag, Double_t PdG) const
Double_t _PrecisionOffsetScale
Double_t _AsymSignFlip
Double_t _STagConstant
const char * stSeed() const
Int_t SignOfTag(Double_t STag) const
Double_t _PrecisionUniform
Double_t UnHideDeltaM(Double_t DeltaMPrime) const
Double_t HideUniform(Double_t Precision) const
const blindMode & mode() const
Double_t HidePrecision(Double_t Precision) const
Double_t _DeltaZSignFlip
Double_t UnHidePrecision(Double_t PrecisionPrime) const
Double_t UnHideDeltaZ(Double_t DeltaZPrime, Double_t STag) const
Double_t MakeGaussianOffset(const char *StringAlphabet) const
Double_t UnHideAsym(Double_t AsymPrime) const
Double_t HideOffset(Double_t Precision) const
Double_t UnHideOffset(Double_t PrecisionBlind) const
Double_t Randomizer(const char *StringAlphabet) const
static void softAbort()
RooCmdArg Precision(Double_t prec)