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 //Piotr.Skowronski@cern.ch :
19 //Corrections applied in order to compile (only) with new I/O and folder structure
20 //To be implemented correctly by responsible
22 #include <Riostream.h>
25 #include <TObjArray.h>
27 #include <TDirectory.h>
28 #include <TParticle.h>
30 #include "AliRunLoader.h"
31 #include "AliLoader.h"
33 #include "AliRICHDigitizer.h"
34 #include "AliRICHChamber.h"
35 #include "AliHitMap.h"
36 #include "AliRICHHitMapA1.h"
38 #include "AliRICHHit.h"
39 #include "AliRICHSDigit.h"
40 #include "AliRICHDigit.h"
41 #include "AliRICHTransientDigit.h"
44 #include "AliRunDigitizer.h"
46 ClassImp(AliRICHDigitizer)
48 //___________________________________________
49 AliRICHDigitizer::AliRICHDigitizer()
51 // Default constructor - don't use it
58 ////////////////////////////////////////////////////////////////////////
59 AliRICHDigitizer::AliRICHDigitizer(AliRunDigitizer* manager)
60 :AliDigitizer(manager)
62 // ctor which should be used
69 cerr<<"AliRICHDigitizer::AliRICHDigitizer"
70 <<"(AliRunDigitizer* manager) was processed"<<endl;
73 ////////////////////////////////////////////////////////////////////////
74 AliRICHDigitizer::~AliRICHDigitizer()
85 for (Int_t i=0; i<kNCH; i++ )
94 //------------------------------------------------------------------------
95 Bool_t AliRICHDigitizer::Exists(const AliRICHSDigit *padhit)
97 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
100 //------------------------------------------------------------------------
101 void AliRICHDigitizer::Update(AliRICHSDigit *padhit)
103 AliRICHTransientDigit *pdigit =
104 static_cast<AliRICHTransientDigit*>(
105 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
109 Int_t iqpad = Int_t(padhit->QPad()); // charge per pad
110 pdigit->AddSignal(iqpad);
111 pdigit->AddPhysicsSignal(iqpad);
113 // update list of tracks
116 track = fTrack+fMask;
122 pdigit->UpdateTrackList(track,charge);
125 //------------------------------------------------------------------------
126 void AliRICHDigitizer::CreateNew(AliRICHSDigit *padhit)
128 fTDList->AddAtAndExpand(
129 new AliRICHTransientDigit(fNch,fDigits),fCounter);
130 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
132 AliRICHTransientDigit* pdigit =
133 static_cast<AliRICHTransientDigit*>(fTDList->Last());
138 charge = padhit->QPad();
143 pdigit->AddToTrackList(track,charge);
148 ////////////////////////////////////////////////////////////////////////
149 Bool_t AliRICHDigitizer::Init()
152 fHits = new TClonesArray("AliRICHHit",1000);
153 fSDigits = new TClonesArray("AliRICHSDigit",1000);
157 ////////////////////////////////////////////////////////////////////////
158 //void AliRICHDigitizer::Digitise(Int_t nev, Int_t flag)
159 void AliRICHDigitizer::Exec(Option_t* option)
161 TString optionString = option;
162 if (optionString.Data() == "deb") {
163 cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl;
167 AliRICHChamber* iChamber;
168 AliSegmentation* segmentation;
170 AliRunLoader *inRL, *outRL;//in and out Run Loaders
171 AliLoader *ingime, *outgime;// in and out ITSLoaders
173 outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
174 outgime = outRL->GetLoader("RICHLoader");
176 fTDList = new TObjArray;
179 AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH");
181 if (outgime->TreeD() == 0x0) outgime->MakeTree("D");
183 pRICH->MakeBranchInTreeD(outgime->TreeD());
184 fHitMap= new AliHitMap* [kNCH];
186 for (Int_t i =0; i<kNCH; i++) {
187 iChamber= &(pRICH->Chamber(i));
188 segmentation=iChamber->GetSegmentationModel(1);
189 fHitMap[i] = new AliRICHHitMapA1(segmentation, fTDList);
192 // Loop over files to digitize
195 for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); inputFile++)
197 inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
198 ingime = inRL->GetLoader("RICHLoader");
200 // Connect RICH branches
202 if (inputFile > 0 ) fSignal = kFALSE;
203 TBranch *branchHits = 0;
204 TBranch *branchSDigits = 0;
206 ingime->LoadHits("READ");
207 TTree *treeH = ingime->TreeH();
209 cerr<<" inputFile "<<inputFile<<endl;
210 cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
212 if (treeH && fHits) {
213 branchHits = treeH->GetBranch("RICH");
217 branchHits->SetAddress(&fHits);
220 Error("Exec","branch RICH was not found");
222 if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl;
224 if (treeH && fSDigits) {
225 branchSDigits = treeH->GetBranch("RICHSDigits");
227 branchSDigits->SetAddress(&fSDigits);
229 Error("exec","branch RICHSDigits was not found");
231 if (GetDebug()>2) cerr<<" branchSDigits = "<<branchSDigits<<endl;
238 Int_t ntracks =(Int_t) treeH->GetEntries();
239 for (fTrack=0; fTrack<ntracks; fTrack++) {
242 branchHits->GetEntry(fTrack);
243 branchSDigits->GetEntry(fTrack);
248 for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) {
249 AliRICHHit* mHit = static_cast<AliRICHHit*>(fHits->At(i));
250 fNch = mHit->Chamber()-1; // chamber number
252 cerr<<"AliRICHDigitizer: chamber nr. fNch out of range: "<<fNch<<endl;
253 cerr<<" track: "<<fTrack<<endl;
256 iChamber = &(pRICH->Chamber(fNch));
259 // Loop over pad hits
260 for (AliRICHSDigit* mPad=
261 (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigits);
263 mPad=(AliRICHSDigit*)pRICH->NextPad(fSDigits))
265 Int_t iqpad = mPad->QPad(); // charge per pad
266 fDigits[0]=mPad->PadX();
267 fDigits[1]=mPad->PadY();
270 fDigits[4]=mPad->HitNumber();
274 // build the list of fired pads and update the info
280 } //end loop over clusters
284 if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
286 Int_t tracks[kMAXTRACKSPERRICHDIGIT];
287 Int_t charges[kMAXTRACKSPERRICHDIGIT];
288 Int_t nentries=fTDList->GetEntriesFast();
290 for (Int_t nent=0;nent<nentries;nent++) {
291 AliRICHTransientDigit *transDigit=(AliRICHTransientDigit*)fTDList->At(nent);
292 if (transDigit==0) continue;
293 Int_t ich=transDigit->GetChamber();
294 Int_t q=transDigit->Signal();
295 iChamber=&(pRICH->Chamber(ich));
296 AliRICHResponse * response=iChamber->GetResponseModel();
297 Int_t adcmax= (Int_t) response->MaxAdc();
300 // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2)
301 //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY()));
304 // Int_t pedestal = iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY());
308 //printf("Pedestal:%d\n",pedestal);
310 Float_t treshold = (pedestal + 4*2.2);
312 Float_t meanNoise = gRandom->Gaus(2.2, 0.3);
313 Float_t noise = gRandom->Gaus(0, meanNoise);
314 q+=(Int_t)(noise + pedestal);
316 // magic number to be parametrised !!!
323 if ( q >= adcmax) q=adcmax;
324 fDigits[0]=transDigit->PadX();
325 fDigits[1]=transDigit->PadY();
327 fDigits[3]=transDigit->Physics();
328 fDigits[4]=transDigit->Hit();
330 Int_t nptracks = transDigit->GetNTracks();
332 // this was changed to accomodate the real number of tracks
333 if (nptracks > kMAXTRACKSPERRICHDIGIT) {
334 printf("Attention - tracks > 10 %d\n",nptracks);
335 nptracks=kMAXTRACKSPERRICHDIGIT;
338 printf("Attention - tracks > 2 %d \n",nptracks);
340 for (Int_t tr=0;tr<nptracks;tr++) {
341 tracks[tr]=transDigit->GetTrack(tr);
342 charges[tr]=transDigit->GetCharge(tr);
343 //printf("%f \n",charges[tr]);
344 } //end loop over list of tracks for one pad
345 if (nptracks < kMAXTRACKSPERRICHDIGIT ) {
346 for (Int_t t=nptracks; t<kMAXTRACKSPERRICHDIGIT; t++) {
353 //fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]);
356 pRICH->AddDigits(ich,tracks,charges,fDigits);
358 outgime->TreeD()->Fill();
360 //pRICH->ResetDigits();
361 fTDList->Delete(); // or fTDList->Clear(); ???
362 for(Int_t ii=0;ii<kNCH;++ii) {
369 TClonesArray *richDigits;
370 for (Int_t k=0;k<kNCH;k++) {
371 richDigits = pRICH->DigitsAddress(k);
372 Int_t ndigit=richDigits->GetEntriesFast();
373 printf ("Chamber %d digits %d \n",k,ndigit);
375 pRICH->ResetDigits(); /// ??? should it be here???
377 outgime->WriteDigits("OVERWRITE");
382 if (fHits) fHits->Delete();
383 if (fSDigits) fSDigits->Delete();