Add TPC preprocessor (Haavard, Marian)
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDDigitizer.cxx
CommitLineData
d3da6dc4 1/**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
94b1fbfa 15//
16//
17//
18//
d3da6dc4 19#include "AliHMPIDDigitizer.h"
94b1fbfa 20#include "AliHMPIDDigit.h"
d3da6dc4 21#include "AliHMPID.h"
d3da6dc4 22#include <AliRunLoader.h>
23#include "AliRunDigitizer.h"
24#include <AliLoader.h>
25#include <AliLog.h>
26
27
28ClassImp(AliHMPIDDigitizer)
29
94b1fbfa 30Bool_t AliHMPIDDigitizer::fgDoNoise=kFALSE;
d3da6dc4 31//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32void AliHMPIDDigitizer::Exec(Option_t*)
33{
34// This methode is responsible for merging sdigits to a list of digits
35//Disintegration leeds to the fact that one hit affects several neighbouring pads, which means that the same pad might be affected by few hits.
36 AliDebug(1,Form("Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr()));
37//First we read all sdigits from all inputs
38 AliRunLoader *pInRunLoader=0;//in and out Run loaders
39 AliLoader *pInRichLoader=0;//in and out HMPID loaders
40 TClonesArray sdigs("AliHMPIDDigit");//tmp storage for sdigits sum up from all input files
41 Int_t total=0;
42 for(Int_t inFileN=0;inFileN<fManager->GetNinputs();inFileN++){//files loop
43 pInRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN)); //get run loader from current input
44 pInRichLoader = pInRunLoader->GetLoader("HMPIDLoader"); if(pInRichLoader==0) continue; //no HMPID in this input, check the next input
45 if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
46 AliHMPID* pInRich=(AliHMPID*)pInRunLoader->GetAliRun()->GetDetector("HMPID"); //take HMPID from current input
47 pInRichLoader->LoadSDigits(); pInRichLoader->TreeS()->GetEntry(0); //take list of HMPID sdigits from current input
48 AliDebug(1,Form("input %i has %i sdigits",inFileN,pInRich->SdiLst()->GetEntries()));
49 for(Int_t i=0;i<pInRich->SdiLst()->GetEntries();i++){ //collect sdigits from current input
50 AliHMPIDDigit *pSDig=(AliHMPIDDigit*)pInRich->SdiLst()->At(i);
51 pSDig->AddTidOffset(fManager->GetMask(inFileN)); //apply TID shift since all inputs count tracks independently starting from 0
52 new(sdigs[total++]) AliHMPIDDigit(*pSDig);
53 }
54 pInRichLoader->UnloadSDigits(); pInRich->SdiReset(); //close current input and reset
55 }//files loop
56
57 //PH if(sdigs.GetEntries()==0) return; //no sdigits collected, nothing to convert
58
59 AliRunLoader *pOutRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); //open output stream (only 1 possible)
60 AliLoader *pOutRichLoader = pOutRunLoader->GetLoader("HMPIDLoader"); //take output HMPID loader
61 AliHMPID *pOutRich = (AliHMPID*)pOutRunLoader->GetAliRun()->GetDetector("HMPID"); //take output HMPID
62 pOutRichLoader->MakeTree("D"); pOutRich->MakeBranch("D"); //create TreeD in output stream
63
64 Sdi2Dig(&sdigs,pOutRich->DigLst());
65
66 pOutRichLoader->TreeD()->Fill(); //fill the output tree with the list of digits
67 pOutRichLoader->WriteDigits("OVERWRITE"); //serialize them to file
68
69 sdigs.Clear(); //remove all tmp sdigits
70 pOutRichLoader->UnloadDigits(); pOutRich->DigReset();
71}//Exec()
72//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73void AliHMPIDDigitizer::Sdi2Dig(TClonesArray *pSdiLst,TObjArray *pDigLst)
74{
75// Converts list of sdigits to 7 lists of digits, one per each chamber
76// Arguments: pSDigLst - list of all sdigits
77// pDigLst - list of 7 lists of digits
78// Returns: none
79
80 TClonesArray *pLst[7]; Int_t iCnt[7];
81
82 for(Int_t i=0;i<7;i++){
83 pLst[i]=(TClonesArray*)(*pDigLst)[i];
3c6274c1 84 iCnt[i]=0; if(pLst[i]->GetEntries()!=0) AliErrorClass("Some of digits lists is not empty"); //in principle those lists should be empty
d3da6dc4 85 }
c5c19d6a 86
87 // make noise array
88 Float_t arrNoise[7][6][80][48];
94b1fbfa 89 if(fgDoNoise) {
c5c19d6a 90 for (Int_t iCh=AliHMPIDDigit::kMinCh;iCh<=AliHMPIDDigit::kMaxCh;iCh++)
91 for (Int_t iPc=AliHMPIDDigit::kMinPc;iPc<=AliHMPIDDigit::kMaxPc;iPc++)
92 for(Int_t iPx=AliHMPIDDigit::kMinPx;iPx<=AliHMPIDDigit::kMaxPx;iPx++)
93 for(Int_t iPy=AliHMPIDDigit::kMinPy;iPy<=AliHMPIDDigit::kMaxPy;iPy++) arrNoise[iCh][iPc][iPx][iPy] = gRandom->Gaus(0,1);
94 }
d3da6dc4 95
96 pSdiLst->Sort();
97
98 Int_t iPad=-1,iCh=-1,iNdigPad=-1,aTids[3]={-1,-1,-1}; Float_t q=-1;
99 for(Int_t i=0;i<pSdiLst->GetEntries();i++){ //sdigits loop (sorted)
100 AliHMPIDDigit *pSdig=(AliHMPIDDigit*)pSdiLst->At(i); //take current sdigit
101 if(pSdig->Pad()==iPad){ //if the same pad
102 q+=pSdig->Q(); //sum up charge
103 iNdigPad++; if(iNdigPad<=3) aTids[iNdigPad-1]=pSdig->GetTrack(0); //collect TID
104 continue;
105 }
106 if(i!=0 && AliHMPIDDigit::IsOverTh(q)) new((*pLst[iCh])[iCnt[iCh]++]) AliHMPIDDigit(iPad,(Int_t)q,aTids); //do not create digit for the very first sdigit
107 iPad=pSdig->Pad(); iCh=AliHMPIDDigit::A2C(iPad); //new sdigit comes, reset collectors
108 iNdigPad=1;
109 aTids[0]=pSdig->GetTrack(0);aTids[1]=aTids[2]=-1;
c5c19d6a 110 q=pSdig->Q();
94b1fbfa 111 if(fgDoNoise) q+=arrNoise[iCh][pSdig->Pc()][pSdig->PadPcX()][pSdig->PadPcY()];
c5c19d6a 112 arrNoise[iCh][pSdig->Pc()][pSdig->PadPcX()][pSdig->PadPcY()]=0;
d3da6dc4 113 }//sdigits loop (sorted)
114
3c6274c1 115 if(AliHMPIDDigit::IsOverTh(q)) new((*pLst[iCh])[iCnt[iCh]++]) AliHMPIDDigit(iPad,(Int_t)q,aTids); //add the last one, in case of empty sdigits list q=-1
c5c19d6a 116// add noise pad above threshold with no signal merged...if any
94b1fbfa 117 if(!fgDoNoise) return;
c5c19d6a 118 aTids[0]=aTids[1]=aTids[2]=-1;
119 for (Int_t iCh=AliHMPIDDigit::kMinCh;iCh<=AliHMPIDDigit::kMaxCh;iCh++)
120 for (Int_t iPc=AliHMPIDDigit::kMinPc;iPc<=AliHMPIDDigit::kMaxPc;iPc++)
121 for(Int_t iPx=AliHMPIDDigit::kMinPx;iPx<=AliHMPIDDigit::kMaxPx;iPx++)
122 for(Int_t iPy=AliHMPIDDigit::kMinPy;iPy<=AliHMPIDDigit::kMaxPy;iPy++) {
123 Float_t q = arrNoise[iCh][iPc][iPx][iPy];
124 if(AliHMPIDDigit::IsOverTh(q)) new((*pLst[iCh])[iCnt[iCh]++]) AliHMPIDDigit(AliHMPIDDigit::Abs(iCh,iPc,iPx,iPy),(Int_t)q,aTids);
125 }
126
d3da6dc4 127}//Sdi2Dig()
128//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++