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 std::cout, std::endl;
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
101double RooBlindTools::HideDeltaZ(double DeltaZ, double STag)const{
102 Int_t sTag = SignOfTag(STag);
103 double DeltaZPrime = _DeltaZSignFlip*DeltaZ*sTag + _DeltaZOffset;
104
105 return DeltaZPrime;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109
110double RooBlindTools::HiDelZPdG(double DeltaZ, double STag, double PdG) const{
111 Int_t sTag = SignOfTag(STag);
112 double DeltaZPrime = _DeltaZSignFlip*(DeltaZ - PdG)*sTag + _DeltaZOffset;
113
114 return DeltaZPrime;
115}
116
117////////////////////////////////////////////////////////////////////////////////
118
119double RooBlindTools::UnHideDeltaZ(double DeltaZPrime, double STag) const{
120 Int_t sTag = SignOfTag(STag);
121 double DeltaZ = (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
122
123 return DeltaZ;
124}
125
126////////////////////////////////////////////////////////////////////////////////
127
128double RooBlindTools::UnHiDelZPdG(double DeltaZPrime, double STag, double PdG) const{
129 Int_t sTag = SignOfTag(STag);
130 double DeltaZ = PdG + (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
131
132 return DeltaZ;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136
137double RooBlindTools::UnHideAsym(double AsymPrime) const{
138 if(mode()==dataonly) return AsymPrime;
139
140 double Asym = (AsymPrime - _AsymOffset)/_AsymSignFlip;
141
142 return Asym;
143}
144
145////////////////////////////////////////////////////////////////////////////////
146
147double RooBlindTools::HideAsym(double Asym) const{
148 if(mode()==dataonly) return Asym;
149
150 double AsymPrime = Asym*_AsymSignFlip + _AsymOffset;
151
152 return AsymPrime;
153}
154
155////////////////////////////////////////////////////////////////////////////////
156
157double RooBlindTools::UnHideDeltaM(double DeltaMPrime) const{
158 if(mode()==dataonly) return DeltaMPrime;
159
160 double DeltaM = DeltaMPrime - _DeltaMOffset;
161
162 return DeltaM;
163}
164
165////////////////////////////////////////////////////////////////////////////////
166
167double RooBlindTools::HideDeltaM(double DeltaM) const{
168 if(mode()==dataonly) return DeltaM;
169
170 double DeltaMPrime = DeltaM + _DeltaMOffset;
171
172 return DeltaMPrime;
173}
174
175////////////////////////////////////////////////////////////////////////////////
176
177double RooBlindTools::UnHiAsPdG(double AsymPrime, double PdG) const{
178 if(mode()==dataonly) return AsymPrime;
179
180 double Asym = PdG + (AsymPrime - _AsymOffset)/_AsymSignFlip;
181
182 return Asym;
183}
184
185////////////////////////////////////////////////////////////////////////////////
186
188 if(mode()==dataonly) return 0.0;
189
190 return _MysteryPhase;
191}
192
193////////////////////////////////////////////////////////////////////////////////
194
195double RooBlindTools::HiAsPdG(double Asym, double PdG) const{
196 if(mode()==dataonly) return Asym;
197
198 double AsymPrime = (Asym - PdG)*_AsymSignFlip + _AsymOffset;
199
200 return AsymPrime;
201}
202
203////////////////////////////////////////////////////////////////////////////////
204
205double RooBlindTools::UnHidePrecision(double PrecisionPrime) const{
206 if(mode()==dataonly) return PrecisionPrime;
207
208 double Precision(0.);
209
210 if (_PrecisionSignFlip>0) {
211 Precision = PrecisionPrime - _PrecisionOffset;
212 }
213 else {
214 Precision = 2.0*_PrecisionCentralValue - PrecisionPrime + _PrecisionOffset;
215 }
216
217
218 return Precision;
219}
220
221////////////////////////////////////////////////////////////////////////////////
222
223double RooBlindTools::HidePrecision(double Precision) const{
224 if(mode()==dataonly) return Precision;
225
226 double PrecisionPrime(0.);
227
228 if (_PrecisionSignFlip>0) {
229 PrecisionPrime = Precision + _PrecisionOffset;
230 }
231 else {
232 PrecisionPrime = 2.0*_PrecisionCentralValue - Precision + _PrecisionOffset;
233 }
234
235 return PrecisionPrime;
236}
237
238////////////////////////////////////////////////////////////////////////////////
239
240double RooBlindTools::UnHideOffset(double PrecisionPrime) const{
241 if(mode()==dataonly) return PrecisionPrime;
242
243 return PrecisionPrime - _PrecisionOffset;
244}
245
246////////////////////////////////////////////////////////////////////////////////
247
248double RooBlindTools::HideOffset(double Precision) const{
249 if(mode()==dataonly) return Precision;
250
251 return Precision + _PrecisionOffset;
252}
253
254////////////////////////////////////////////////////////////////////////////////
255
256double RooBlindTools::UnHideUniform(double PrecisionPrime) const{
257 if(mode()==dataonly) return PrecisionPrime;
258
259 return PrecisionPrime - _PrecisionUniform;
260}
261
262////////////////////////////////////////////////////////////////////////////////
263
264double RooBlindTools::HideUniform(double Precision) const{
265 if(mode()==dataonly) return Precision;
266
267 return Precision + _PrecisionUniform;
268}
269
270////////////////////////////////////////////////////////////////////////////////
271
272double RooBlindTools::RandomizeTag(double STag, Int_t EventNumber) const{
273 Int_t Seed = EventNumber % 7997 + 2;
274 double r = PseudoRandom(Seed);
275 double STagPrime(0.0);
276
277 if (r < _STagConstant){
278 STagPrime = STag;
279 } else {
280 STagPrime = -1.0 * STag ;
281 }
282
283 return STagPrime;
284
285}
286
287////////////////////////////////////////////////////////////////////////////////
288
289double RooBlindTools::Randomizer(const char *StringAlphabet) const{
290 char lowerseed[1024] ;
291 strlcpy(lowerseed,_stSeed,1024) ;
292
293 Int_t lengthSeed = strlen(lowerseed);
294
295 for (Int_t j=0; j<lengthSeed; j++){
296 lowerseed[j] =tolower(_stSeed[j]);
297 }
298 Int_t sumSeed = 0;
299 for (Int_t i=0; i<lengthSeed; i++){
300 for (Int_t iAlphabet=0; iAlphabet<26; iAlphabet++){
301 if ( lowerseed[i] == StringAlphabet[iAlphabet] ){
302 if (_s2bMode) {
303 sumSeed = (iAlphabet<<(5*(i%3)))^sumSeed;
304 } else {
305 sumSeed = sumSeed + iAlphabet ;
306 }
307 }
308 }
309 }
310
311 if (lengthSeed<5 || ((sumSeed<1 || sumSeed>8000)&&!_s2bMode)) {
312 cout<< "RooBlindTools::Randomizer: Your String Seed is Bad: '" << _stSeed << "'" << endl ;
314 }
315
316 Int_t ia = 8121;
317 Int_t ic = 28411;
318 Int_t im = 134456;
319 UInt_t jRan = (sumSeed*ia + ic) % im;
320
321 jRan = (jRan*ia + ic) % im;
322 jRan = (jRan*ia + ic) % im;
323 jRan = (jRan*ia + ic) % im;
324
325 double theRan = (float) jRan / (float) im;
326
327 return theRan; //theRan is between 0.0 - 1.0
328
329}
330
331////////////////////////////////////////////////////////////////////////////////
332
334 if (Seed<1 || Seed>8000 ) {
335 cout<< "RooBlindTools::PseudoRandom: Your integer Seed is Bad" <<endl;
336 }
337
338 Int_t ia = 8121;
339 Int_t ic = 28411;
340 Int_t im = 134456;
341 UInt_t jRan = (Seed*ia + ic) % im;
342
343 jRan = (jRan*ia + ic) % im;
344 jRan = (jRan*ia + ic) % im;
345 jRan = (jRan*ia + ic) % im;
346
347 double theRan = (float) jRan / (float) im;
348
349 return theRan; //theRan is between 0.0 - 1.0
350
351}
352
353////////////////////////////////////////////////////////////////////////////////
354
355double RooBlindTools::MakeOffset(const char *StringAlphabet) const{
356 double theRan = Randomizer(StringAlphabet);
357
358 double theOffset = (2.0)*theRan - (1.0);
359
360 return theOffset; //theOffset lies between -1.0 and 1.0
361}
362
363////////////////////////////////////////////////////////////////////////////////
364
365double RooBlindTools::MakeGaussianOffset(const char *StringAlphabet) const{
366 double theRan1 = Randomizer(StringAlphabet);
367 double theRan2 = Randomizer("cdefghijklmnopqrstuvwxyzab");
368
369 if (theRan1==0.0 || theRan1==1.0){
370 theRan1 = 0.5;
371 }
372 if (theRan2==0.0 || theRan2==1.0){
373 theRan2 = 0.5;
374 }
375
376 double theOffset = sin(2.0*3.14159*theRan1)*sqrt(-2.0*log(theRan2));
377
378 return theOffset; //theOffset is Gaussian with mean 0, sigma 1
379}
380
381////////////////////////////////////////////////////////////////////////////////
382
383double RooBlindTools::MakeSignFlip(const char *StringAlphabet) const{
384 double theRan = Randomizer(StringAlphabet);
385
386 double theSignFlip = 1.0;
387 if (theRan>0.5){
388 theSignFlip = 1.0;
389 } else {
390 theSignFlip = -1.0;
391 }
392
393 return theSignFlip; //theSignFlip is = +1 or -1
394}
395
396////////////////////////////////////////////////////////////////////////////////
397
399 Int_t sTag;
400 if (STag < 0.0){
401 sTag = -1;
402 }
403 else if (STag > 0.0) {
404 sTag = 1;
405 }
406 else {
407 sTag = 1;
408 }
409
410 return sTag;
411
412}
#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
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.