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 "AliRICHSDigit.h"
39 #include "AliRICHDigit.h"
40 #include "AliRICHTransientDigit.h"
43 #include "AliRunDigitizer.h"
45 ClassImp(AliRICHDigitizer)
47 //___________________________________________
48 AliRICHDigitizer::AliRICHDigitizer()
50 // Default constructor - don't use it
57 ////////////////////////////////////////////////////////////////////////
58 AliRICHDigitizer::AliRICHDigitizer(AliRunDigitizer* manager)
59 :AliDigitizer(manager)
61 // ctor which should be used
68 cerr<<"AliRICHDigitizer::AliRICHDigitizer"
69 <<"(AliRunDigitizer* manager) was processed"<<endl;
72 ////////////////////////////////////////////////////////////////////////
73 AliRICHDigitizer::~AliRICHDigitizer()
84 for (Int_t i=0; i<kNCH; i++ )
93 //------------------------------------------------------------------------
94 Bool_t AliRICHDigitizer::Exists(const AliRICHSDigit *padhit)
96 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
99 //------------------------------------------------------------------------
100 void AliRICHDigitizer::Update(AliRICHSDigit *padhit)
102 AliRICHTransientDigit *pdigit =
103 static_cast<AliRICHTransientDigit*>(
104 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
108 Int_t iqpad = Int_t(padhit->QPad()); // charge per pad
109 pdigit->AddSignal(iqpad);
110 pdigit->AddPhysicsSignal(iqpad);
112 // update list of tracks
115 track = fTrack+fMask;
121 pdigit->UpdateTrackList(track,charge);
124 //------------------------------------------------------------------------
125 void AliRICHDigitizer::CreateNew(AliRICHSDigit *padhit)
127 fTDList->AddAtAndExpand(
128 new AliRICHTransientDigit(fNch,fDigits),fCounter);
129 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
131 AliRICHTransientDigit* pdigit =
132 static_cast<AliRICHTransientDigit*>(fTDList->Last());
137 charge = padhit->QPad();
142 pdigit->AddToTrackList(track,charge);
147 ////////////////////////////////////////////////////////////////////////
148 Bool_t AliRICHDigitizer::Init()
151 fHits = new TClonesArray("AliRICHhit",1000);
152 fSDigits = new TClonesArray("AliRICHSDigit",1000);
156 ////////////////////////////////////////////////////////////////////////
157 //void AliRICHDigitizer::Digitise(Int_t nev, Int_t flag)
158 void AliRICHDigitizer::Exec(Option_t* option)
160 TString optionString = option;
161 if (optionString.Data() == "deb") {
162 cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl;
166 AliRICHChamber* iChamber;
167 AliSegmentation* segmentation;
169 AliRunLoader *inRL, *outRL;//in and out Run Loaders
170 AliLoader *ingime, *outgime;// in and out ITSLoaders
172 outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
173 outgime = outRL->GetLoader("RICHLoader");
175 fTDList = new TObjArray;
178 AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH");
180 if (outgime->TreeD() == 0x0) outgime->MakeTree("D");
182 pRICH->MakeBranchInTreeD(outgime->TreeD());
183 fHitMap= new AliHitMap* [kNCH];
185 for (Int_t i =0; i<kNCH; i++) {
186 iChamber= &(pRICH->Chamber(i));
187 segmentation=iChamber->GetSegmentationModel();
188 fHitMap[i] = new AliRICHHitMapA1(segmentation, fTDList);
191 // Loop over files to digitize
194 for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); inputFile++)
196 inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
197 ingime = inRL->GetLoader("RICHLoader");
199 // Connect RICH branches
201 if (inputFile > 0 ) fSignal = kFALSE;
202 TBranch *branchHits = 0;
203 TBranch *branchSDigits = 0;
205 ingime->LoadHits("READ");
206 TTree *treeH = ingime->TreeH();
208 cerr<<" inputFile "<<inputFile<<endl;
209 cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
211 if (treeH && fHits) {
212 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();
273 // build the list of fired pads and update the info
279 } //end loop over clusters
283 if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
285 Int_t tracks[kMAXTRACKSPERRICHDIGIT];
286 Int_t charges[kMAXTRACKSPERRICHDIGIT];
287 Int_t nentries=fTDList->GetEntriesFast();
289 for (Int_t nent=0;nent<nentries;nent++) {
290 AliRICHTransientDigit *transDigit=(AliRICHTransientDigit*)fTDList->At(nent);
291 if (transDigit==0) continue;
292 Int_t ich=transDigit->GetChamber();
293 Int_t q=transDigit->Signal();
294 iChamber=&(pRICH->Chamber(ich));
295 AliRICHResponse * response=iChamber->GetResponseModel();
296 Int_t adcmax= (Int_t) response->MaxAdc();
299 // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2)
300 //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY()));
303 // Int_t pedestal = iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY());
307 //printf("Pedestal:%d\n",pedestal);
309 Float_t treshold = (pedestal + 4*2.2);
311 Float_t meanNoise = gRandom->Gaus(2.2, 0.3);
312 Float_t noise = gRandom->Gaus(0, meanNoise);
313 q+=(Int_t)(noise + pedestal);
315 // magic number to be parametrised !!!
322 if ( q >= adcmax) q=adcmax;
323 fDigits[0]=transDigit->PadX();
324 fDigits[1]=transDigit->PadY();
326 fDigits[3]=transDigit->Physics();
327 fDigits[4]=transDigit->Hit();
329 Int_t nptracks = transDigit->GetNTracks();
331 // this was changed to accomodate the real number of tracks
332 if (nptracks > kMAXTRACKSPERRICHDIGIT) {
333 printf("Attention - tracks > 10 %d\n",nptracks);
334 nptracks=kMAXTRACKSPERRICHDIGIT;
337 printf("Attention - tracks > 2 %d \n",nptracks);
339 for (Int_t tr=0;tr<nptracks;tr++) {
340 tracks[tr]=transDigit->GetTrack(tr);
341 charges[tr]=transDigit->GetCharge(tr);
342 //printf("%f \n",charges[tr]);
343 } //end loop over list of tracks for one pad
344 if (nptracks < kMAXTRACKSPERRICHDIGIT ) {
345 for (Int_t t=nptracks; t<kMAXTRACKSPERRICHDIGIT; t++) {
352 //fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]);
355 pRICH->AddDigits(ich,tracks,charges,fDigits);
357 outgime->TreeD()->Fill();
359 //pRICH->ResetDigits();
360 fTDList->Delete(); // or fTDList->Clear(); ???
361 for(Int_t ii=0;ii<kNCH;++ii) {
368 TClonesArray *richDigits;
369 for (Int_t k=0;k<kNCH;k++) {
370 richDigits = pRICH->DigitsAddress(k);
371 Int_t ndigit=richDigits->GetEntriesFast();
372 printf ("Chamber %d digits %d \n",k,ndigit);
374 pRICH->ResetDigits(); /// ??? should it be here???
376 outgime->WriteDigits("OVERWRITE");
381 if (fHits) fHits->Delete();
382 if (fSDigits) fSDigits->Delete();