difference between float and double

Transcription

difference between float and double
difference between float and double • 
float a = 4.12; • 
• 
• 
• 
• 
• 
• 
if(a==4.12) { cout<<"hello"; } else { cout<<"bye "< • 
• 
• 
This will show you the output as "bye 4.12” Why? Because by default 4.12 is a double (such as in the if statement or in the assignment to our variable), but storing it in a float it loses some precision, and so comparing then comparing a double with a float lead to microscopic changes in the precision of the number-­‐-­‐remember that floats and doubles are not precise. • 
Two lessons here: one is that floaLng point numbers shouldn't be compared directly most of the Lme, and the other is that the default size and type of a hard-­‐coded floaLng point number is double. Differences between class and struct •  There is no difference between class and struct, except the members of class are private by default and those of struct are public by default. What you can do with a class you can do with a struct. Passing a pointer to a func7on • 
• 
• 
• 
• 
• 
void funcLon(int* p) { //Changing the address to where p points. int* number = new int(5); p = number; } • 
• 
• 
• 
• 
• 
int main() { int* pointer = new int(1); funLon(pointer); cout << *pointer; } • 
• 
When we run the program it will print out 1. This is because the funcLon creates a local copy of the pointer, so whatever it does within the funcLon doesnt affect the real pointer. In order to get around this we can pass the pointer by reference: • 
void funcLon(int* &p) • 
This will ensure that we work with the actual pointer being passed and not just a copy of it. • 
(Note that its always a good idea to delete the pointer before reassigning it to another address since not doing so will result in memory leaks.) 13 ALICE experimental setup Detector: Length: 26 meters Height: 16 meters Weight: 10,000 tons V0 (centrality) η: -­‐1.7– -­‐3.7, 2.8–5.1 T0 (Lming) ZDC (centrality) FMD (Nch -­‐3.4<h<5) Evgeny Kryshen Central Barrel 2 π tracking & PID |η| < 1 Muon Spectrometer -­‐2.5 > η > -­‐4 Overview of ALICE results Collabora7on: > 1000 Members > 100 Ins7tutes > 30 countries 14 PID, vertexing and tracking capabili7es ITS TPC TOF TRD HMPID • 
• 
• 
• 
parLcle idenLficaLon (pracLcally all known techniques) extremely low-­‐mass tracker ~ 10% of X0 excellent vertexing capability efficient low-­‐momentum tracking – down to ~ 100 MeV/c vertexing
15 enum { kV0A, kV0C, kSPD, kV0OR, kMB, kNoMB, kNoTrigg }; TString triggName[] = {"V0A", "V0C", "SPD", "V0A|V0C", "V0A|V0C|SPD", "!kMB"}; 10
T
T
1/Neve 1/(2 p ) dN/dp [ (GeV/c)-2 ]
103
10-2
PYTHIA 8.176
V0A, trigg = 0.859
10-5
V0C, trigg = 0.849
SPD, trigg = 0.864
V0A|V0C, trigg = 0.927
-8
V0A|V0C|SPD, trigg = 0.929
10
10-11
1.04
Ratio
1.02
1
0.98
0.96
10-1
1
10
±
h p [GeV/c]
T
// File gROOT-­‐>cd(); TFile *fout = new TFile(ouuile,"recreate","pythia 8 generaLon"); // Histograms const int Ntrigg = kNoTrigg; TH1D *wChargedEta= new TH1D("hChargedEta","All eta",800,-­‐10.0,10.0); wChargedEta-­‐>Sumw2(); TH1D *wNtriggFired = new TH1D("hNtriggFired","hNtriggFired",11,-­‐0.5,10.5); const int nCJACEK = 74 ; double pyJacek[nCJACEK] = {0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, 4, 4.5, 5, 5.5, 6, 6.5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 40, 45, 50, 60, 70, 80, 90, 100}; TH1D *wChargedPtJacek = new TH1D(Form("hChargedPtJacek%02d",00), Form("hChargedPtJacek%02d",00), nCJACEK-­‐1, pyJacek ); wChargedPtJacek-­‐>Sumw2(); // Trigger bias study TH1D *wChargedPtJacekTrigg[Ntrigg]; TH1D *wChargedEtaTrigg[Ntrigg]; for(int i=0;i<Ntrigg;i++) { wChargedPtJacekTrigg[i] = new TH1D(Form("hChargedPtJacekTrigg%02d",i), Form("%s",triggName[i].Data()), nCJACEK-­‐1, pyJacek ); wChargedPtJacekTrigg[i]-­‐>Sumw2(); wChargedEtaTrigg[i] = new TH1D(Form("hChargedEtaTrigg%02d",i), Form("%s",triggName[i].Data()), 800,-­‐10.0,10.0 ); wChargedEtaTrigg[i]-­‐>Sumw2(); } TH1D *hCrossSecLonInfo = new TH1D("hCrossSecLon","CrossSecLonInfo",5,0,5); // check the trigg bool firedV0A=false; bool firedV0C=false; bool firedSPD=false; bool firedV0OR=false; bool firedMB=false; bool firedNoMB=false; for (Int_t ip = 0; ip < np; ip++) { Pythia8::Event &event = pythia8.event; Pythia8::ParLcle &part = event[ip]; if( !part.isFinal() || !part.isCharged() || !part.isHadron() ) conLnue; double eta = part.eta(); if( eta>2.8 && eta<5.1 ) firedV0A=true; if( eta>-­‐3.7 && eta<-­‐1.7 ) firedV0C=true; if( eta>-­‐1.6 && eta<1.6 ) firedSPD=true; if( (eta>2.8 && eta<5.1)||(eta>-­‐3.7 && eta<-­‐1.7) ) firedV0OR=true; if( (eta>2.8 && eta<5.1)||(eta>-­‐3.7 && eta<-­‐1.7)||(eta>-­‐1.6 && eta<1.6) ) firedMB=true; if( !((eta>2.8 && eta<5.1)||(eta>-­‐3.7 && eta<-­‐1.7)||(eta>-­‐1.6 && eta<1.6)) ) firedNoMB=true; } //cout <<"Trigg fired on "<< firedV0A << firedV0C<< firedSPD << firedV0OR << firedMB <<firedNoMB << endl; if (firedV0A) wNtriggFired-­‐>Fill(kV0A,1); if (firedV0C) wNtriggFired-­‐>Fill(kV0C,1); if (firedSPD) wNtriggFired-­‐>Fill(kSPD,1); if (firedV0OR) wNtriggFired-­‐>Fill(kV0OR,1); if (firedMB) wNtriggFired-­‐>Fill(kMB,1); if (!firedMB) wNtriggFired-­‐>Fill(kNoMB,1); ParLcle spectra // ParLcle Loop to fill hist for (Int_t ip = 0; ip < np; ip++) { // event && part Pythia8::Event &event = pythia8.event; Pythia8::ParLcle &part = event[ip]; if( !part.isFinal() || !part.isCharged() || !part.isHadron() ) conLnue; double eta = part.eta(); wChargedEta-­‐>Fill(eta); if( !(TMath::Abs(eta)<etaCut)) conLnue; //cout << ip <<"\t"<< part.pT() <<"\t"<<part.eta() << endl; wChargedPtJacek-­‐>Fill(part.pT(),1./part.pT()); if (firedV0A) { wChargedEtaTrigg[kV0A]-­‐>Fill(eta); wChargedPtJacekTrigg[kV0A]-­‐>Fill(part.pT(),1./part.pT()); } if (firedV0C) { wChargedEtaTrigg[kV0C]-­‐>Fill(eta); wChargedPtJacekTrigg[kV0C]-­‐>Fill(part.pT(),1./part.pT()); } if (firedSPD) { wChargedEtaTrigg[kSPD]-­‐>Fill(eta); wChargedPtJacekTrigg[kSPD]-­‐>Fill(part.pT(),1./part.pT()); } if (firedV0OR) { wChargedEtaTrigg[kV0OR]-­‐>Fill(eta); wChargedPtJacekTrigg[kV0OR]-­‐>Fill(part.pT(),1./part.pT()); } if (firedMB) { wChargedEtaTrigg[kMB]-­‐>Fill(eta); wChargedPtJacekTrigg[kMB]-­‐>Fill(part.pT(),1./part.pT()); } if (!firedMB) { wChargedEtaTrigg[kNoMB]-­‐>Fill(eta); wChargedPtJacekTrigg[kNoMB]-­‐>Fill(part.pT(),1./part.pT()); } }//parLcle loop • 
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
pythia8.staLsLcs(); long nTried = pythia8.info.nTried(); long nAccepted = pythia8.info.nAccepted(); double sigmaGen = pythia8.info.sigmaGen(); //double sigmaErr = pythia8.info.sigmaErr(); hCrossSecLonInfo-­‐>Fill(0.5,nTried); hCrossSecLonInfo-­‐>Fill(1.5,nAccepted); hCrossSecLonInfo-­‐>Fill(2.5,sigmaGen); hCrossSecLonInfo-­‐>Fill(3.5,nEvent); hCrossSecLonInfo-­‐>Fill(4.5,energy); fout-­‐>Write(); fout-­‐>Close(); cout <<"Sucessfully finished."<< endl; 

Similar documents

Measurements of jet rates with the anti

Measurements of jet rates with the anti G. P. Salam and G. Soyez, “A Practical Seedless Infrared-Safe Cone jet algorithm”, JHEP 0705 (2007) 086 M. Cacciari et al., “The Anti-k(t) jet clustering algorithm”, JHEP 0804 (2008) 063

More information