Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "strlcpy.h"
28
29#include <iostream>
30#include <fstream>
31#include <cmath>
32#include <cstring>
33#include <cctype>
34
35using namespace std;
36
38
39////////////////////////////////////////////////////////////////////////////////
40/// Constructor
41
42RooBlindTools::RooBlindTools(const char *stSeedIn, blindMode Mode,
43 Double_t centralValue, Double_t sigmaOffset, Bool_t s2bMode) :
44
45 _PrecisionOffsetScale(sigmaOffset),
46 _PrecisionCentralValue(centralValue),
47 _mode(Mode),
48 _s2bMode(s2bMode)
49{
50 setup(stSeedIn);
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Constructor
55
57 _PrecisionOffsetScale(blindTool.getPrecisionOffsetScale()),
58 _PrecisionCentralValue(blindTool.getPrecisionCentralValue()),
59 _mode(blindTool.mode()),
60 _s2bMode(blindTool._s2bMode)
61{
62 setup(blindTool.stSeed());
63}
64
65////////////////////////////////////////////////////////////////////////////////
66
67void RooBlindTools::setup(const char *stSeedIn)
68{
69 _stSeed = stSeedIn;
70
71 _DeltaZScale = 1.56;
72
73 _DeltaZOffset = _DeltaZScale*MakeOffset("abcdefghijklmnopqrstuvwxyz");
74
75 _DeltaZSignFlip = MakeSignFlip("ijklmnopqrstuvwxyzabcdefgh");
76
77 _AsymOffset = MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
78
79 _AsymSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
80
81 _DeltaMScale = 0.1;
82
83 _DeltaMOffset = _DeltaMScale*MakeOffset("opqrstuvwxyzabcdefghijklmn");
84
85 _MysteryPhase = 3.14159 *
86 MakeOffset("wxyzabcdefghijklmnopqrstuv");
87
88 if (_s2bMode) {
89 _PrecisionSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
90 } else {
91 _PrecisionSignFlip = MakeSignFlip("klmnopqrstuvwxyzabcdefghij");
92 }
93
94 _PrecisionOffset = _PrecisionOffsetScale*MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
95
96 _PrecisionUniform = _PrecisionOffsetScale*MakeOffset("jihgfedcbazyxwvutsrqponmlk");
97
98 _STagConstant = Randomizer("fghijklmnopqrstuvwxyzabcde");
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Destructor
103
105
106////////////////////////////////////////////////////////////////////////////////
107
109 Int_t sTag = SignOfTag(STag);
110 Double_t DeltaZPrime = _DeltaZSignFlip*DeltaZ*sTag + _DeltaZOffset;
111
112 return DeltaZPrime;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116
118 Int_t sTag = SignOfTag(STag);
119 Double_t DeltaZPrime = _DeltaZSignFlip*(DeltaZ - PdG)*sTag + _DeltaZOffset;
120
121 return DeltaZPrime;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125
127 Int_t sTag = SignOfTag(STag);
128 Double_t DeltaZ = (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
129
130 return DeltaZ;
131}
132
133////////////////////////////////////////////////////////////////////////////////
134
136 Int_t sTag = SignOfTag(STag);
137 Double_t DeltaZ = PdG + (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
138
139 return DeltaZ;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143
145 if(mode()==dataonly) return AsymPrime;
146
147 Double_t Asym = (AsymPrime - _AsymOffset)/_AsymSignFlip;
148
149 return Asym;
150}
151
152////////////////////////////////////////////////////////////////////////////////
153
155 if(mode()==dataonly) return Asym;
156
157 Double_t AsymPrime = Asym*_AsymSignFlip + _AsymOffset;
158
159 return AsymPrime;
160}
161
162////////////////////////////////////////////////////////////////////////////////
163
165 if(mode()==dataonly) return DeltaMPrime;
166
167 Double_t DeltaM = DeltaMPrime - _DeltaMOffset;
168
169 return DeltaM;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173
175 if(mode()==dataonly) return DeltaM;
176
177 Double_t DeltaMPrime = DeltaM + _DeltaMOffset;
178
179 return DeltaMPrime;
180}
181
182////////////////////////////////////////////////////////////////////////////////
183
185 if(mode()==dataonly) return AsymPrime;
186
187 Double_t Asym = PdG + (AsymPrime - _AsymOffset)/_AsymSignFlip;
188
189 return Asym;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193
195 if(mode()==dataonly) return 0.0;
196
197 return _MysteryPhase;
198}
199
200////////////////////////////////////////////////////////////////////////////////
201
203 if(mode()==dataonly) return Asym;
204
205 Double_t AsymPrime = (Asym - PdG)*_AsymSignFlip + _AsymOffset;
206
207 return AsymPrime;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211
213 if(mode()==dataonly) return PrecisionPrime;
214
215 Double_t Precision(0.);
216
217 if (_PrecisionSignFlip>0) {
218 Precision = PrecisionPrime - _PrecisionOffset;
219 }
220 else {
221 Precision = 2.0*_PrecisionCentralValue - PrecisionPrime + _PrecisionOffset;
222 }
223
224
225 return Precision;
226}
227
228////////////////////////////////////////////////////////////////////////////////
229
231 if(mode()==dataonly) return Precision;
232
233 Double_t PrecisionPrime(0.);
234
235 if (_PrecisionSignFlip>0) {
236 PrecisionPrime = Precision + _PrecisionOffset;
237 }
238 else {
239 PrecisionPrime = 2.0*_PrecisionCentralValue - Precision + _PrecisionOffset;
240 }
241
242 return PrecisionPrime;
243}
244
245////////////////////////////////////////////////////////////////////////////////
246
248 if(mode()==dataonly) return PrecisionPrime;
249
250 return PrecisionPrime - _PrecisionOffset;
251}
252
253////////////////////////////////////////////////////////////////////////////////
254
256 if(mode()==dataonly) return Precision;
257
258 return Precision + _PrecisionOffset;
259}
260
261////////////////////////////////////////////////////////////////////////////////
262
264 if(mode()==dataonly) return PrecisionPrime;
265
266 return PrecisionPrime - _PrecisionUniform;
267}
268
269////////////////////////////////////////////////////////////////////////////////
270
272 if(mode()==dataonly) return Precision;
273
274 return Precision + _PrecisionUniform;
275}
276
277////////////////////////////////////////////////////////////////////////////////
278
280 Int_t Seed = EventNumber % 7997 + 2;
281 Double_t r = PseudoRandom(Seed);
282 Double_t STagPrime(0.0);
283
284 if (r < _STagConstant){
285 STagPrime = STag;
286 } else {
287 STagPrime = -1.0 * STag ;
288 }
289
290 return STagPrime;
291
292}
293
294////////////////////////////////////////////////////////////////////////////////
295
296Double_t RooBlindTools::Randomizer(const char *StringAlphabet) const{
297 char lowerseed[1024] ;
298 strlcpy(lowerseed,_stSeed,1024) ;
299
300 Int_t lengthSeed = strlen(lowerseed);
301
302 for (Int_t j=0; j<lengthSeed; j++){
303 lowerseed[j] =tolower(_stSeed[j]);
304 }
305 Int_t sumSeed = 0;
306 for (Int_t i=0; i<lengthSeed; i++){
307 for (Int_t iAlphabet=0; iAlphabet<26; iAlphabet++){
308 if ( lowerseed[i] == StringAlphabet[iAlphabet] ){
309 if (_s2bMode) {
310 sumSeed = (iAlphabet<<(5*(i%3)))^sumSeed;
311 } else {
312 sumSeed = sumSeed + iAlphabet ;
313 }
314 }
315 }
316 }
317
318 if (lengthSeed<5 || ((sumSeed<1 || sumSeed>8000)&&!_s2bMode)) {
319 cout<< "RooBlindTools::Randomizer: Your String Seed is Bad: '" << _stSeed << "'" << endl ;
321 }
322
323 Int_t ia = 8121;
324 Int_t ic = 28411;
325 Int_t im = 134456;
326 UInt_t jRan = (sumSeed*ia + ic) % im;
327
328 jRan = (jRan*ia + ic) % im;
329 jRan = (jRan*ia + ic) % im;
330 jRan = (jRan*ia + ic) % im;
331
332 Double_t theRan = (float) jRan / (float) im;
333
334 return theRan; //theRan is between 0.0 - 1.0
335
336}
337
338////////////////////////////////////////////////////////////////////////////////
339
341 if (Seed<1 || Seed>8000 ) {
342 cout<< "RooBlindTools::PseudoRandom: Your integer Seed is Bad" <<endl;
343 }
344
345 Int_t ia = 8121;
346 Int_t ic = 28411;
347 Int_t im = 134456;
348 UInt_t jRan = (Seed*ia + ic) % im;
349
350 jRan = (jRan*ia + ic) % im;
351 jRan = (jRan*ia + ic) % im;
352 jRan = (jRan*ia + ic) % im;
353
354 Double_t theRan = (float) jRan / (float) im;
355
356 return theRan; //theRan is between 0.0 - 1.0
357
358}
359
360////////////////////////////////////////////////////////////////////////////////
361
362Double_t RooBlindTools::MakeOffset(const char *StringAlphabet) const{
363 Double_t theRan = Randomizer(StringAlphabet);
364
365 Double_t theOffset = (2.0)*theRan - (1.0);
366
367 return theOffset; //theOffset lies between -1.0 and 1.0
368}
369
370////////////////////////////////////////////////////////////////////////////////
371
372Double_t RooBlindTools::MakeGaussianOffset(const char *StringAlphabet) const{
373 Double_t theRan1 = Randomizer(StringAlphabet);
374 Double_t theRan2 = Randomizer("cdefghijklmnopqrstuvwxyzab");
375
376 if (theRan1==0.0 || theRan1==1.0){
377 theRan1 = 0.5;
378 }
379 if (theRan2==0.0 || theRan2==1.0){
380 theRan2 = 0.5;
381 }
382
383 Double_t theOffset = sin(2.0*3.14159*theRan1)*sqrt(-2.0*log(theRan2));
384
385 return theOffset; //theOffset is Gaussian with mean 0, sigma 1
386}
387
388////////////////////////////////////////////////////////////////////////////////
389
390Double_t RooBlindTools::MakeSignFlip(const char *StringAlphabet) const{
391 Double_t theRan = Randomizer(StringAlphabet);
392
393 Double_t theSignFlip = 1.0;
394 if (theRan>0.5){
395 theSignFlip = 1.0;
396 } else {
397 theSignFlip = -1.0;
398 }
399
400 return theSignFlip; //theSignFlip is = +1 or -1
401}
402
403////////////////////////////////////////////////////////////////////////////////
404
406 Int_t sTag;
407 if (STag < 0.0){
408 sTag = -1;
409 }
410 else if (STag > 0.0) {
411 sTag = 1;
412 }
413 else {
414 sTag = 1;
415 }
416
417 return sTag;
418
419}
ROOT::R::TRInterface & r
Definition Object.C:4
#define ClassImp(name)
Definition Rtypes.h:364
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()