/*
<img src="gif/AliT0Class.gif">
</pre>
<br clear=left>
<font size=+2 color=red>
<p>The responsible person for this module is
<a href="mailto:Alla.Maevskaia@cern.ch">Alla Maevskaia</a>.
</font>
<pre>
*/
//End_Html
#include "TClonesArray.h"
#include "TString.h"
#include "AliLoader.h"
#include "AliLog.h"
#include "AliLog.h"
#include "AliMC.h"
#include "AliRun.h"
#include "AliT0.h"
#include "AliT0Digitizer.h"
#include "AliT0RawData.h"
#include "AliT0RecPoint.h"
#include "AliT0digit.h"
#include "AliT0hit.h"
ClassImp(AliT0)
AliT0::AliT0()
: AliDetector(), fIdSens(0), fDigits(NULL), fRecPoints(NULL)
{
fIshunt = 1;
fHits = 0;
fDigits = 0;
fRecPoints = 0;
}
AliT0::AliT0(const char *name, const char *title)
: AliDetector(name,title), fIdSens(0), fDigits(new AliT0digit()), fRecPoints(new AliT0RecPoint())
{
fHits = new TClonesArray("AliT0hit", 405);
gAlice->GetMCApp()->AddHitList(fHits);
fIshunt = 1;
}
AliT0::~AliT0() {
if (fHits) {
fHits->Delete();
delete fHits;
}
}
void AliT0::AddHit(Int_t track, Int_t *vol, Float_t *hits)
{
TClonesArray &lhits = *fHits;
new(lhits[fNhits++]) AliT0hit(fIshunt,track,vol,hits);
}
void AliT0::AddDigit(Int_t besttimeright, Int_t besttimeleft, Int_t meantime,
Int_t timediff, Int_t sumMult, Int_t refpoint,
TArrayI *timeCFD, TArrayI *qt0, TArrayI *timeLED, TArrayI *qt1)
{
if (!fDigits) {
fDigits = new AliT0digit();
}
fDigits-> SetTimeBestA(besttimeright);
fDigits->SetTimeBestC(besttimeleft);
fDigits-> SetMeanTime(meantime);
fDigits-> SetDiffTime(timediff);
fDigits-> SetSumMult(sumMult);
fDigits->SetTimeCFD(*timeCFD);
fDigits->SetTimeLED(*timeLED);
fDigits->SetQT0(*qt0);
fDigits->SetQT1(*qt1);
fDigits->SetRefPoint(refpoint);
}
void AliT0::Init()
{
Int_t i;
if(AliLog::GetGlobalDebugLevel()>0) {
printf("\n%s: ",ClassName());
for(i=0;i<35;i++) printf("*");
printf(" T0_INIT ");
for(i=0;i<35;i++) printf("*");
printf("\n%s: ",ClassName());
for(i=0;i<80;i++) printf("*");
printf("\n");
}
}
void AliT0::MakeBranch(Option_t* option)
{
TString branchname = Form("%s", GetName());
const char *cH = strstr(option,"H");
const char *cD = strstr(option,"D");
const char *cR = strstr(option,"R");
const char *cS = strstr(option,"S");
if (cH && fLoader->TreeH())
{
if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
AliDetector::MakeBranch(option);
}
if (cD && fLoader->TreeD())
{
if (fDigits == 0x0) fDigits = new AliT0digit();
fLoader->TreeD()->Branch(branchname.Data(),"AliT0digit",&fDigits);
}
if (cR && fLoader->TreeR())
{
if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint();
MakeBranchInTree(fLoader->TreeR(), branchname, &fRecPoints);
}
if (cS && fLoader->TreeS())
{
if (fDigits == 0x0) fDigits = new AliT0digit();
fLoader->TreeS()->Branch(branchname,"AliT0digit",&fDigits);
}
}
void AliT0::ResetHits()
{
AliDetector::ResetHits();
}
void AliT0::ResetDigits()
{
if (fDigits) fDigits->Clear();
}
void AliT0::SetTreeAddress()
{
TTree *treeH = fLoader->TreeH();
if (treeH)
{
if (fHits == 0x0) fHits = new TClonesArray("AliT0hit", 405);
}
AliDetector::SetTreeAddress();
TTree *treeD = fLoader->TreeD();
if (treeD) {
if (fDigits == 0x0) fDigits = new AliT0digit();
TBranch* branch = treeD->GetBranch ("T0");
if (branch) branch->SetAddress(&fDigits);
}
TTree *treeR = fLoader->TreeR();
if (treeR) {
if (fRecPoints == 0x0) fRecPoints = new AliT0RecPoint() ;
TBranch* branch = treeR->GetBranch ("T0");
if (branch) branch->SetAddress(&fRecPoints);
}
TTree *treeS = fLoader->TreeS();
if (treeS) {
if (fDigits == 0x0) fDigits = new AliT0digit();
TBranch* branch = treeS->GetBranch ("T0");
if (branch) branch->SetAddress(&fDigits);
}
}
void AliT0::MakeBranchInTreeD(TTree *treeD, const char *file)
{
const Int_t kBufferSize = 4000;
TString branchname = Form("%s", GetName());
if(treeD)
{
MakeBranchInTree(treeD, branchname.Data(),&fDigits, kBufferSize, file);
}
}
AliDigitizer* AliT0::CreateDigitizer(AliDigitizationInput* digInput) const
{
return new AliT0Digitizer(digInput);
}
void AliT0::Digits2Raw()
{
fLoader ->LoadDigits("read");
TTree* treeD = fLoader->TreeD();
if (!treeD) {
AliError("no digits tree");
return;
}
if (fDigits == 0x0) fDigits = new AliT0digit();
TBranch *branch = treeD->GetBranch("T0");
if (branch) {
branch->SetAddress(&fDigits);
}else{
AliError("Branch T0 DIGIT not found");
exit(111);
}
AliT0RawData rawWriter;
rawWriter.SetVerbose(0);
AliDebug(2,Form(" Formatting raw data for T0 "));
branch->GetEntry(0);
rawWriter.RawDataT0(fDigits);
fLoader->UnloadDigits();
}
void AliT0::Raw2Digits(AliRawReader *rawReader,TTree* digitsTree)
{
AliT0RawReader myrawreader(rawReader);
if (!myrawreader.Next())
AliDebug(1,Form(" no raw data found!! %i", myrawreader.Next()));
Int_t allData[110][5];
for (Int_t i=0; i<110; i++) {
allData[i][0]=myrawreader.GetData(i,0);
}
fDigits = new AliT0digit();
digitsTree->Branch("T0","AliT0digit",&fDigits);
TArrayI *timeLED = new TArrayI(24);
TArrayI * timeCFD = new TArrayI(24);
TArrayI *chargeQT0 = new TArrayI(24);
TArrayI *chargeQT1 = new TArrayI(24);
for (Int_t in=0; in<24; in++)
{
timeLED->AddAt(allData[in+1][0],in);
timeCFD->AddAt(allData[in+25][0],in);
chargeQT0->AddAt(allData[in+55][0],in);
chargeQT1->AddAt(allData[in+79][0],in);
AliDebug(2, Form(" readed Raw %i %i %i %i %i", in, timeLED->At(in),timeCFD->At(in),chargeQT0->At(in),chargeQT1->At(in)));
}
fDigits->SetTimeCFD(*timeCFD);
fDigits->SetQT0(*chargeQT1);
fDigits->SetTimeLED(*timeLED);
fDigits->SetQT1(*chargeQT1);
fDigits->SetMeanTime(allData[49][0]);
fDigits->SetDiffTime(allData[50][0]);
fDigits->SetTimeBestA(allData[51][0]);
fDigits->SetTimeBestC(allData[52][0]);
digitsTree->Fill();
fDigits->Write();
delete timeCFD ;
delete chargeQT0;
delete timeLED ;
delete chargeQT1;
}