Exercises linked to DaVinci session 1
The purpose of these exercises is to allow you to write a complete though simple selection algorithms for a typical decay: Bs->J/psiPhi. We start with a very simple algorithm that looks at muons and fills some histograms.
1. Setting up the environment
... You should already have done that all- Choose the DaVinci environment
- add the following line
- Then go ahead
cd $HOME/cmtuser/
DaVinciEnv v17r5 ; getpack Tutorial/Analysis v6r1 ; getpack Phys/DaVinci v17r5 cd Phys/DaVinci/v17r5/cmt
emacs requirements
use Analysis v* Tutorial
cmt config
cmt br make
source setup.csh
cd $ANALYSISROOT
2. Start to write the options
- Open a new file in the options directory and write
#include "$DAVINCIROOT/options/DaVinciCommon.opts"
#include "$ANALYSISROOT/options/BolognaOptions.opts"
ApplicationMgr.DLLs += { "Analysis" };// Don't forget the DLL
ApplicationMgr.TopAlg += { "GaudiSequencer/TutorialSeq" };
TutorialSeq.Members += { "TutorialAlgorithm" };
Now we need to write the algorithm!
2. Start to write the algorithm
We will make a small algorithm that loops over muons and plots some variables.
- Open a file
- Before you forget it, declare it to Analysis_load.cpp:
- Now let's add something to the execute method:
- Declare the method in the header file:
- Create it in the cpp file:
- In the method add:
- Now get the primary vertices (outside the muons loop):
- And loop over them (inside...):
emacs src/TutorialAlgorithm.{cpp,h} &
Answer "D" for DVAlgorithm twice
DECLARE_ALGORITHM(TutorialAlgorithm)
StatusCode TutorialAlgorithm::execute() {
debug() << "==> Execute" << endmsg;
StatusCode sc = StatusCode::SUCCESS ;
// code goes here
LHCb::Particle::ConstVector muons = desktop()->particles();
sc = loopOnMuons(muons);
if (!sc) return sc;
setFilterPassed(true); // Set to true if event is accepted.
return StatusCode::SUCCESS;
}
Here we get the particles from the hysDesktop tool and added a method that will do the actual work.
private:
StatusCode loopOnMuons(const LHCb::Particle::ConstVector&)const ;
//====================================================
// loop on muons
//====================================================
StatusCode TutorialAlgorithm::loopOnMuons(
const LHCb::Particle::ConstVector& muons)const {
StatusCode sc = StatusCode::SUCCESS ;
// code goes here
return sc ;
}
for ( LHCb::Particle::ConstVector::const_iterator im = muons.begin() ;
im != muons.end() ; ++im ){
plot((*im)->p(), "Muon P", 0., 50.*Gaudi::Units::GeV); // momentum
plot((*im)->pt(), "Muon Pt", 0., 5.*Gaudi::Units::GeV ); // Pt
debug() << "Mu Momentum: " << (*im)->momentum() << endmsg ;
}
LHCb::RecVertex::ConstVector pvs = desktop()->primaryVertices();
for ( LHCb::RecVertex::ConstVector::const_iterator ipv =
pvs.begin() ; ipv != pvs.end() ; ++ipv ){
double IP, IPE;
debug() << (*ipv)->position() << endmsg ;
sc = geomDispCalculator()->calcImpactPar(*(*im), *(*ipv), IP, IPE);
if (sc){
plot(IP, "Muon IP", 0., 10.*Gaudi::Units::mm);
if (IPE>0.) plot(IP/IPE, "Muon IP/error", 0., 10.);
}
}
3. Run!
First we need some data
- We need to tell the algorithm what particles to use:
- Define the rules for creation of "Standard Particles"
#include "$COMMONPARTICLESROOT/options/StandardMuons.opts"
- We need to tell the algorithm what particles to use:
- We want to save the histograms, so add the following line to your options:
- Now run:
#include "$DAVINCITUTORIALDATA"
TutorialAlgorithm.PhysDesktop.InputLocations = { "Phys/StdLooseMuons" } ;
The PhysDesktop will automatically add the /Event/.
HistogramPersistencySvc.OutputFile = "DVHistos.root";
DaVinci $ANAYSISROOT/options/MyOptions.opts
4. Look at the histograms
- Open root
- The simplest way to look at histograms is to use the TBrowser
- But if you just want to save the histograms, you could as well just paste the following in the root prompt
- To quit root:
root.exe
This will get you the version of root used by DaVinci.
Note that
root
sometimes also works, but sometimes doesn't...
TBrowser B
Which has a windows-like look and feel.
TCanvas* c1 = new TCanvas("c1","Bologna",800,800);
c1->SetLogy();
TFile* F = new TFile("DVHistos.root")
F->ls()
F->cd("TutorialAlgorithm")
F->ls()
TH1D* H1 = F->Get("TutorialAlgorithm/1")
TH1D* H2 = F->Get("TutorialAlgorithm/2")
TH1D* H3 = F->Get("TutorialAlgorithm/3")
TH1D* H4 = F->Get("TutorialAlgorithm/4")
H1->SetLineColor(2)
H1->SetLineWidth(3)
H1->Draw()
gPad->SaveAs("H1.eps");
H2->SetLineColor(2)
H2->SetLineWidth(3)
H2->Draw() gPad->SaveAs("H2.eps");
H3->SetLineColor(2)
H3->SetLineWidth(3)
H3->Draw() gPad->SaveAs("H3.eps");
H4->SetLineColor(2)
H4->SetLineWidth(3)
H4->Draw() gPad->SaveAs("H4.eps");
For sure one could do this shorter.
.q
Last modified by Vanya BELYAEV, June 1 2006