laura is hosted by Hepforge, IPPP Durham

Ticket #53: GenFit3pi_mod.cc

File GenFit3pi_mod.cc, 7.7 KB (added by guest, 9 years ago)
Line 
1
2#include <cstdlib>
3#include <iostream>
4#include <vector>
5
6#include "TFile.h"
7#include "TH2.h"
8#include "TString.h"
9#include "TTree.h"
10
11#include "LauSimpleFitModel.hh"
12#include "LauBkgndDPModel.hh"
13#include "LauDaughters.hh"
14#include "LauEffModel.hh"
15#include "LauIsobarDynamics.hh"
16#include "LauMagPhaseCoeffSet.hh"
17#include "LauResonanceMaker.hh"
18#include "LauVetoes.hh"
19
20void usage( std::ostream& out, const TString& progName )
21{
22        out<<"Usage:\n";
23        out<<progName<<" gen [nExpt = 1] [firstExpt = 0]\n";
24        out<<"or\n";
25        out<<progName<<" fit <iFit> [nExpt = 1] [firstExpt = 0]"<<std::endl;
26}
27
28int main( int argc, char** argv )
29{
30        // Process command-line arguments
31        // Usage:
32        // ./GenFit3pi gen [nExpt = 1] [firstExpt = 0]
33        // or
34        // ./GenFit3pi fit <iFit> [nExpt = 1] [firstExpt = 0]
35        if ( argc < 2 ) {
36                usage( std::cerr, argv[0] );
37                return EXIT_FAILURE;
38        }
39
40        TString command = argv[1];
41        command.ToLower();
42        Int_t iFit(0);
43        Int_t nExpt(1);
44        Int_t firstExpt(0);
45        if ( command == "gen" ) {
46                if ( argc > 2 ) {
47                        nExpt = atoi( argv[2] );
48                        if ( argc > 3 ) {
49                                firstExpt = atoi( argv[3] );
50                        }
51                }
52        } else if ( command == "fit" ) {
53                if ( argc < 3 ) {
54                        usage( std::cerr, argv[0] );
55                        return EXIT_FAILURE;
56                }
57                iFit = atoi( argv[2] );
58                if ( argc > 3 ) {
59                        nExpt = atoi( argv[3] );
60                        if ( argc > 4 ) {
61                                firstExpt = atoi( argv[4] );
62                        }
63                }
64        } else {
65                usage( std::cerr, argv[0] );
66                return EXIT_FAILURE;
67        }
68
69        // If you want to use square DP histograms for efficiency,
70        // backgrounds or you just want the square DP co-ordinates
71        // stored in the toy MC ntuple then set this to kTRUE
72        Bool_t squareDP = kFALSE;
73
74        // This defines the DP => decay is B+ -> pi+ pi+ pi-
75        // Particle 1 = pi+
76        // Particle 2 = pi+
77        // Particle 3 = pi-
78        // The DP is defined in terms of m13Sq and m23Sq
79        LauDaughters* daughters = new LauDaughters("B+", "pi+", "pi+", "pi-", squareDP);
80
81        // Optionally apply some vetoes to the DP
82        LauVetoes* vetoes = new LauVetoes();
83        //Double_t DMin = 1.70;
84        //Double_t DMax = 1.925;
85        //Double_t JpsiMin = 3.051;
86        //Double_t JpsiMax = 3.222;
87        //Double_t psi2SMin = 3.676;
88        //Double_t psi2SMax = 3.866;
89        //vetoes->addMassVeto(2, DMin, DMax); // D0 veto, m13
90        //vetoes->addMassVeto(2, JpsiMin, JpsiMax); // J/psi veto, m13
91        //vetoes->addMassVeto(2, psi2SMin, psi2SMax); // psi(2S) veto, m13
92        //vetoes->addMassVeto(1, DMin, DMax); // D0 veto, m23
93        //vetoes->addMassVeto(1, JpsiMin, JpsiMax); // J/psi veto, m23
94        //vetoes->addMassVeto(1, psi2SMin, psi2SMax); // psi(2S) veto, m23
95
96        // Define the efficiency model (defaults to unity everywhere)
97        // Can optionally provide a histogram to model variation over DP
98        // (example syntax given in commented-out section)
99        LauEffModel* effModel = new LauEffModel(daughters, vetoes);
100        //TFile *effHistFile = TFile::Open("histoFiles/B3piNRDPEff.root", "read");
101        //TH2* effHist = dynamic_cast<TH2*>(effHistFile->Get("effHist"));
102        //Bool_t useInterpolation = kTRUE;
103        //Bool_t fluctuateBins = kFALSE;
104        //Bool_t useUpperHalf = kTRUE;
105        //effModel->setEffHisto(effHist, useInterpolation, fluctuateBins, 0.0, 0.0, useUpperHalf, squareDP);
106
107        // Create the isobar model
108
109        // Set the values of the Blatt-Weisskopf barrier radii and whether they are fixed or floating
110        LauResonanceMaker& resMaker = LauResonanceMaker::get();
111        resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Parent,     5.0 );
112        resMaker.setDefaultBWRadius( LauBlattWeisskopfFactor::Light,      4.0 );
113        resMaker.fixBWRadius( LauBlattWeisskopfFactor::Parent,  kTRUE );
114        resMaker.fixBWRadius( LauBlattWeisskopfFactor::Light,  kFALSE );
115
116        LauIsobarDynamics* sigModel = new LauIsobarDynamics(daughters, effModel);
117        LauAbsResonance* reson(0);
118        reson = sigModel->addResonance("rho0(770)",  1, LauAbsResonance::GS);           // resPairAmpInt = 1 => resonance mass is m23.
119        reson = sigModel->addResonance("rho0(1450)", 1, LauAbsResonance::RelBW);
120        reson = sigModel->addResonance("f_0(980)",   1, LauAbsResonance::Flatte);
121        reson->setResonanceParameter("g1",0.2);
122        reson->setResonanceParameter("g2",1.0);
123        reson = sigModel->addResonance("f_2(1270)",  1, LauAbsResonance::RelBW);
124        reson = sigModel->addIncoherentResonance("NonReson",   0, LauAbsResonance::FlatNR);
125
126        // Reset the maximum signal DP ASq value
127        // This will be automatically adjusted to avoid bias or extreme
128        // inefficiency if you get the value wrong but best to set this by
129        // hand once you've found the right value through some trial and
130        // error.
131        sigModel->setASqMaxValue(0.32); 
132
133        // Create the fit model
134        LauSimpleFitModel* fitModel = new LauSimpleFitModel(sigModel);
135
136        // Create the complex coefficients for the isobar model
137        // Here we're using the magnitude and phase form:
138        // c_j = a_j exp(i*delta_j)
139        std::vector<LauAbsCoeffSet*> coeffset;
140        coeffset.push_back( new LauMagPhaseCoeffSet("rho0(770)",  1.00,  0.00,  kTRUE,  kTRUE) );
141        coeffset.push_back( new LauMagPhaseCoeffSet("rho0(1450)", 0.37,  1.99, kFALSE, kFALSE) );
142        coeffset.push_back( new LauMagPhaseCoeffSet("f_0(980)",   0.27, -1.59, kFALSE, kFALSE) );
143        coeffset.push_back( new LauMagPhaseCoeffSet("f_2(1270)",  0.53,  1.39, kFALSE, kFALSE) );
144        coeffset.push_back( new LauMagPhaseCoeffSet("NonReson",   0.54, -0.84, kFALSE, kFALSE) );
145        for (std::vector<LauAbsCoeffSet*>::iterator iter=coeffset.begin(); iter!=coeffset.end(); ++iter) {
146                fitModel->setAmpCoeffSet(*iter);
147        }
148
149        // Set the signal yield and define whether it is fixed or floated
150        LauParameter * nSigEvents = new LauParameter("nSigEvents",500.0,-1000.0,1000.0,kFALSE);
151        fitModel->setNSigEvents(nSigEvents);
152
153        // Set the number of experiments to generate or fit and which
154        // experiment to start with
155        fitModel->setNExpts( nExpt, firstExpt );
156
157        // Optionally load in continuum background DP model histogram
158        // (example syntax given in commented-out section)
159        std::vector<TString> bkgndNames(1);
160        bkgndNames[0] = "qqbar";
161        fitModel->setBkgndClassNames( bkgndNames );
162        LauParameter* nBkgndEvents = new LauParameter("qqbar",1200.0,-2400.0,2400.0,kFALSE);
163        fitModel->setNBkgndEvents( nBkgndEvents );
164        //TString qqFileName("histoFiles/offResDP.root");
165        //TFile* qqFile = TFile::Open(qqFileName.Data(), "read");
166        //TH2* qqDP = dynamic_cast<TH2*>(qqFile->Get("AllmTheta")); // m', theta'
167        LauBkgndDPModel* qqbarModel = new LauBkgndDPModel(daughters, vetoes);
168        //qqbarModel->setBkgndHisto(qqDP, useInterpolation, fluctuateBins, useUpperHalf, squareDP);
169        fitModel->setBkgndDPModel( "qqbar", qqbarModel );
170
171        // Switch on/off calculation of asymmetric errors.
172        fitModel->useAsymmFitErrors(kFALSE);
173
174        // Randomise initial fit values for the signal mode
175        fitModel->useRandomInitFitPars(kTRUE);
176
177        // Switch on/off Poissonian smearing of total number of events
178        fitModel->doPoissonSmearing(kTRUE);
179
180        // Switch on/off Extended ML Fit option
181        Bool_t emlFit = ( fitModel->nBkgndClasses() > 0 );
182        fitModel->doEMLFit(emlFit);
183
184        // Set the names of the files to read/write
185        TString dataFile("gen.root");
186        TString treeName("genResults");
187        TString rootFileName("");
188        TString tableFileName("");
189        TString fitToyFileName("fitToyMC_");
190        TString splotFileName("splot_");
191        if (command == "fit") {
192                rootFileName = "fit"; rootFileName += iFit;
193                rootFileName += "_expt_"; rootFileName += firstExpt;
194                rootFileName += "-"; rootFileName += (firstExpt+nExpt-1);
195                rootFileName += ".root";
196                tableFileName = "fitResults_"; tableFileName += iFit;
197                fitToyFileName += iFit;
198                fitToyFileName += ".root";
199                splotFileName += iFit;
200                splotFileName += ".root";
201        } else {
202                rootFileName = "dummy.root";
203                tableFileName = "genResults";
204        }
205
206        // Generate toy from the fitted parameters
207        //fitModel->compareFitData(100, fitToyFileName);
208
209        // Write out per-event likelihoods and sWeights
210        //fitModel->writeSPlotData(splotFileName, "splot", kFALSE);
211
212        // Execute the generation/fit
213        fitModel->run( command, dataFile, treeName, rootFileName, tableFileName );
214
215        return EXIT_SUCCESS;
216}