X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TOF%2FAliTOFT0.cxx;h=4b7dcb8fbaad433d69f407492c9cb9e62c10e94a;hb=627a5dbe22f5056a43bd242ee5e86abf17a61edc;hp=b3e8e23e8952d989653e9f3c7e00e180aa45d74a;hpb=d599d9133969c655bf212389d74425b0784b1371;p=u%2Fmrichter%2FAliRoot.git diff --git a/TOF/AliTOFT0.cxx b/TOF/AliTOFT0.cxx index b3e8e23e895..4b7dcb8fbaa 100644 --- a/TOF/AliTOFT0.cxx +++ b/TOF/AliTOFT0.cxx @@ -13,41 +13,56 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ +/* $Id$ */ + //_________________________________________________________________________ +// // This is a TTask that made the calculation of the Time zero using TOF. -// Description: The algorithm used to calculate the time zero of interaction -// using TOF detector is the following. -// We select in the MonteCarlo some primary particles - or tracks in the following - -// that strike the TOF detector (the larger part are pions, kaons or protons). -// We choose a set of 10 selected tracks, for each track You have the length -// of the track when the TOF is reached (a standard TOF hit does not contain this -// additional information, this is the reason why we implemented a new time zero -// dedicated TOF hit class AliTOFhitT0; in order to store this type of hit You -// have to use the AliTOFv4T0 as TOF class in Your Config.C. In AliTOFv4T0 the -// StepManager was modified in order to fill the TOF hit branch with this type -// of hits; in fact the AliTOF::AddT0Hit is called rather that the usual AliTOF::AddHit), -// the momentum at generation (from TreeK) and the time of flight -// given by the TOF detector. -// (Observe that the ctor of the AliTOF class, when the AliTOFv4T0 class is used, is called -// with the "tzero" option: it is in order create the fHits TClonesArray filled with -// AliTOFhitT0 objects, rather than with normal AliTOFhit) -// Then Momentum and time of flight for each track are smeared according to -// known experimental resolution (all sources of error have been token into account). -// Let consider now only one set of 10 tracks (the algorithm is the same for all sets). -// Assuming the (mass) hypothesis that each track can be AUT a pion, AUT a kaon, AUT a proton, -// we consider all the 3 at 10 possible cases. +// Description: The algorithm used to calculate the time zero of +// interaction using TOF detector is the following. +// We select in the MonteCarlo some primary particles - or tracks in +// the following - that strike the TOF detector (the larger part are +// pions, kaons or protons). +// We choose a set of 10 selected tracks, for each track You have the +// length of the track when the TOF is reached (a standard TOF hit +// does not contain this additional information, this is the reason +// why we implemented a new time zero dedicated TOF hit class +// AliTOFhitT0; in order to store this type of hit You have to use the +// AliTOFv4T0 as TOF class in Your Config.C. In AliTOFv4T0 the +// StepManager was modified in order to fill the TOF hit branch with +// this type of hits; in fact the AliTOF::AddT0Hit is called rather +// that the usual AliTOF::AddHit), the momentum at generation (from +// TreeK) and the time of flight given by the TOF detector. +// (Observe that the ctor of the AliTOF class, when the AliTOFv4T0 +// class is used, is called with the "tzero" option: it is in order +// create the fHits TClonesArray filled with AliTOFhitT0 objects, +// rather than with normal AliTOFhit) +// Then Momentum and time of flight for each track are smeared +// according to known experimental resolution (all sources of error +// have been token into account). +// Let consider now only one set of 10 tracks (the algorithm is the +// same for all sets). +// Assuming the (mass) hypothesis that each track can be AUT a pion, +// AUT a kaon, AUT a proton, we consider all the 3 at 10 possible +// cases. // For each track in each (mass) configuration -// (a configuration can be e.g. pion/pion/kaon/proton/pion/proton/kaon/kaon/pion/pion) -// we calculate the time zero (we know in fact the velocity of the track after -// the assumption about its mass, the time of flight given by the TOF, and the -// corresponding path travelled till the TOF detector). Then for each mass configuration we have -// 10 time zero and we can calculate the ChiSquare for the current configuration using the -// weighted mean over all 10 time zero. -// We call the best assignment the mass configuration that gives the minimum value of the ChiSquare. -// We plot the weighted mean over all 10 time zero for the best assignment, -// the ChiSquare for the best assignment and the corresponding confidence level. -// The strong assumption is the MC selection of primary particles. It will be introduced -// in the future also some more realistic simulation about this point. +// (a configuration can be +// e.g. pion/pion/kaon/proton/pion/proton/kaon/kaon/pion/pion) +// we calculate the time zero (we know in fact the velocity of the +// track after the assumption about its mass, the time of flight given +// by the TOF, and the corresponding path travelled till the TOF +// detector). Then for each mass configuration we have 10 time zero +// and we can calculate the ChiSquare for the current configuration +// using the weighted mean over all 10 time zero. +// We call the best assignment the mass configuration that gives the +// minimum value of the ChiSquare. +// We plot the weighted mean over all 10 time zero for the best +// assignment, the ChiSquare for the best assignment and the +// corresponding confidence level. +// The strong assumption is the MC selection of primary particles. It +// will be introduced in the future also some more realistic +// simulation about this point. +// // Use case: // root [0] AliTOFT0 * tzero = new AliTOFT0("galice.root") // Warning in : object already instantiated @@ -55,58 +70,77 @@ // root [2] tzero->ExecuteTask("tim") // // available parameters: // tim - print benchmarking information -// all - print usefull informations about the number of misidentified tracks -// and a comparison about the true configuration (known from MC) and the best +// all - print usefull informations about the number of +// misidentified tracks and a comparison about the +// true configuration (known from MC) and the best // assignment +// //-- Author: F. Pierella -////////////////////////////////////////////////////////////////////////////// +// +//_________________________________________________________________________ + +#include +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "AliLoader.h" +#include "AliMC.h" +#include "AliRun.h" -#include "AliTOFT0.h" #include "AliTOFhitT0.h" +#include "AliTOFT0.h" #include "AliTOF.h" -#include "AliTOFv4T0.h" -#include "AliRun.h" -#include "AliDetector.h" -#include "AliMC.h" -#include "TH1.h" -#include "TFile.h" -#include "TTask.h" -#include "TTree.h" -#include "TSystem.h" -#include "TCanvas.h" -#include "TFrame.h" -#include "TROOT.h" -#include "TFolder.h" -#include "TBenchmark.h" -#include "TParticle.h" -#include "TClonesArray.h" -#include -#include -#include -#include +extern TROOT *gROOT; +extern TRandom *gRandom; +extern TBenchmark *gBenchmark; + +extern AliRun *gAlice; ClassImp(AliTOFT0) //____________________________________________________________________________ - AliTOFT0::AliTOFT0():TTask("AliTOFT0","") +AliTOFT0::AliTOFT0(): + TTask("AliTOFT0",""), + fNevents(0), + fTimeResolution(0), + fLowerMomBound(0), + fUpperMomBound(0), + fT0File(""), + fHeadersFile("") { // ctor - fNevents = 0 ; - fHits = 0 ; - } //____________________________________________________________________________ - AliTOFT0::AliTOFT0(char* headerFile, Int_t nEvents):TTask("AliTOFT0","") +AliTOFT0::AliTOFT0(char* headerFile, Int_t nEvents): + TTask("AliTOFT0",""), + fNevents(nEvents), + fTimeResolution(1.2e-10), + fLowerMomBound(1.5), + fUpperMomBound(2.), + fT0File(""), + fHeadersFile(headerFile) { - fNevents=nEvents ; // Number of events for which calculate the T0, + // + // + // + + //fNevents=nEvents ; // Number of events for which calculate the T0, // default 0: it means all evens in current file - fLowerMomBound=1.5; // [GeV/c] default value - fUpperMomBound=2. ; // [GeV/c] default value - fTimeResolution = 1.2e-10; // 120 ps by default - fHeadersFile = headerFile ; - fHits = 0 ; + //fLowerMomBound=1.5; // [GeV/c] default value + //fUpperMomBound=2. ; // [GeV/c] default value + //fTimeResolution = 1.2e-10; // 120 ps by default + //fHeadersFile = headerFile ; TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ; @@ -124,6 +158,21 @@ ClassImp(AliTOFT0) roottasks->Add(this) ; } +//____________________________________________________________________________ +AliTOFT0::AliTOFT0(const AliTOFT0 & tzero): + TTask("AliTOFT0",""), + fNevents(0), + fTimeResolution(0), + fLowerMomBound(0), + fUpperMomBound(0), + fT0File(""), + fHeadersFile("") +{ + // copy ctr + +( (AliTOFT0 &)tzero ).Copy(*this); +} + //____________________________________________________________________________ AliTOFT0::~AliTOFT0() { @@ -212,53 +261,60 @@ void AliTOFT0::Exec(Option_t *option) Float_t chisquare=999.; Float_t tracktoflen[10]={0.,0.,0.,0.,0.,0.,0.,0.,0.,0.}; - AliTOF *TOF = (AliTOF *) gAlice->GetDetector ("TOF"); + AliTOF *detTOF = (AliTOF *) gAlice->GetDetector ("TOF"); - if (!TOF) { + if (!detTOF) { Error("AliTOFT0","TOF not found"); return; } if(strstr(option,"all")){ - cout << "Selecting primary tracks with momentum between " << fLowerMomBound << " GeV/c and " << fUpperMomBound << " GeV/c" << endl; - cout << "Memorandum: 0 means PION | 1 means KAON | 2 means PROTON" << endl; + AliInfo(Form("Selecting primary tracks with momentum between %f GeV/c and %f GeV/c", fLowerMomBound, fUpperMomBound)); + AliInfo("Memorandum: 0 means PION | 1 means KAON | 2 means PROTON"); } - if (fNevents == 0) fNevents = (Int_t) gAlice->TreeE()->GetEntries(); + if (fNevents == 0) fNevents = (Int_t) AliRunLoader::Instance()->TreeE()->GetEntries(); for (Int_t ievent = 0; ievent < fNevents; ievent++) { gAlice->GetEvent(ievent); - TTree *TH = gAlice->TreeH (); - if (!TH) + TTree *hitTree = detTOF->GetLoader()->TreeH (); + if (!hitTree) return; TParticle* particle; AliTOFhitT0* tofHit; - TClonesArray* TOFhits = TOF->Hits(); + TClonesArray* tofHits = detTOF->Hits(); Int_t lasttrack=-1; Int_t nset=0; + + hitTree->SetBranchStatus("*",0); // switch off all branches + hitTree->SetBranchStatus("TOF*",1); // switch on only TOF + // Start loop on primary tracks in the hits containers - Int_t ntracks = static_cast(TH->GetEntries()); + Int_t ntracks = static_cast(hitTree->GetEntries()); for (Int_t track = 0; track < ntracks; track++) { if(nset>=5) break; // check on the number of set analyzed - gAlice->ResetHits(); - TH->GetEvent(track); - particle = gAlice->Particle(track); - Int_t nhits = TOFhits->GetEntriesFast(); + gAlice->GetMCApp()->ResetHits(); + hitTree->GetEvent(track); + + //AliMC *mcApplication = (AliMC*)gAlice->GetMCApp(); + + //particle = mcApplication->Particle(track); + Int_t nhits = tofHits->GetEntriesFast(); for (Int_t hit = 0; hit < nhits; hit++) { - tofHit = (AliTOFhitT0 *) TOFhits->UncheckedAt(hit); + tofHit = (AliTOFhitT0 *) tofHits->UncheckedAt(hit); ipart = tofHit->GetTrack(); // check to discard the case when the same particle is selected more than one // time if (ipart != ipartold){ - particle = (TParticle*)gAlice->Particle(ipart); + particle = (TParticle*)gAlice->GetMCApp()->Particle(ipart); Float_t idealtime=tofHit->GetTof(); // Float_t time=idealtime; @@ -282,7 +338,7 @@ void AliTOFT0::Exec(Option_t *option) timeofflight[index]=time; tracktoflen[index]=toflen; momentum[index]=mom; - // cout << timeofflight[index] << " " << tracktoflen[index] << " " << momentum[index] << endl; + //AliInfo(Form(" %d %d %d ", timeofflight[index], tracktoflen[index], momentum[index])); switch (abspdg) { case 211: truparticle[index]=0; @@ -303,40 +359,37 @@ void AliTOFT0::Exec(Option_t *option) lasttrack=track; istop=0; selected=0; - //cout << "starting t0 calculation for current set" << endl; + //AliInfo("starting t0 calculation for current set"); for (Int_t i1=0; i1<3;i1++) { + beta[0]=momentum[0]/sqrt(massarray[i1]*massarray[i1]+momentum[0]*momentum[0]); for (Int_t i2=0; i2<3;i2++) { + beta[1]=momentum[1]/sqrt(massarray[i2]*massarray[i2]+momentum[1]*momentum[1]); for (Int_t i3=0; i3<3;i3++) { + beta[2]=momentum[2]/sqrt(massarray[i3]*massarray[i3]+momentum[2]*momentum[2]); for (Int_t i4=0; i4<3;i4++) { + beta[3]=momentum[3]/sqrt(massarray[i4]*massarray[i4]+momentum[3]*momentum[3]); for (Int_t i5=0; i5<3;i5++) { + beta[4]=momentum[4]/sqrt(massarray[i5]*massarray[i5]+momentum[4]*momentum[4]); for (Int_t i6=0; i6<3;i6++) { + beta[5]=momentum[5]/sqrt(massarray[i6]*massarray[i6]+momentum[5]*momentum[5]); for (Int_t i7=0; i7<3;i7++) { + beta[6]=momentum[6]/sqrt(massarray[i7]*massarray[i7]+momentum[6]*momentum[6]); for (Int_t i8=0; i8<3;i8++) { + beta[7]=momentum[7]/sqrt(massarray[i8]*massarray[i8]+momentum[7]*momentum[7]); for (Int_t i9=0; i9<3;i9++) { + beta[8]=momentum[8]/sqrt(massarray[i9]*massarray[i9]+momentum[8]*momentum[8]); for (Int_t i10=0; i10<3;i10++) { - - beta[0]=momentum[0]/sqrt(massarray[i1]*massarray[i1]+momentum[0]*momentum[0]); - beta[1]=momentum[1]/sqrt(massarray[i2]*massarray[i2]+momentum[1]*momentum[1]); - beta[2]=momentum[2]/sqrt(massarray[i3]*massarray[i3]+momentum[2]*momentum[2]); - beta[3]=momentum[3]/sqrt(massarray[i4]*massarray[i4]+momentum[3]*momentum[3]); - beta[4]=momentum[4]/sqrt(massarray[i5]*massarray[i5]+momentum[4]*momentum[4]); - beta[5]=momentum[5]/sqrt(massarray[i6]*massarray[i6]+momentum[5]*momentum[5]); - beta[6]=momentum[6]/sqrt(massarray[i7]*massarray[i7]+momentum[6]*momentum[6]); - beta[7]=momentum[7]/sqrt(massarray[i8]*massarray[i8]+momentum[7]*momentum[7]); - beta[8]=momentum[8]/sqrt(massarray[i9]*massarray[i9]+momentum[8]*momentum[8]); beta[9]=momentum[9]/sqrt(massarray[i10]*massarray[i10]+momentum[9]*momentum[9]); - Float_t meantzero=0.; Float_t sumAllweights=0.; for (Int_t itz=0; itz<10;itz++) { sqMomError[itz]=((1.-beta[itz]*beta[itz])*0.025)*((1.-beta[itz]*beta[itz])*0.025)*(tracktoflen[itz]/(0.299792*beta[itz]))*(tracktoflen[itz]/(0.299792*beta[itz])); // this gives the square of the momentum error in nanoseconds sqTrackError[itz]=(timeresolutioninns*timeresolutioninns+sqMomError[itz]); // total error for the current track sumAllweights+=1./sqTrackError[itz]; - // redefining beta, it is useful in order to calculate t zero - beta[itz]*=0.299792; - timezero[itz]=(tracktoflen[itz]/beta[itz])-timeofflight[itz]; - weightedtimezero[itz]=((tracktoflen[itz]/beta[itz])-timeofflight[itz])/sqTrackError[itz];// weighted time zero for current track + + timezero[itz]=(tracktoflen[itz]/(beta[itz]*0.299792))-timeofflight[itz]; + weightedtimezero[itz]=((tracktoflen[itz]/(beta[itz]*0.299792))-timeofflight[itz])/sqTrackError[itz];// weighted time zero for current track meantzero+=weightedtimezero[itz]; } // end loop for (Int_t itz=0; itz<10;itz++) meantzero=meantzero/sumAllweights; // it is given in [ns] @@ -392,10 +445,10 @@ void AliTOFT0::Exec(Option_t *option) hchibestconflevel->Fill(confLevel); itimes++; if(strstr(option,"all")){ - cout << "True Assignment " << truparticle[0] << truparticle[1] << truparticle[2] << truparticle[3] << truparticle[4] << truparticle[5] << truparticle[6] << truparticle[7] << truparticle[8] << truparticle[9] <Stop("TOFT0"); - cout << "AliTOFT0:" << endl ; + AliInfo("AliTOFT0:"); + /* cout << " took " << gBenchmark->GetCpuTime("TOFT0") << " seconds in order to calculate T0 " - << gBenchmark->GetCpuTime("TOFT0")/fNevents << " seconds per event " << endl ; - cout << endl ; + << gBenchmark->GetCpuTime("TOFT0")/fNevents << " seconds per event " << endl ; + */ + gBenchmark->Print("TOFT0"); } } //__________________________________________________________________ -void AliTOFT0::SetTZeroFile(char * file ){ - cout << "Destination file : " << file << endl ; +void AliTOFT0::SetTZeroFile(char * file ) +{ + // + // Set T0 file name + // + printf("Destination file : %s \n", file) ; fT0File=file; + } + //__________________________________________________________________ -void AliTOFT0::Print(Option_t* option)const +void AliTOFT0::Print(Option_t* /*option*/)const { - cout << "------------------- "<< GetName() << " -------------" << endl ; + // + // Print class content + // + printf("------------------- %s -------------\n", GetName()) ; if(!fT0File.IsNull()) - cout << " Writing T0 Distribution to file " << (char*) fT0File.Data() << endl ; + printf(" Writing T0 Distribution to file %s \n",(char*) fT0File.Data()); + } //__________________________________________________________________ Bool_t AliTOFT0::operator==( AliTOFT0 const &tzero )const { - // Equal operator. + // + // Equal operator // if( (fTimeResolution==tzero.fTimeResolution)&&(fLowerMomBound==tzero.fLowerMomBound)&&(fUpperMomBound==tzero.fUpperMomBound)) @@ -489,4 +557,3 @@ Bool_t AliTOFT0::operator==( AliTOFT0 const &tzero )const else return kFALSE ; } -