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 "RooBlindTools.h"
23
24#include "RooErrorHandler.h"
25#include "strlcpy.h"
26
27#include <iostream>
28#include <fstream>
29#include <cmath>
30#include <cstring>
31#include <cctype>
32
33using namespace std;
34
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor
39
40RooBlindTools::RooBlindTools(const char *stSeedIn, blindMode Mode,
41 double centralValue, double sigmaOffset, bool 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
106double RooBlindTools::HideDeltaZ(double DeltaZ, double STag)const{
107 Int_t sTag = SignOfTag(STag);
108 double DeltaZPrime = _DeltaZSignFlip*DeltaZ*sTag + _DeltaZOffset;
109
110 return DeltaZPrime;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114
115double RooBlindTools::HiDelZPdG(double DeltaZ, double STag, double PdG) const{
116 Int_t sTag = SignOfTag(STag);
117 double DeltaZPrime = _DeltaZSignFlip*(DeltaZ - PdG)*sTag + _DeltaZOffset;
118
119 return DeltaZPrime;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123
124double RooBlindTools::UnHideDeltaZ(double DeltaZPrime, double STag) const{
125 Int_t sTag = SignOfTag(STag);
126 double DeltaZ = (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
127
128 return DeltaZ;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132
133double RooBlindTools::UnHiDelZPdG(double DeltaZPrime, double STag, double PdG) const{
134 Int_t sTag = SignOfTag(STag);
135 double DeltaZ = PdG + (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
136
137 return DeltaZ;
138}
139
140////////////////////////////////////////////////////////////////////////////////
141
142double RooBlindTools::UnHideAsym(double AsymPrime) const{
143 if(mode()==dataonly) return AsymPrime;
144
145 double Asym = (AsymPrime - _AsymOffset)/_AsymSignFlip;
146
147 return Asym;
148}
149
150////////////////////////////////////////////////////////////////////////////////
151
152double RooBlindTools::HideAsym(double Asym) const{
153 if(mode()==dataonly) return Asym;
154
155 double AsymPrime = Asym*_AsymSignFlip + _AsymOffset;
156
157 return AsymPrime;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161
162double RooBlindTools::UnHideDeltaM(double DeltaMPrime) const{
163 if(mode()==dataonly) return DeltaMPrime;
164
165 double DeltaM = DeltaMPrime - _DeltaMOffset;
166
167 return DeltaM;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171
172double RooBlindTools::HideDeltaM(double DeltaM) const{
173 if(mode()==dataonly) return DeltaM;
174
175 double DeltaMPrime = DeltaM + _DeltaMOffset;
176
177 return DeltaMPrime;
178}
179
180////////////////////////////////////////////////////////////////////////////////
181
182double RooBlindTools::UnHiAsPdG(double AsymPrime, double PdG) const{
183 if(mode()==dataonly) return AsymPrime;
184
185 double 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
200double RooBlindTools::HiAsPdG(double Asym, double PdG) const{
201 if(mode()==dataonly) return Asym;
202
203 double AsymPrime = (Asym - PdG)*_AsymSignFlip + _AsymOffset;
204
205 return AsymPrime;
206}
207
208////////////////////////////////////////////////////////////////////////////////
209
210double RooBlindTools::UnHidePrecision(double PrecisionPrime) const{
211 if(mode()==dataonly) return PrecisionPrime;
212
213 double Precision(0.);
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
228double RooBlindTools::HidePrecision(double Precision) const{
229 if(mode()==dataonly) return Precision;
230
231 double 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
245double RooBlindTools::UnHideOffset(double PrecisionPrime) const{
246 if(mode()==dataonly) return PrecisionPrime;
247
248 return PrecisionPrime - _PrecisionOffset;
249}
250
251////////////////////////////////////////////////////////////////////////////////
252
253double RooBlindTools::HideOffset(double Precision) const{
254 if(mode()==dataonly) return Precision;
255
256 return Precision + _PrecisionOffset;
257}
258
259////////////////////////////////////////////////////////////////////////////////
260
261double RooBlindTools::UnHideUniform(double PrecisionPrime) const{
262 if(mode()==dataonly) return PrecisionPrime;
263
264 return PrecisionPrime - _PrecisionUniform;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268
269double RooBlindTools::HideUniform(double Precision) const{
270 if(mode()==dataonly) return Precision;
271
272 return Precision + _PrecisionUniform;
273}
274
275////////////////////////////////////////////////////////////////////////////////
276
277double RooBlindTools::RandomizeTag(double STag, Int_t EventNumber) const{
278 Int_t Seed = EventNumber % 7997 + 2;
279 double r = PseudoRandom(Seed);
280 double 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 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 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 theRan = (float) jRan / (float) im;
353
354 return theRan; //theRan is between 0.0 - 1.0
355
356}
357
358////////////////////////////////////////////////////////////////////////////////
359
360double RooBlindTools::MakeOffset(const char *StringAlphabet) const{
361 double theRan = Randomizer(StringAlphabet);
362
363 double theOffset = (2.0)*theRan - (1.0);
364
365 return theOffset; //theOffset lies between -1.0 and 1.0
366}
367
368////////////////////////////////////////////////////////////////////////////////
369
370double RooBlindTools::MakeGaussianOffset(const char *StringAlphabet) const{
371 double theRan1 = Randomizer(StringAlphabet);
372 double 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 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 RooBlindTools::MakeSignFlip(const char *StringAlphabet) const{
389 double theRan = Randomizer(StringAlphabet);
390
391 double 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}
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char mode
double UnHiAsPdG(double AsymPrime, double PdG) const
double PseudoRandom(Int_t Seed) const
double HideAsym(double Asym) const
virtual ~RooBlindTools()
Destructor.
double HiAsPdG(double Asym, double PdG) const
double _PrecisionOffsetScale
double MysteryPhase() const
double UnHideUniform(double PrecisionBlind) const
double UnHideDeltaZ(double DeltaZPrime, double STag) const
double HidePrecision(double Precision) const
double MakeOffset(const char *StringAlphabet) const
double _PrecisionSignFlip
double UnHidePrecision(double PrecisionPrime) const
double _DeltaZSignFlip
void setup(const char *stSeed)
double UnHiDelZPdG(double DeltaZPrime, double STag, double PdG) const
double Randomizer(const char *StringAlphabet) const
double UnHideAsym(double AsymPrime) const
double MakeGaussianOffset(const char *StringAlphabet) const
double HideOffset(double Precision) const
double UnHideOffset(double PrecisionBlind) const
double _PrecisionCentralValue
const char * stSeed() const
double MakeSignFlip(const char *StringAlphabet) const
double HideUniform(double Precision) const
double _PrecisionOffset
const blindMode & mode() const
double RandomizeTag(double STag, Int_t EventNumber) const
double HideDeltaM(double DeltaM) const
double _PrecisionUniform
double UnHideDeltaM(double DeltaMPrime) const
double HideDeltaZ(double DeltaZ, double STag) const
Int_t SignOfTag(double STag) const
double HiDelZPdG(double DeltaZ, double STag, double PdG) const
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.