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 **************************************************************************/
18 Revision 1.6 2002/10/14 14:57:32 hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
21 Revision 1.3.6.2 2002/07/24 10:07:52 alibrary
24 Revision 1.3.6.1 2002/06/10 15:12:46 hristov
27 Revision 1.4 2002/05/28 07:53:10 morsch
28 Wrong order of arguments in for-statement corrected.
30 Revision 1.3 2001/12/05 14:53:34 hristov
33 Revision 1.2 2001/11/07 14:50:31 hristov
34 Minor correction of the Log part
36 Revision 1.1 2001/11/02 15:37:26 hristov
37 Digitizer class created. Code cleaning and bug fixes (J.Chudoba)
39 #include <Riostream.h>
42 #include <TObjArray.h>
44 #include <TDirectory.h>
45 #include <TParticle.h>
47 #include "AliRICHDigitizer.h"
48 #include "AliRICHChamber.h"
49 #include "AliHitMap.h"
50 #include "AliRICHHitMapA1.h"
52 #include "AliRICHHit.h"
53 #include "AliRICHSDigit.h"
54 #include "AliRICHDigit.h"
55 #include "AliRICHTransientDigit.h"
58 #include "AliRunDigitizer.h"
60 ClassImp(AliRICHDigitizer)
62 //___________________________________________
63 AliRICHDigitizer::AliRICHDigitizer()
65 // Default constructor - don't use it
72 ////////////////////////////////////////////////////////////////////////
73 AliRICHDigitizer::AliRICHDigitizer(AliRunDigitizer* manager)
74 :AliDigitizer(manager)
76 // ctor which should be used
83 cerr<<"AliRICHDigitizer::AliRICHDigitizer"
84 <<"(AliRunDigitizer* manager) was processed"<<endl;
87 ////////////////////////////////////////////////////////////////////////
88 AliRICHDigitizer::~AliRICHDigitizer()
99 for (Int_t i=0; i<kNCH; i++ )
108 //------------------------------------------------------------------------
109 Bool_t AliRICHDigitizer::Exists(const AliRICHSDigit *padhit)
111 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
114 //------------------------------------------------------------------------
115 void AliRICHDigitizer::Update(AliRICHSDigit *padhit)
117 AliRICHTransientDigit *pdigit =
118 static_cast<AliRICHTransientDigit*>(
119 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
123 Int_t iqpad = Int_t(padhit->QPad()); // charge per pad
124 pdigit->AddSignal(iqpad);
125 pdigit->AddPhysicsSignal(iqpad);
127 // update list of tracks
130 track = fTrack+fMask;
136 pdigit->UpdateTrackList(track,charge);
139 //------------------------------------------------------------------------
140 void AliRICHDigitizer::CreateNew(AliRICHSDigit *padhit)
142 fTDList->AddAtAndExpand(
143 new AliRICHTransientDigit(fNch,fDigits),fCounter);
144 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
146 AliRICHTransientDigit* pdigit =
147 static_cast<AliRICHTransientDigit*>(fTDList->Last());
152 charge = padhit->QPad();
157 pdigit->AddToTrackList(track,charge);
162 ////////////////////////////////////////////////////////////////////////
163 Bool_t AliRICHDigitizer::Init()
166 fHits = new TClonesArray("AliRICHHit",1000);
167 fSDigits = new TClonesArray("AliRICHSDigit",1000);
171 ////////////////////////////////////////////////////////////////////////
172 //void AliRICHDigitizer::Digitise(Int_t nev, Int_t flag)
173 void AliRICHDigitizer::Exec(Option_t* option)
175 TString optionString = option;
176 if (optionString.Data() == "deb") {
177 cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl;
181 AliRICHChamber* iChamber;
182 AliSegmentation* segmentation;
184 fTDList = new TObjArray;
186 AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH");
187 pRICH->MakeBranchInTreeD(fManager->GetTreeD());
188 fHitMap= new AliHitMap* [kNCH];
190 for (Int_t i =0; i<kNCH; i++) {
191 iChamber= &(pRICH->Chamber(i));
192 segmentation=iChamber->GetSegmentationModel(1);
193 fHitMap[i] = new AliRICHHitMapA1(segmentation, fTDList);
196 // Loop over files to digitize
199 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
202 // Connect RICH branches
204 if (inputFile > 0 ) fSignal = kFALSE;
205 TBranch *branchHits = 0;
206 TBranch *branchSDigits = 0;
207 TTree *treeH = fManager->GetInputTreeH(inputFile);
209 cerr<<" inputFile "<<inputFile<<endl;
210 cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
212 if (treeH && fHits) {
213 branchHits = treeH->GetBranch("RICH");
216 branchHits->SetAddress(&fHits);
219 Error("Exec","branch RICH was not found");
221 if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl;
223 if (treeH && fSDigits) {
224 branchSDigits = treeH->GetBranch("RICHSDigits");
226 branchSDigits->SetAddress(&fSDigits);
228 Error("exec","branch RICHSDigits was not found");
230 if (GetDebug()>2) cerr<<" branchSDigits = "<<branchSDigits<<endl;
237 Int_t ntracks =(Int_t) treeH->GetEntries();
238 for (fTrack=0; fTrack<ntracks; fTrack++) {
241 branchHits->GetEntry(fTrack);
242 branchSDigits->GetEntry(fTrack);
247 for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) {
248 AliRICHHit* mHit = static_cast<AliRICHHit*>(fHits->At(i));
249 fNch = mHit->Chamber()-1; // chamber number
251 cerr<<"AliRICHDigitizer: chamber nr. fNch out of range: "<<fNch<<endl;
252 cerr<<" track: "<<fTrack<<endl;
255 iChamber = &(pRICH->Chamber(fNch));
258 // Loop over pad hits
259 for (AliRICHSDigit* mPad=
260 (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigits);
262 mPad=(AliRICHSDigit*)pRICH->NextPad(fSDigits))
264 Int_t iqpad = mPad->QPad(); // charge per pad
265 fDigits[0]=mPad->PadX();
266 fDigits[1]=mPad->PadY();
269 fDigits[4]=mPad->HitNumber();
271 // build the list of fired pads and update the info
277 } //end loop over clusters
281 if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
283 Int_t tracks[kMAXTRACKSPERRICHDIGIT];
284 Int_t charges[kMAXTRACKSPERRICHDIGIT];
285 Int_t nentries=fTDList->GetEntriesFast();
287 for (Int_t nent=0;nent<nentries;nent++) {
288 AliRICHTransientDigit *transDigit=(AliRICHTransientDigit*)fTDList->At(nent);
289 if (transDigit==0) continue;
290 Int_t ich=transDigit->GetChamber();
291 Int_t q=transDigit->Signal();
292 iChamber=&(pRICH->Chamber(ich));
293 AliRICHResponse * response=iChamber->GetResponseModel();
294 Int_t adcmax= (Int_t) response->MaxAdc();
297 // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2)
298 //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY()));
301 // Int_t pedestal = iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY());
305 //printf("Pedestal:%d\n",pedestal);
307 Float_t treshold = (pedestal + 4*2.2);
309 Float_t meanNoise = gRandom->Gaus(2.2, 0.3);
310 Float_t noise = gRandom->Gaus(0, meanNoise);
311 q+=(Int_t)(noise + pedestal);
313 // magic number to be parametrised !!!
320 if ( q >= adcmax) q=adcmax;
321 fDigits[0]=transDigit->PadX();
322 fDigits[1]=transDigit->PadY();
324 fDigits[3]=transDigit->Physics();
325 fDigits[4]=transDigit->Hit();
327 Int_t nptracks = transDigit->GetNTracks();
329 // this was changed to accomodate the real number of tracks
330 if (nptracks > kMAXTRACKSPERRICHDIGIT) {
331 printf("Attention - tracks > 10 %d\n",nptracks);
332 nptracks=kMAXTRACKSPERRICHDIGIT;
335 printf("Attention - tracks > 2 %d \n",nptracks);
337 for (Int_t tr=0;tr<nptracks;tr++) {
338 tracks[tr]=transDigit->GetTrack(tr);
339 charges[tr]=transDigit->GetCharge(tr);
340 } //end loop over list of tracks for one pad
341 if (nptracks < kMAXTRACKSPERRICHDIGIT ) {
342 for (Int_t t=nptracks; t<kMAXTRACKSPERRICHDIGIT; t++) {
349 //fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]);
352 pRICH->AddDigits(ich,tracks,charges,fDigits);
354 fManager->GetTreeD()->Fill();
356 pRICH->ResetDigits();
357 fTDList->Delete(); // or fTDList->Clear(); ???
358 for(Int_t ii=0;ii<kNCH;++ii) {
365 TClonesArray *richDigits;
366 for (Int_t k=0;k<kNCH;k++) {
367 richDigits = pRICH->DigitsAddress(k);
368 Int_t ndigit=richDigits->GetEntriesFast();
369 printf ("Chamber %d digits %d \n",k,ndigit);
371 pRICH->ResetDigits(); /// ??? should it be here???
372 fManager->GetTreeD()->Write(0,TObject::kOverwrite);
376 if (fHits) fHits->Delete();
377 if (fSDigits) fSDigits->Delete();