1 /**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 #include <AliRunLoader.h>
22 #include "AliRunDigitizer.h"
23 #include <AliLoader.h>
25 #include <AliCDBEntry.h>
26 #include <AliCDBManager.h>
27 #include "AliHMPIDDigitizer.h"
28 #include "AliHMPIDReconstructor.h"
29 #include "AliHMPIDDigit.h"
31 #include "AliHMPIDParam.h"
35 #include <TObjArray.h>
37 ClassImp(AliHMPIDDigitizer)
39 Bool_t AliHMPIDDigitizer::fgDoNoise=kTRUE;
40 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 void AliHMPIDDigitizer::Exec(Option_t*)
43 // This methode is responsible for merging sdigits to a list of digits
44 //Disintegration leeds to the fact that one hit affects several neighbouring pads, which means that the same pad might be affected by few hits.
45 AliDebug(1,Form("Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr()));
46 //First we read all sdigits from all inputs
47 AliRunLoader *pInRunLoader=0;//in and out Run loaders
48 AliLoader *pInRichLoader=0;//in and out HMPID loaders
49 static TClonesArray sdigs("AliHMPIDDigit");//tmp storage for sdigits sum up from all input files
51 for(Int_t inFileN=0;inFileN<fManager->GetNinputs();inFileN++){//files loop
52 pInRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN)); //get run loader from current input
53 pInRichLoader = pInRunLoader->GetLoader("HMPIDLoader"); if(pInRichLoader==0) continue; //no HMPID in this input, check the next input
54 if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
55 AliHMPID* pInRich=(AliHMPID*)pInRunLoader->GetAliRun()->GetDetector("HMPID"); //take HMPID from current input
56 pInRichLoader->LoadSDigits(); pInRichLoader->TreeS()->GetEntry(0); //take list of HMPID sdigits from current input
57 AliDebug(1,Form("input %i has %i sdigits",inFileN,pInRich->SdiLst()->GetEntries()));
58 for(Int_t i=0;i<pInRich->SdiLst()->GetEntries();i++){ //collect sdigits from current input
59 AliHMPIDDigit *pSDig=(AliHMPIDDigit*)pInRich->SdiLst()->At(i);
60 pSDig->AddTidOffset(fManager->GetMask(inFileN)); //apply TID shift since all inputs count tracks independently starting from 0
61 new(sdigs[total++]) AliHMPIDDigit(*pSDig);
63 pInRichLoader->UnloadSDigits(); pInRich->SdiReset(); //close current input and reset
66 //PH if(sdigs.GetEntries()==0) return; //no sdigits collected, nothing to convert
68 AliRunLoader *pOutRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); //open output stream (only 1 possible)
69 AliLoader *pOutRichLoader = pOutRunLoader->GetLoader("HMPIDLoader"); //take output HMPID loader
70 AliRun *pArun = pOutRunLoader->GetAliRun();
71 AliHMPID *pOutRich = (AliHMPID*)pArun->GetDetector("HMPID"); //take output HMPID
72 pOutRichLoader->MakeTree("D"); pOutRich->MakeBranch("D"); //create TreeD in output stream
74 Sdi2Dig(&sdigs,pOutRich->DigLst());
76 pOutRichLoader->TreeD()->Fill(); //fill the output tree with the list of digits
77 pOutRichLoader->WriteDigits("OVERWRITE"); //serialize them to file
79 sdigs.Clear(); //remove all tmp sdigits
80 pOutRichLoader->UnloadDigits(); pOutRich->DigReset();
82 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
83 void AliHMPIDDigitizer::Sdi2Dig(TClonesArray *pSdiLst,TObjArray *pDigLst)
85 // Converts list of sdigits to 7 lists of digits, one per each chamber
86 // Arguments: pSDigLst - list of all sdigits
87 // pDigLst - list of 7 lists of digits
90 TClonesArray *pLst[7]; Int_t iCnt[7];
92 for(Int_t i=0;i<7;i++){
93 pLst[i]=(TClonesArray*)(*pDigLst)[i];
94 iCnt[i]=0; if(pLst[i]->GetEntries()!=0) AliErrorClass("Some of digits lists is not empty"); //in principle those lists should be empty
99 AliCDBEntry *pDaqSigEnt = AliCDBManager::Instance()->Get("HMPID/Calib/DaqSig"); //contains TObjArray of TObjArray 14 TMatrixF sigmas values for pads
101 TObjArray *pDaqSig = (TObjArray*)pDaqSigEnt->GetObject();
102 for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){ //chambers loop
103 pM[iCh] = (TMatrixF*)pDaqSig->At(iCh);
107 for (Int_t iCh=0; iCh<7; iCh++)
108 for (Int_t i=0; i<160; i++)
109 for (Int_t j=0; j<144; j++)
110 (*pM[iCh])(i,j) = 1.0;
114 Float_t arrNoise[7][6][80][48];
116 for (Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++)
117 for (Int_t iPc=AliHMPIDParam::kMinPc;iPc<=AliHMPIDParam::kMaxPc;iPc++)
118 for(Int_t iPx=AliHMPIDParam::kMinPx;iPx<=AliHMPIDParam::kMaxPx;iPx++)
119 for(Int_t iPy=AliHMPIDParam::kMinPy;iPy<=AliHMPIDParam::kMaxPy;iPy++){
120 Int_t padX = (iPc%2)*AliHMPIDParam::kPadPcX+iPx;
121 Int_t padY = (iPc/2)*AliHMPIDParam::kPadPcY+iPy;
122 arrNoise[iCh][iPc][iPx][iPy] = gRandom->Gaus(0,(*pM[iCh])(padX,padY));
128 Int_t iPad=-1,iCh=-1,iNdigPad=-1,aTids[3]={-1,-1,-1}; Float_t q=-1;
129 for(Int_t i=0;i<pSdiLst->GetEntries();i++){ //sdigits loop (sorted)
130 AliHMPIDDigit *pSdig=(AliHMPIDDigit*)pSdiLst->At(i); //take current sdigit
131 if(pSdig->Pad()==iPad){ //if the same pad
132 q+=pSdig->Q(); //sum up charge
133 iNdigPad++; if(iNdigPad<=3) aTids[iNdigPad-1]=pSdig->GetTrack(0); //collect TID
136 if(i!=0 && iCh>=AliHMPIDParam::kMinCh && iCh<=AliHMPIDParam::kMaxCh){
137 AliHMPIDParam::Instance()->SetThreshold(TMath::Nint(((*pM[iCh])(pSdig->PadChX(),pSdig->PadChY()))*AliHMPIDParam::Nsig()));
138 if(AliHMPIDParam::IsOverTh(q)) new((*pLst[iCh])[iCnt[iCh]++]) AliHMPIDDigit(iPad,(Int_t)q,aTids);} //do not create digit for the very first sdigit
140 iPad=pSdig->Pad(); iCh=AliHMPIDParam::A2C(iPad); //new sdigit comes, reset collectors
142 aTids[0]=pSdig->GetTrack(0);aTids[1]=aTids[2]=-1;
144 if(fgDoNoise) q+=arrNoise[iCh][pSdig->Pc()][pSdig->PadPcX()][pSdig->PadPcY()];
145 arrNoise[iCh][pSdig->Pc()][pSdig->PadPcX()][pSdig->PadPcY()]=0;
146 }//sdigits loop (sorted)
148 if(iCh>=AliHMPIDParam::kMinCh && iCh<=AliHMPIDParam::kMaxCh){
149 Int_t pc = AliHMPIDParam::A2P(iPad);
150 Int_t padX = (pc%2)*AliHMPIDParam::kPadPcX+AliHMPIDParam::A2X(iPad);
151 Int_t padY = (pc/2)*AliHMPIDParam::kPadPcY+AliHMPIDParam::A2Y(iPad);
152 AliHMPIDParam::Instance()->SetThreshold(TMath::Nint(((*pM[iCh])(padX,padY))*AliHMPIDParam::Nsig()));
153 if(AliHMPIDParam::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
155 // add noise pad above threshold with no signal merged...if any
156 if(!fgDoNoise) return;
158 aTids[0]=aTids[1]=aTids[2]=-1;
159 for (Int_t iChCurr=AliHMPIDParam::kMinCh;iChCurr<=AliHMPIDParam::kMaxCh;iChCurr++){
160 for (Int_t iPc=AliHMPIDParam::kMinPc;iPc<=AliHMPIDParam::kMaxPc;iPc++)
161 for(Int_t iPx=AliHMPIDParam::kMinPx;iPx<=AliHMPIDParam::kMaxPx;iPx++)
162 for(Int_t iPy=AliHMPIDParam::kMinPy;iPy<=AliHMPIDParam::kMaxPy;iPy++) {
163 Float_t qNoise = arrNoise[iChCurr][iPc][iPx][iPy];
164 Int_t padX = (iPc%2)*AliHMPIDParam::kPadPcX+iPx;
165 Int_t padY = (iPc/2)*AliHMPIDParam::kPadPcY+iPy;
166 AliHMPIDParam::Instance()->SetThreshold(TMath::Nint(((*pM[iChCurr])(padX,padY))*AliHMPIDParam::Nsig()));
167 if(AliHMPIDParam::IsOverTh(qNoise)) new((*pLst[iChCurr])[iCnt[iChCurr]++]) AliHMPIDDigit(AliHMPIDParam::Abs(iChCurr,iPc,iPx,iPy),(Int_t)qNoise,aTids);
171 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++