--- /dev/null
+////////////////////////////////////////////////////////////////////////
+//
+// name: AliHits2SDigits
+// date: 4.4.2002
+// last update: 4.4.2002
+// author: Jiri Chudoba
+// version: 1.0
+//
+// description:
+// creates sdigits for several detectors
+// stores sdigits in separate file (or in the source file
+// with hits). Stores gAlice object and copies TE to the
+// file with sdigits
+//
+// input:
+// TString fileNameSDigits ... output file with sdigits
+// TString fileNameHits ... input file with hits
+// Int_t nEvents ... how many events to proceed
+// Int_t firstEvent ... first event number
+// Int_t ITS, TPC, ... many flags for diff. detectors
+//
+// History:
+//
+// 04.04.02 - first version
+//
+////////////////////////////////////////////////////////////////////////
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include "iostream.h"
+#include "TTree.h"
+#include "TBranch.h"
+#include "TDirectory.h"
+#include "TFile.h"
+#include "AliRun.h"
+#include "TParticle.h"
+#include "TPC/AliTPCDigitsArray.h"
+#include "AliHeader.h"
+#include "TGeometry.h"
+#include "TObjArray.h"
+#include "TString.h"
+#include "ITS/AliITS.h"
+#include "TPC/AliTPC.h"
+#include "PHOS/AliPHOSSDigitizer.h"
+#include "TOF/AliTOFSDigitizer.h"
+#include "TRD/AliTRDdigitizer.h"
+#include "TStopwatch.h"
+#include "TRD/AliTRDparameter.h"
+#endif
+
+TFile* Init(TString fileNameSDigits, TString fileNameHits);
+TFile* OpenFile(TString fileName);
+Bool_t ImportgAlice(TFile *file);
+AliTRDdigitizer *InitTRDdigitizer();
+void AliCopy(TFile *inputFile, TFile *outputFile);
+
+// global variables
+
+TFile *gFileHits = 0;
+Bool_t gSameFiles = kFALSE;
+Int_t gDEBUG = 1;
+
+
+Int_t AliHits2SDigits(TString fileNameSDigits="sdigits.root",
+ TString fileNameHits="rfio:galice.root",
+ Int_t nEvents = 1, Int_t firstEvent = 0, Int_t iITS = 0,
+ Int_t iTPC = 0, Int_t iTRD = 0,Int_t iPHOS = 0,
+ Int_t iTOF = 1, Int_t iCopy = 1)
+{
+//
+// Initialization
+//
+ TFile *fileSDigits;
+ fileSDigits = Init(fileNameSDigits, fileNameHits);
+ if (!fileSDigits) return 1;
+ if (iCopy) {
+ AliCopy(gFileHits,fileSDigits);
+ gFileHits->cd();
+ }
+
+// ITS
+ AliITS *ITS;
+ if (iITS) {
+ ITS = (AliITS*) gAlice->GetModule("ITS");
+ if (!ITS) {
+ iITS = 0;
+ cerr<<"AliITS object not found on file." << endl;
+ } else if (!ITS->GetITSgeom()) {
+ cerr<<"AliITSgeom not found." << endl;
+ iITS = 0;
+ }
+ }
+
+// TPC
+ AliTPC *TPC;
+ if (iTPC) {
+ TPC = (AliTPC*)gAlice->GetDetector("TPC");
+ if (!TPC) {
+ iTPC = 0;
+ cerr<<"AliTPC object not found"<<endl;
+ }
+ }
+
+// TRD
+ AliTRDdigitizer *sdTRD;
+ if (iTRD) {
+ sdTRD = InitTRDdigitizer();
+ }
+
+
+// PHOS
+ AliPHOSSDigitizer *sdPHOS;
+ if (iPHOS) {
+ sdPHOS = new AliPHOSSDigitizer(fileNameHits.Data());
+ }
+
+// TOF
+ AliTOFSDigitizer *sdTOF;
+ if (iTOF) {
+ sdTOF = new AliTOFSDigitizer(fileNameHits.Data(),fileNameSDigits.Data(),firstEvent,nEvents);
+ }
+
+
+//
+// loop over events
+//
+ TStopwatch timer;
+ timer.Start();
+ for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
+ gAlice->GetEvent(iEvent);
+ gAlice->MakeTree("S",fileSDigits);
+
+// ITS
+ if (iITS) {
+ if (gDEBUG) {cout<<" Create ITS sdigits: ";}
+ ITS->MakeBranch("S");
+ ITS->SetTreeAddress();
+ ITS->Hits2SDigits();
+ if (gDEBUG) {cout<<"done"<<endl;}
+ }
+
+// TPC
+ if (iTPC) {
+ if (gDEBUG) {cout<<" Create TPC sdigits: ";}
+ TPC->SetActiveSectors(1);
+ TPC->Hits2SDigits2(iEvent);
+ if (gDEBUG) {cout<<"done"<<endl;}
+ }
+
+// TRD
+ if (iTRD) {
+ if (gDEBUG) {cout<<" Create TRD sdigits: ";}
+ sdTRD->InitOutput(fileSDigits, iEvent);
+ sdTRD->MakeDigits();
+ sdTRD->WriteDigits();
+ if (gDEBUG) {cout<<"done"<<endl;}
+ }
+
+ } // end of loop over events
+
+// PHOS processes always all events
+ if (iPHOS) {
+ sdPHOS->ExecuteTask("deb all");
+ }
+
+// TOF (precesses the events as specified in the AliTOFSDigitizer
+// par ctor)
+ if (iTOF) {
+ // Activate this line if you want to print the
+ // parameters used for sdigitization
+ // sdTOF->PrintParameters();
+ sdTOF->Exec("all");
+ }
+
+//
+// finish
+//
+ timer.Stop();
+ timer.Print();
+
+ if (iTRD) {
+ fileSDigits->cd();
+ sdTRD->GetParameter()->Write();
+ gFileHits->cd();
+ }
+
+ fileSDigits->Close();
+ delete fileSDigits;
+ if (!gSameFiles) {
+ gFileHits->Close();
+ delete gFileHits;
+ }
+
+}
+
+
+////////////////////////////////////////////////////////////////////////
+TFile* Init(TString fileNameSDigits, TString fileNameHits) {
+// open input file, read in gAlice, prepare output file
+ if (gAlice) delete gAlice;
+ gAlice = 0;
+
+ Bool_t gSameFiles = kFALSE;
+ if (fileNameSDigits == fileNameHits || fileNameSDigits == "") gSameFiles = kTRUE;
+
+ TString fileMode = "read";
+ if (gSameFiles) fileMode = "update";
+
+ gFileHits = TFile::Open(fileNameHits.Data(),fileMode.Data());
+ if (!gFileHits->IsOpen()) {
+ cerr<<"Can't open "<<fileNameHits.Data()<<" !\n";
+ return 0;
+ }
+ if (!ImportgAlice(gFileHits)) return 0;
+ if (!gSameFiles) return gAlice->InitTreeFile("S",fileNameSDigits.Data());
+ return gFileHits;
+
+}
+
+////////////////////////////////////////////////////////////////////////
+TFile* OpenFile(TString fileName) {
+// open file fileName
+ TFile *file = TFile::Open(fileName.Data());
+ if (!file->IsOpen()) {
+ cerr<<"Can't open "<<fileName.Data()<<" !\n";
+ return 0;
+ }
+ return file;
+}
+
+////////////////////////////////////////////////////////////////////////
+Bool_t ImportgAlice(TFile *file) {
+// read in gAlice object from the file
+ gAlice = (AliRun*)file->Get("gAlice");
+ if (!gAlice) return kFALSE;
+ return kTRUE;
+}
+////////////////////////////////////////////////////////////////////////
+AliTRDdigitizer *InitTRDdigitizer() {
+// initialization of TRD digitizer
+ AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
+ ,"TRD digitizer class");
+ sdTRD->SetDebug(0);
+ sdTRD->SetSDigits(kTRUE);
+ AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
+ ,"TRD parameter class");
+
+ sdTRD->SetParameter(TRDparam);
+ sdTRD->InitDetector();
+ return sdTRD;
+}
+////////////////////////////////////////////////////////////////////////
+void AliCopy(TFile *inputFile, TFile *outputFile) {
+// copy some objects
+
+// copy gAlice
+ if (gDEBUG) cout<<"Copy gAlice: ";
+ outputFile->cd();
+ gAlice->Write();
+ if (gDEBUG) cout<<"done"<<endl;
+
+ TTree *treeE = gAlice->TreeE();
+ if (!treeE) {
+ cerr<<"No TreeE found "<<endl;
+ return;
+ }
+
+// copy TreeE
+ if (gDEBUG) cout<<"Copy TreeE: ";
+ AliHeader *header = new AliHeader();
+ treeE->SetBranchAddress("Header", &header);
+ treeE->SetBranchStatus("*",1);
+ TTree *treeENew = treeE->CloneTree();
+ treeENew->Write();
+ if (gDEBUG) cout<<"done"<<endl;
+
+// copy AliceGeom
+ if (gDEBUG) cout<<"Copy AliceGeom: ";
+ TGeometry *AliceGeom = static_cast<TGeometry*>(inputFile->Get("AliceGeom"));
+ if (!AliceGeom) {
+ cerr<<"AliceGeom was not found in the input file "<<endl;
+ return;
+ }
+ AliceGeom->Write();
+ if (gDEBUG) cout<<"done"<<endl;
+
+}
-//_________________________________________________________________________
-// TOF digit: member variables
-// fSector : TOF sector
-// fPlate : TOF plate
-// fStrip : strips number
-// fPadx : pad number along x
-// fPadz : pad number along z
-// fTdc : TArrayF of TDC values
-// fAdc : TArrayF of ADC values
-//
-// Getters, setters and member functions defined here
-//
-//*-- Authors: F. Pierella, A. Seganti, D. Vicinanza
-
-
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* *
* provided "as is" without express or implied warranty. *
**************************************************************************/
-#include <iostream.h>
+//_________________________________________________________________________
+// TOF sdigit: member variables
+// fSector : TOF sector
+// fPlate : TOF plate
+// fStrip : strips number
+// fPadx : pad number along x
+// fPadz : pad number along z
+// fTdc : TArrayF of TDC values
+// fAdc : TArrayF of ADC values
+//
+// Getters, setters and member functions defined here
+//
+//*-- Authors: F. Pierella, A. Seganti, D. Vicinanza
+
+#include <iostream.h>
#include "TArrayF.h"
#include "TArrayI.h"
ClassImp(AliTOFSDigit)
////////////////////////////////////////////////////////////////////////
-AliTOFSDigit::AliTOFSDigit()
+ AliTOFSDigit::AliTOFSDigit()
{
-//
-// default ctor
-//
+ //
+ // default ctor
+ //
fNDigits = 0;
fTdc = 0;
fAdc = 0;
////////////////////////////////////////////////////////////////////////
AliTOFSDigit::AliTOFSDigit(Int_t tracknum, Int_t *vol,Float_t *digit)
{
-//
-// Constructor of digit object
-//
+ //
+ // Constructor of digit object
+ //
fSector = vol[0];
fPlate = vol[1];
fStrip = vol[2];
////////////////////////////////////////////////////////////////////////
AliTOFSDigit::AliTOFSDigit(Int_t sector, Int_t plate, Int_t strip, Int_t padx,
-Int_t padz, Float_t tdc, Float_t adc)
+ Int_t padz, Float_t tdc, Float_t adc)
{
-//
-// Constructor for sdigit
-//
+ //
+ // Constructor for sdigit
+ //
fSector = sector;
fPlate = plate;
fStrip = strip;
fTdc = new TArrayF(fNDigits);
(*fTdc)[0] = tdc;
fAdc = new TArrayF(fNDigits);
- (*fAdc)[0] = tdc;
-// no tracks were specified, set them to -1
+ (*fAdc)[0] = adc;
+ // no tracks were specified, set them to -1
fTracks = new TArrayI(kMAXDIGITS*fNDigits);
for (Int_t i = 0; i <kMAXDIGITS*fNDigits; i++) {
(*fTracks)[i] = -1;
}
}
-
+
////////////////////////////////////////////////////////////////////////
void AliTOFSDigit::GetLocation(Int_t *Loc) const
{
-//
-// Get the coordinates of the digit
-// in terms of Sector - Plate - Strip - Pad
-//
-
- Loc[0]=fSector;
- Loc[1]=fPlate;
- Loc[2]=fStrip;
- Loc[3]=fPadx;
- Loc[4]=fPadz;
+ //
+ // Get the coordinates of the digit
+ // in terms of Sector - Plate - Strip - Pad
+ //
+
+ Loc[0]=fSector;
+ Loc[1]=fPlate;
+ Loc[2]=fStrip;
+ Loc[3]=fPadx;
+ Loc[4]=fPadz;
}
////////////////////////////////////////////////////////////////////////
void AliTOFSDigit::Update(Int_t tdc, Int_t adc, Int_t track)
{
-//
-// Add charge and track
-//
-
+ //
+ // Add charge and track
+ //
+
Int_t sameTime = -1;
-
+
for (Int_t i = 0; i < fNDigits; i++) {
if (TMath::Abs(tdc-fTdc->At(i)) < AliTOFConstants::fgkTimeDiff) {
sameTime = i;
break;
}
}
-
+
if (sameTime >= 0) {
(*fAdc)[sameTime] += static_cast<Float_t>(adc);
-// update track - find the first -1 value and replace it by the
-// track number
+ // update track - find the first -1 value and replace it by the
+ // track number
for (Int_t iTrack=0; iTrack<kMAXDIGITS; iTrack++) {
if ((*fTracks)[sameTime*kMAXDIGITS+iTrack] == -1) {
(*fTracks)[sameTime*kMAXDIGITS+iTrack] = track;
break;
}
-// write warning about many tracks going to this pad
+ // write warning about many tracks going to this pad
if (iTrack == kMAXDIGITS) {
cerr<<"WARNING: AliTOFSDigit::Update Many hits in the padhit"<<endl;
cerr<<" ";
-// PrintPad();
+ // PrintPad();
}
}
} else {
-// add new time slot
+ // add new time slot
fNDigits++;
fTdc->Set(fNDigits);
(*fTdc)[fNDigits-1] = tdc;
(*fTracks)[(fNDigits-1)*kMAXDIGITS+i] = -1;
}
}
-
+
}
////////////////////////////////////////////////////////////////////////
AliTOFSDigit::~AliTOFSDigit()
{
-//
-// dtor
-//
+ //
+ // dtor
+ //
delete fTdc;
delete fAdc;
delete fTracks;
Int_t AliTOFSDigit::GetTotPad() const
{
-//
-// Get the "total" index of the pad inside a Sector
-// starting from the digits data.
-//
-
+ //
+ // Get the "total" index of the pad inside a Sector
+ // starting from the digits data.
+ //
+
AliTOF* tof;
if(gAlice){
- tof =(AliTOF*) gAlice->GetDetector("TOF");
+ tof =(AliTOF*) gAlice->GetDetector("TOF");
}else{
- printf("AliTOFSDigit::GetTotPad - No AliRun object present, exiting");
- return 0;
+ printf("AliTOFSDigit::GetTotPad - No AliRun object present, exiting");
+ return 0;
}
Int_t pad = fPadx+tof->GetNpadX()*(fPadz-1);
Int_t before=0;
-
+
switch(fPlate){
case 1: before = 0;
- break;
+ break;
case 2: before = tof->GetNStripC();
- break;
+ break;
case 3: before = tof->GetNStripB() + tof->GetNStripC();
- break;
+ break;
case 4: before = tof->GetNStripA() + tof->GetNStripB() + tof->GetNStripC();
- break;
+ break;
case 5: before = tof->GetNStripA() + 2*tof->GetNStripB() + tof->GetNStripC();
- break;
+ break;
}
Int_t strip = fStrip+before;
return padTot;
}
-////////////////////////////////////////////////////////////////////////
-//void AliTOFSDigit::AddTrack(Int_t track)
-//{
-//
-// Add a new and different track to the digit -- but to which digit??
-// do not implemet this function
-//
-////////////////////////////////////////////////////////////////////////
-
-// Overloading of Streaming, Sum and Comparison operators
-
-////////////////////////////////////////////////////////////////////////
-/*
-Bool_t AliTOFSDigit::operator==(AliTOFSDigit const &digit) const
-{
-//
-// Overloading of Comparison operator
-//
- if (fSector==digit.fSector &&
- fPlate==digit.fPlate &&
- fStrip==digit.fStrip &&
- fPadx==digit.fPadx &&
- fPadz==digit.fPadz &&
- fTdc==digit.fTdc &&
- fAdc==digit.fAdc) return kTRUE;
- else return kFALSE;
-}
-*/
-////////////////////////////////////////////////////////////////////////
-/*
-ostream& operator << (ostream& out, const AliTOFSDigit &digit)
-{
-//
-// Output streamer: output of the digit data
-//
-out << "Sector " << digit.fSector << ", Plate " << digit.fPlate << ", Strip " << digit.fStrip << endl;
-out << "Padx" << digit.fPadx << ", Padz " << digit.fPadz << endl;
-out << "TDC " << digit.fTdc->At(0) << ", ADC "<< digit.fAdc->At(0) << endl;
-return out;
-}
-*/
//_________________________________________________________________________
// This is a TTask that constructs SDigits out of Hits
-// A Summable Digits is the sum of all hits in a pad
-//
+// A Summable Digits is the "sum" of all hits in a pad
+// Detector response has been simulated via the method
+// SimulateDetectorResponse
//
-//-- Author: F. Pierella
+//-- Authors: F. Pierella, A. De Caro
+// Use case: see AliTOFhits2sdigits.C macro in the CVS
//////////////////////////////////////////////////////////////////////////////
-
+#include "TBenchmark.h"
#include "TTask.h"
#include "TTree.h"
#include "TSystem.h"
#include "TFile.h"
+#include "TParticle.h"
+#include "TH1.h"
#include "AliTOFHitMap.h"
#include "AliTOFSDigit.h"
AliTOFSDigitizer::AliTOFSDigitizer():TTask("AliTOFSDigitizer","")
{
// ctor
- fNevents = 0 ;
-// fSDigits = 0 ;
- fHits = 0 ;
+ fSDigits = 0 ;
+ fEvent1=0;
+ fEvent2=0;
ftail = 0;
}
//____________________________________________________________________________
- AliTOFSDigitizer::AliTOFSDigitizer(char* HeaderFile,char *SdigitsFile ):TTask("AliTOFSDigitizer","")
+ AliTOFSDigitizer::AliTOFSDigitizer(char* HeaderFile,char *SdigitsFile, Int_t evNumber1, Int_t nEvents):TTask("AliTOFSDigitizer","")
{
- fNevents = 0 ; // Number of events to digitize, 0 means all evens in current file
+ fEvent1=evNumber1;
+ fEvent2=fEvent1+nEvents;
+ fSDigits = 0;
ftail = 0;
+ fHeadersFile = HeaderFile ; // input filename (with hits)
+ fSDigitsFile = SdigitsFile; // output filename for sdigits
+ TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
+
+ //File was not opened yet
+ // open file and get alirun object
+ if(file == 0){
+ file = TFile::Open(fHeadersFile.Data(),"update") ;
+ gAlice = (AliRun *) file->Get("gAlice") ;
+ }
+
// init parameters for sdigitization
InitParameters();
fLogChargeSmearing=0.13;
fTimeSmearing =0.022;
fAverageTimeFlag=0 ;
-
+ fTdcBin = 50.; // 1 TDC bin = 50 ps
+ fAdcBin = 0.25; // 1 ADC bin = 0.25 pC (or 0.03 pC)
+ fAdcMean = 50.; // ADC distribution mpv value for Landau (in bins)
+ // it corresponds to a mean value of ~100 bins
+ fAdcRms = 25.; // ADC distribution rms value (in bins)
+ // it corresponds to distribution rms ~50 bins
}
//__________________________________________________________________
-Double_t TimeWithTailS(Double_t* x, Double_t* par)
+Double_t TimeWithTail(Double_t* x, Double_t* par)
{
// sigma - par[0], alpha - par[1], part - par[2]
// at x<part*sigma - gauss
//____________________________________________________________________________
-void AliTOFSDigitizer::Exec(Option_t *option) {
+void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) {
+ if(strstr(verboseOption,"tim") || strstr(verboseOption,"all"))
+ gBenchmark->Start("TOFSDigitizer");
AliTOF *TOF = (AliTOF *) gAlice->GetDetector ("TOF");
return;
}
- if (fEdgeTails) ftail = new TF1("tail",TimeWithTailS,-2,2,3);
+ if (fEdgeTails) ftail = new TF1("tail",TimeWithTail,-2,2,3);
+
+ Int_t nselectedHits=0;
+ Int_t ntotalsdigits=0;
+ Int_t ntotalupdates=0;
+ Int_t nnoisesdigits=0;
+ Int_t nsignalsdigits=0;
+ Int_t nHitsFromPrim=0;
+ Int_t nHitsFromSec=0;
+ Int_t nlargeTofDiff=0;
- if (fNevents == 0)
- fNevents = (Int_t) gAlice->TreeE()->GetEntries();
+ if (strstr(allEvents,"all")){
+ fEvent1=0;
+ fEvent2= (Int_t) gAlice->TreeE()->GetEntries();
+ }
+
+ for (Int_t ievent = fEvent1; ievent < fEvent2; ievent++) {
+ cout << "------------------- "<< GetName() << " -------------" << endl ;
+ cout << "Sdigitizing event " << ievent << endl;
+
+ Int_t nselectedHitsinEv=0;
+ Int_t ntotalsdigitsinEv=0;
+ Int_t ntotalupdatesinEv=0;
+ Int_t nnoisesdigitsinEv=0;
+ Int_t nsignalsdigitsinEv=0;
- for (Int_t ievent = 0; ievent < fNevents; ievent++) {
gAlice->GetEvent(ievent);
TTree *TH = gAlice->TreeH ();
if (!TH)
vol[3] = tofHit->GetPadx();
vol[4] = tofHit->GetPadz();
- Bool_t isCloneOfThePrevious=((tracknum==previousTrack) && (vol[0]==previousSector) && (vol[1]==previousPlate) && (vol[2]==previousStrip) && (vol[3]==previousPadX) && (vol[4]==previousPadZ));
-
+ Bool_t dummy=((tracknum==previousTrack) && (vol[0]==previousSector) && (vol[1]==previousPlate) && (vol[2]==previousStrip));
+
+ Bool_t isCloneOfThePrevious=dummy && ((vol[3]==previousPadX) && (vol[4]==previousPadZ));
+
+ // much stronger check to be inserted here
+
if(!isCloneOfThePrevious){
// update "previous" values
// in fact, we are yet in the future, so the present is past
previousPadX=vol[3];
previousPadZ=vol[4];
- // 95% of efficiency to be inserted here
- // edge effect to be inserted here
- // cross talk to be inserted here
-
- Float_t idealtime = tofHit->GetTof(); // unit s
- idealtime *= 1.E+12; // conversion from s to ps
- // fTimeRes is given usually in ps
- Float_t tdctime = gRandom->Gaus(idealtime, TOF->GetTimeRes());
- digit[0] = tdctime;
-
- // typical Landau Distribution to be inserted here
- // instead of Gaussian Distribution
- Float_t idealcharge = tofHit->GetEdep();
- Float_t adccharge = gRandom->Gaus(idealcharge, TOF->GetChrgRes());
- digit[1] = adccharge;
-
- // check if two digit are on the same pad; in that case we sum
- // the two or more digits
- if (hitMap->TestHit(vol) != kEmpty) {
- AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(hitMap->GetHit(vol));
- sdig->Update(tdctime,adccharge,tracknum);
- } else {
- TOF->AddSDigit(tracknum, vol, digit);
- hitMap->SetHit(vol);
- }
+ nselectedHits++;
+ nselectedHitsinEv++;
+ if (particle->GetFirstMother() < 0){
+ nHitsFromPrim++;
+ } // counts hits due to primary particles
+
+ Float_t Xpad = tofHit->GetDx();
+ Float_t Zpad = tofHit->GetDz();
+ Float_t xStrip=AliTOFConstants::fgkXPad*(vol[3]-0.5-0.5*AliTOFConstants::fgkNpadX)+Xpad;
+ Float_t zStrip=AliTOFConstants::fgkZPad*(vol[4]-0.5-0.5*AliTOFConstants::fgkNpadZ)+Zpad;
+ Float_t geantTime = tofHit->GetTof(); // unit [s]
+ geantTime *= 1.e+09; // conversion from [s] to [ns]
+
+ //cout << "geantTime " << geantTime << " [ns]" << endl;
+ Int_t nActivatedPads = 0, nFiredPads = 0;
+ Bool_t isFired[4] = {kFALSE, kFALSE, kFALSE, kFALSE};
+ Float_t tofAfterSimul[4] = {0., 0., 0., 0.};
+ Float_t qInduced[4] = {0.,0.,0.,0.};
+ Int_t nPlace[4] = {0, 0, 0, 0};
+ Float_t averageTime = 0.;
+ SimulateDetectorResponse(zStrip,xStrip,geantTime,nActivatedPads,nFiredPads,isFired,nPlace,qInduced,tofAfterSimul,averageTime);
+ if(nFiredPads) {
+ for(Int_t indexOfPad=0; indexOfPad<nActivatedPads; indexOfPad++) {
+ if(isFired[indexOfPad]){ // the pad has fired
+ Float_t timediff=geantTime-tofAfterSimul[indexOfPad];
+
+ if(timediff>=0.2) nlargeTofDiff++;
+
+ digit[0] = (Int_t) ((tofAfterSimul[indexOfPad]*1.e+03)/fTdcBin); // TDC bin number (each bin -> 25. ps)
+
+ Float_t landauFactor = gRandom->Landau(fAdcMean, fAdcRms);
+ digit[1] = (Int_t) (qInduced[indexOfPad] * landauFactor); // ADC bins (each bin -> 0.25 (or 0.03) pC)
+
+ // recalculate the volume only for neighbouring pads
+ if(indexOfPad){
+ (nPlace[indexOfPad]<=AliTOFConstants::fgkNpadX) ? vol[4] = 1 : vol[4] = 2;
+ (nPlace[indexOfPad]<=AliTOFConstants::fgkNpadX) ? vol[3] = nPlace[indexOfPad] : vol[3] = nPlace[indexOfPad] - AliTOFConstants::fgkNpadX;
+ }
+
+ // check if two sdigit are on the same pad; in that case we sum
+ // the two or more sdigits
+ if (hitMap->TestHit(vol) != kEmpty) {
+ AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(hitMap->GetHit(vol));
+ Int_t tdctime = (Int_t) digit[0];
+ Int_t adccharge = (Int_t) digit[1];
+ sdig->Update(tdctime,adccharge,tracknum);
+ ntotalupdatesinEv++;
+ ntotalupdates++;
+ } else {
+
+ TOF->AddSDigit(tracknum, vol, digit);
+
+ if(indexOfPad){
+ nnoisesdigits++;
+ nnoisesdigitsinEv++;
+ } else {
+ nsignalsdigits++;
+ nsignalsdigitsinEv++;
+ }
+ ntotalsdigitsinEv++;
+ ntotalsdigits++;
+ hitMap->SetHit(vol);
+ } // if (hitMap->TestHit(vol) != kEmpty)
+ } // if(isFired[indexOfPad])
+ } // end loop on nActivatedPads
+ } // if(nFiredPads) i.e. if some pads has fired
} // close if(!isCloneOfThePrevious)
} // end loop on hits for the current track
} // end loop on ntracks
gAlice->TreeS()->Reset();
gAlice->TreeS()->Fill();
- gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
- } //event loop
+ //gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
+ gAlice->TreeS()->AutoSave();
+
+ if(strstr(verboseOption,"all")){
+ cout << "----------------------------------------" << endl;
+ cout << " <AliTOFSDigitizer> " << endl;
+ cout << "After sdigitizing " << nselectedHitsinEv << " hits" << " in event " << ievent << endl;
+ //" (" << nHitsFromPrim << " from primaries and " << nHitsFromSec << " from secondaries) TOF hits, "
+ cout << ntotalsdigitsinEv << " digits have been created " << endl;
+ cout << "(" << nsignalsdigitsinEv << " due to signals and " << nnoisesdigitsinEv << " due to border effect)" << endl;
+ cout << ntotalupdatesinEv << " total updates of the hit map have been performed in current event" << endl;
+ cout << "----------------------------------------" << endl;
+ }
+
+ } //event loop on events
+
+ // free used memory
+ if (ftail){
+ delete ftail;
+ ftail = 0;
+ }
+
+ nHitsFromSec=nselectedHits-nHitsFromPrim;
+ if(strstr(verboseOption,"all")){
+ cout << "----------------------------------------" << endl;
+ cout << "----------------------------------------" << endl;
+ cout << "-----------SDigitization Summary--------" << endl;
+ cout << " <AliTOFSDigitizer> " << endl;
+ cout << "After sdigitizing " << nselectedHits << " hits" << endl;
+ cout << "in " << (fEvent2-fEvent1) << " events" << endl;
+//" (" << nHitsFromPrim << " from primaries and " << nHitsFromSec << " from secondaries) TOF hits, "
+ cout << ntotalsdigits << " sdigits have been created " << endl;
+ cout << "(" << nsignalsdigits << " due to signals and " << nnoisesdigits << " due to border effect)" << endl;
+ cout << ntotalupdates << " total updates of the hit map have been performed" << endl;
+ cout << "in " << nlargeTofDiff << " cases the time of flight difference is greater than 200 ps" << endl;
+ }
+
+ if(strstr(verboseOption,"tim") || strstr(verboseOption,"all")){
+ gBenchmark->Stop("TOFSDigitizer");
+ cout << "AliTOFSDigitizer:" << endl ;
+ cout << " took " << gBenchmark->GetCpuTime("TOFSDigitizer") << " seconds in order to make sdigits "
+ << gBenchmark->GetCpuTime("TOFSDigitizer")/(fEvent2-fEvent1) << " seconds per event " << endl ;
+ cout << endl ;
+ }
+ Print("");
}
//__________________________________________________________________
cout << "Changing SDigits file from " <<(char *)fSDigitsFile.Data() << " to " << file << endl ;
fSDigitsFile=file ;
}
+
//__________________________________________________________________
-void AliTOFSDigitizer::Print(Option_t* option)const
+void AliTOFSDigitizer::Print(Option_t* opt)const
{
cout << "------------------- "<< GetName() << " -------------" << endl ;
if(fSDigitsFile.IsNull())
- cout << " Writing SDigitis to file galice.root "<< endl ;
+ cout << " Writing SDigits to file with hits "<< endl ;
else
- cout << " Writing SDigitis to file " << (char*) fSDigitsFile.Data() << endl ;
-
+ cout << " Writing SDigits to file " << (char*) fSDigitsFile.Data() << endl ;
+ cout << "--------------------------------------------------" << endl;
}
//__________________________________________________________________
cout << " Parameters used for TOF SDigitization " << endl ;
// Printing the parameters
- cout << " Number of events: " << fNevents << endl;
-
+ cout << " Number of events: " << (fEvent2-fEvent1) << endl;
+ cout << " from event " << fEvent1 << " to event " << (fEvent2-1) << endl;
cout << " Time Resolution (ns) "<< fTimeResolution <<" Pad Efficiency: "<< fpadefficiency << endl;
cout << " Edge Effect option: "<< fEdgeEffect<< endl;
//_________________________________________________________________________
// Task Class for making SDigits in TOF
//
-//-- Author: F. Pierella
+//-- Authors: F. Pierella, A. De Caro
#include "TTask.h"
public:
AliTOFSDigitizer() ; // ctor
- AliTOFSDigitizer(char* HeaderFile, char *SdigitsFile = 0) ;
+ AliTOFSDigitizer(char* HeaderFile, char *SdigitsFile = 0, Int_t evNumber1=0, Int_t nEvents=1) ; // par ctor
virtual ~AliTOFSDigitizer() ; // dtor
-
-// char *GetSDigitsFile() const {return const_cast<char*>(fSDigitsFile.Data());}
+
const char *GetSDigitsFile() const {return fSDigitsFile.Data();}
- virtual void Exec(Option_t *option);
- void SetNEvents(Int_t Nevents) {fNevents = Nevents;}
- Int_t GetNEvents() const {return fNevents;}
+ virtual void Exec(Option_t *verboseOption, Option_t *allEvents="noAll");
void SetSDigitsFile(char * file ) ;
void InitParameters();
virtual void PrintParameters() const ;
virtual void SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t geantTime, Int_t& nActivatedPads, Int_t& nFiredPads, Bool_t* isFired, Int_t* nPlace, Float_t* qInduced, Float_t* tofTime, Float_t& averageTime);
- virtual void Print(Option_t* option) const ;
+ virtual void Print(Option_t* opt) const ;
TClonesArray *SDigits() const {return fSDigits;}
- TClonesArray *Hits() const {return fHits;}
+ void SetFirstEvent(Int_t event1) {fEvent1=event1;}
+ void SetSecondEvent(Int_t event2) {fEvent2=event2;}
+ Int_t GetFirstEvent() const {return fEvent1;}
+ Int_t GetSecondEvent() const {return fEvent2;}
+ Int_t GetNEvents() const {return (fEvent2-fEvent1);}
// setters and getters for detector simulation
// it summarizes all it is known about TOF strip
void SetLogChargeSmearing(Float_t logChargeSmearing){fLogChargeSmearing=logChargeSmearing;}
void SetTimeSmearing(Float_t timeSmearing) {fTimeSmearing=timeSmearing;}
void SetAverageTimeFlag(Int_t averageTimeFlag) {fAverageTimeFlag=averageTimeFlag;}
+ void SetTdcBin(Float_t tdcBin) {fTdcBin=tdcBin;}
+ void SetAdcBin(Float_t adcBin) {fAdcBin=adcBin;}
+ void SetAdcMean(Float_t adcMean) {fAdcMean=adcMean;}
+ void SetAdcRms(Float_t adcRms) {fAdcRms=adcRms;}
Float_t GetPadefficiency() const {return fpadefficiency;}
Int_t GetEdgeEffect() const {return fEdgeEffect;}
Float_t GetLogChargeSmearing()const {return fLogChargeSmearing;}
Float_t GetTimeSmearing() const {return fTimeSmearing;}
Int_t GetAverageTimeFlag() const {return fAverageTimeFlag;}
+ Float_t GetTdcBin() const {return fTdcBin;}
+ Float_t GetAdcBin() const {return fAdcBin;}
+ Float_t GetAdcMean() const {return fAdcMean;}
+ Float_t GetAdcRms() const {return fAdcRms;}
private:
- Int_t fNevents; // Number of events to digitize
+ Int_t fEvent1; // lower bound for events to sdigitize
+ Int_t fEvent2; // upper bound for events to sdigitize
TString fSDigitsFile; // output file
- TClonesArray *fSDigits; // array of summable digits
- TClonesArray *fHits; // array of summable digits
+ TClonesArray *fSDigits; //! array of summable digits
TF1 *ftail; // pointer to formula for time with tail
TString fHeadersFile; // input file
Float_t fLogChargeSmearing;// Smearing in log of charge ratio
Float_t fTimeSmearing; // Smearing in time in time vs log(q1/q2) plot
Int_t fAverageTimeFlag; // flag (see the setter for details)
+ Float_t fTdcBin; // time-window for the TDC bins [ps]
+ Float_t fAdcBin; // charge-window for the ADC bins [pC]
+ Float_t fAdcMean; // mean value for the ADC spectrum [bins]
+ Float_t fAdcRms; // rms value for the ADC spectrum [bins]
protected:
AliTOFT0::AliTOFT0():TTask("AliTOFT0","")
{
// ctor
- fNevents = 0 ;
- fHits = 0 ;
-
+ fNevents = 0 ;
}
//____________________________________________________________________________
fUpperMomBound=2. ; // [GeV/c] default value
fTimeResolution = 1.2e-10; // 120 ps by default
fHeadersFile = headerFile ;
- fHits = 0 ;
TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
selected=0;
//cout << "starting t0 calculation for current set" << endl;
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]
void SetTZeroFile(char* file) ;
void SetMomBounds(Float_t pLow, Float_t pUp) { fLowerMomBound=pLow; fUpperMomBound=pUp;} // momenta are expressed in [GeV/c]
virtual void Print(Option_t* option) const ;
- TClonesArray *Hits() const {return fHits;}
Bool_t operator == (const AliTOFT0 & tzero) const ;
private:
Float_t fLowerMomBound; // momentum lower bound for selected primary tracks
Float_t fUpperMomBound; // momentum upper bound for selected primary tracks
TString fT0File ; // output file; it contains for time being only 3 histos
- TClonesArray *fHits; // array of AliTOFhitT0
TString fHeadersFile; // input file
protected:
-
ClassDef(AliTOFT0,1) // Calculate the time zero using TOF detector
};
--- /dev/null
+Int_t AliTOFanalyzeSDigits(TString headersFile, Int_t iEvNum=0)
+{
+ //
+ // Analyzes the TOF sdigits and fills QA-histograms
+ //
+ // iEvNum=0 means all events in the file
+
+ Int_t rc=0;
+
+ TFile * file = (TFile*) gROOT->GetFile(headersFile.Data() ) ;
+
+ //File was not opened yet
+
+ if(file == 0){
+ if(headersFile.Contains("rfio"))
+ file = TFile::Open(headersFile,"update") ;
+ else
+ file = new TFile(headersFile.Data(),"update") ;
+ gAlice = (AliRun *) file->Get("gAlice") ;
+ }
+
+
+ if (iEvNum == 0) iEvNum = (Int_t) gAlice->TreeE()->GetEntries();
+
+
+ AliTOFSDigit *tofsdigit;
+
+ AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
+
+ if (!tof) {
+ cout << "<AliTOFanalyzeSDigits> No TOF detector found" << endl;
+ rc = 2;
+ return rc;
+ }
+
+ // adc and tdc
+ TH1F *htdc = new TH1F("htdc","TDC [bin]",5000,0.,150000.);
+ TH1F *hadc = new TH1F("hadc","ADC [bin]",100,0., 3000.);
+
+ // TOF sdigit volumes
+ TH1F *hsector = new TH1F("hsector","Sector",20,0.,20.);
+ TH1F *hplate = new TH1F("hplate","Plate ", 6,0., 6.);
+ TH1F *hstrip = new TH1F("hstrip","Strip ",25,0.,25.);
+ TH1F *hpadz = new TH1F("hpadz","Pad along z ",3,0.,3.);
+ TH1F *hpadx = new TH1F("hpadx","Pad along x",50,0.,50.);
+ // ADC-TDC correlation
+ TH2F *h2tdcVSadc = new TH2F("h2tdcVSadc","TDC [bin] VS ADC [bin]",500,0.,150000.,100,0.,3000.);
+
+
+ for (Int_t ievent = 0; ievent < iEvNum; ievent++) {
+
+ gAlice->GetEvent(ievent) ;
+ if(gAlice->TreeS()==0) {
+ cout << "<AliTOFanalyzeSDigits> No TreeS found" << endl;
+ rc = 4;
+ return rc;
+ }
+
+
+
+ Int_t ndig, k;
+ gAlice->ResetDigits();
+ gAlice->TreeS()->GetEvent(ievent);
+ TClonesArray * TOFdigits = tof->SDigits();
+
+ ndig=TOFdigits->GetEntries();
+
+ cout << "<AliTOFanalyzeSDigits> found " << ndig
+ << " TOF sdigits for event " << ievent << endl;
+
+ for (k=0; k<ndig; k++) {
+ tofsdigit= (AliTOFSDigit*) TOFdigits->UncheckedAt(k);
+ Float_t firstTDC=tofsdigit->GetTdc(0);
+ Float_t firstADC=tofsdigit->GetAdc(0);
+ htdc->Fill(firstTDC);
+ hadc->Fill(firstADC);
+ // TOF sdigit volumes
+ Int_t sector = tofsdigit->GetSector(); // range [1-18]
+ Int_t plate = tofsdigit->GetPlate(); // range [1- 5]
+ Int_t strip = tofsdigit->GetStrip(); // range [1-20]
+ Int_t padz = tofsdigit->GetPadz(); // range [1- 2]
+ Int_t padx = tofsdigit->GetPadx(); // range [1-48]
+ // it is QA, then I perform QA!
+ Bool_t isSDigitBad = (sector<1 || sector>18 || plate<1 || plate >5 || padz<1 || padz>2 || padx<1 || padx>48);
+
+ if (isSDigitBad) {
+ cout << "<AliTOFanalyzeHits> strange hit found" << endl;
+ rc = 3;
+ return rc;
+ }
+
+ // filling sdigit volume histos
+ hsector->Fill(sector);
+ hplate->Fill(plate);
+ hstrip->Fill(strip);
+ hpadx->Fill(padx);
+ hpadz->Fill(padz);
+ h2tdcVSadc->Fill(firstTDC,firstADC);
+
+ //cout << "firstTDC " << firstTDC << " firstADC " << firstADC << endl;
+ }
+
+ }
+
+ TFile *fout = new TFile("TOF_sdigitsQA.root","RECREATE");
+ htdc->Write();
+ hadc->Write();
+ h2tdcVSadc->Write();
+ hsector->Write();
+ hplate->Write();
+ hstrip->Write();
+ hpadz->Write();
+ hpadx->Write();
+ fout->Close();
+
+
+ return rc;
+
+}
+
--- /dev/null
+void AliTOFhits2sdigits(TString fileNameHits, Int_t firstEvent=0,Int_t nEvents=1)
+{
+
+ /////////////////////////////////////////////////////////////////////////
+ //
+ // Creates TOF summable digits from the hit information.
+ //
+ // Report problems to pierella@bo.infn.it
+ //
+ // Use case:
+ // start root
+ // // load the macro
+ // root[0] .L AliTOFhits2sdigits.C
+ // root[1] AliTOFhits2sdigits("galice.root",0,1)
+ /////////////////////////////////////////////////////////////////////////
+
+ // Dynamically link some shared libs
+ if (gClassTable->GetID("AliRun") < 0) {
+ gROOT->LoadMacro("loadlibs.C");
+ loadlibs();
+ cout << "Loaded shared libraries" << endl;
+ }
+
+
+ // Create the TOF sdigitzer and sdigitize by default the first event
+ // (in fact by default Int_t firstEvent=0,Int_t nEvents=1)
+ AliTOFSDigitizer *sdigitizer = new AliTOFSDigitizer(fileNameHits.Data(),fileNameHits.Data(),firstEvent,nEvents); // it is the same nevents numbering
+ // scheme used by STEER/AliHits2SDigits.C
+
+ // Activate this line if you want to print the parameters
+ // used in sdigitization
+ // sdigitizer->PrintParameters();
+
+ // performs sdigitization of the above events with "all" verbose option
+ // "tim" option is also available for benchmarking only
+ sdigitizer->Exec("all");
+
+ // N.B.: in order to maintain the functionality to sdigitize
+ // all events in current file add a second option
+ // sdigitizer->Exec("all","all");
+ // the second "all" option overrides the previous settings for
+ // lower and upper bounds for event to sdigitize and allow
+ // the sdigitization for ALL events in fileNameHits
+}