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