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.5 2001/10/23 13:03:35 hristov
19 The access to several data members was changed from public to protected. The digitisation was adapted to the multi-event case (J.Chudoba)
21 Revision 1.4 2001/10/21 18:31:24 hristov
22 Several pointers were set to zero in the default constructors to avoid memory management problems
24 Revision 1.3 2001/05/16 14:57:20 alibrary
25 New files for folders and Stack
27 Revision 1.2 2001/03/14 18:16:08 jbarbosa
28 Corrected bug (more to correct).
29 File "points.dat" is no longer created.
31 Revision 1.1 2001/02/27 22:13:34 jbarbosa
32 Implementing merger class.
38 #include <TObjArray.h>
40 #include <TDirectory.h>
41 #include <TParticle.h>
43 #include "AliRICHMerger.h"
44 #include "AliRICHChamber.h"
45 #include "AliHitMap.h"
46 #include "AliRICHHitMapA1.h"
48 #include "AliRICHHit.h"
49 #include "AliRICHSDigit.h"
50 #include "AliRICHDigit.h"
51 #include "AliRICHTransientDigit.h"
55 ClassImp(AliRICHMerger)
57 //___________________________________________
58 AliRICHMerger::AliRICHMerger()
60 // Default constructor
75 //------------------------------------------------------------------------
76 AliRICHMerger::~AliRICHMerger()
79 if (fTrH1) delete fTrH1;
80 if (fHitsBgr) delete fHitsBgr;
81 if (fSDigitsBgr) delete fSDigitsBgr;
82 if (fHitMap) delete fHitMap;
83 if (fList) delete fList;
84 if (fBgrFile) delete fBgrFile;
87 //------------------------------------------------------------------------
88 Bool_t AliRICHMerger::Exists(const AliRICHSDigit *padhit)
90 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
93 //------------------------------------------------------------------------
94 void AliRICHMerger::Update(AliRICHSDigit *padhit)
96 AliRICHTransientDigit *pdigit =
97 static_cast<AliRICHTransientDigit*>(
98 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
102 Int_t iqpad = Int_t(padhit->QPad()); // charge per pad
103 pdigit->AddSignal(iqpad);
104 pdigit->AddPhysicsSignal(iqpad);
106 // update list of tracks
116 pdigit->UpdateTrackList(track,charge);
119 //------------------------------------------------------------------------
120 void AliRICHMerger::CreateNew(AliRICHSDigit *padhit)
122 fList->AddAtAndExpand(
123 new AliRICHTransientDigit(fNch,fDigits),fCounter);
124 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
126 AliRICHTransientDigit* pdigit =
127 static_cast<AliRICHTransientDigit*>(fList->Last());
132 charge = padhit->QPad();
137 pdigit->AddToTrackList(track,charge);
142 //------------------------------------------------------------------------
143 void AliRICHMerger::Init()
147 if (fMerge && !fBgrFile) fBgrFile = InitBgr();
152 //------------------------------------------------------------------------
153 TFile* AliRICHMerger::InitBgr()
155 // Initialise background event
156 TFile *file = new TFile(fFnBgr);
157 // add error checking later
158 printf("\n AliRICHMerger has opened %s file with background event \n", fFnBgr);
159 fHitsBgr = new TClonesArray("AliRICHHit",1000);
160 fSDigitsBgr = new TClonesArray("AliRICHSDigit",1000);
164 //------------------------------------------------------------------------
165 void AliRICHMerger::Digitise(Int_t nev, Int_t flag)
168 // keep galice.root for signal and name differently the file for
169 // background when add! otherwise the track info for signal will be lost !
173 AliRICHChamber* iChamber;
174 AliSegmentation* segmentation;
176 fList = new TObjArray;
178 AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH");
179 fHitMap= new AliHitMap* [kNCH];
184 // Get Hits Tree header from file
185 if(fHitsBgr) fHitsBgr->Clear();
186 if(fSDigitsBgr) fSDigitsBgr->Clear();
187 if(fTrH1) delete fTrH1;
191 sprintf(treeName,"TreeH%d",fEvNrBgr);
192 fTrH1 = (TTree*)gDirectory->Get(treeName);
194 printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr);
197 // Set branch addresses
200 sprintf(branchname,"%s",pRICH->GetName());
201 if (fTrH1 && fHitsBgr) {
202 branch = fTrH1->GetBranch(branchname);
203 if (branch) branch->SetAddress(&fHitsBgr);
205 if (fTrH1 && fSDigitsBgr) {
206 branch = fTrH1->GetBranch("RICHSDigits");
207 if (branch) branch->SetAddress(&fSDigitsBgr);
211 for (Int_t i =0; i<kNCH; i++) {
212 iChamber= &(pRICH->Chamber(i));
213 segmentation=iChamber->GetSegmentationModel(1);
214 fHitMap[i] = new AliRICHHitMapA1(segmentation, fList);
222 TTree *treeH = gAlice->TreeH();
223 Int_t ntracks =(Int_t) treeH->GetEntries();
224 for (fTrack=0; fTrack<ntracks; fTrack++) {
226 treeH->GetEvent(fTrack);
229 for(AliRICHHit* mHit=(AliRICHHit*)pRICH->FirstHit(-1);
231 mHit=(AliRICHHit*)pRICH->NextHit())
234 fNch = mHit->Chamber()-1; // chamber number
235 Int_t trackIndex = mHit->Track();
237 cerr<<"AliRICHMerger: chamber nr. fNch out of range: "<<fNch<<endl;
238 cerr<<" track: "<<fTrack<<endl;
241 iChamber = &(pRICH->Chamber(fNch));
245 // If flag is set, create digits only for some particles
247 TParticle *current = (TParticle*)gAlice->Particle(trackIndex);
248 if (current->GetPdgCode() >= 50000050)
250 TParticle *motherofcurrent = (TParticle*)gAlice->Particle(current->GetFirstMother());
251 particle = motherofcurrent->GetPdgCode();
255 particle = current->GetPdgCode();
259 //printf("Flag:%d\n",flag);
260 //printf("Track:%d\n",track);
261 //printf("Particle:%d\n",particle);
266 if(TMath::Abs(particle)==211 || TMath::Abs(particle)==111)
270 if(TMath::Abs(particle)==321 || TMath::Abs(particle)==130 || TMath::Abs(particle)==310
271 || TMath::Abs(particle)==311)
274 if (flag == 3 && TMath::Abs(particle)==2212)
277 if (flag == 4 && TMath::Abs(particle)==13)
280 if (flag == 5 && TMath::Abs(particle)==11)
283 if (flag == 6 && TMath::Abs(particle)==2112)
287 //printf ("Particle: %d, Flag: %d, Digitise: %d\n",particle,flag,digitise);
294 // Loop over pad hits
295 for (AliRICHSDigit* mPad=
296 (AliRICHSDigit*)pRICH->FirstPad(mHit,pRICH->SDigits());
298 mPad=(AliRICHSDigit*)pRICH->NextPad(pRICH->SDigits()))
300 Int_t iqpad = mPad->QPad(); // charge per pad
301 fDigits[0]=mPad->PadX();
302 fDigits[1]=mPad->PadY();
305 fDigits[4]=mPad->HitNumber();
307 // build the list of fired pads and update the info
313 } //end loop over clusters
314 }// track type condition
318 // open the file with background
322 ntracks = (Int_t)fTrH1->GetEntries();
326 for (fTrack = 0; fTrack < ntracks; fTrack++) {
328 if (fHitsBgr) fHitsBgr->Clear();
329 if (fSDigitsBgr) fSDigitsBgr->Clear();
331 fTrH1->GetEvent(fTrack);
335 for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i)
337 mHit = (AliRICHHit*) (*fHitsBgr)[i];
338 fNch = mHit->Chamber()-1; // chamber number
339 iChamber = &(pRICH->Chamber(fNch));
342 // Loop over pad hits
343 for (AliRICHSDigit* mPad =
344 (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigitsBgr);
346 mPad = (AliRICHSDigit*)pRICH->NextPad(fSDigitsBgr))
348 fDigits[0] = mPad->PadX();
349 fDigits[1] = mPad->PadY();
350 fDigits[2] = mPad->QPad();
352 fDigits[4] = -1; // set hit number to -1 for bgr
354 // build the list of fired pads and update the info
360 } //end loop over clusters
364 TTree *treeK = gAlice->TreeK();
367 if (treeK) file = treeK->GetCurrentFile();
371 Int_t tracks[kMAXTRACKSPERRICHDIGIT];
372 Int_t charges[kMAXTRACKSPERRICHDIGIT];
373 Int_t nentries=fList->GetEntriesFast();
375 for (Int_t nent=0;nent<nentries;nent++) {
376 AliRICHTransientDigit *transDigit=(AliRICHTransientDigit*)fList->At(nent);
377 if (transDigit==0) continue;
378 Int_t ich=transDigit->GetChamber();
379 Int_t q=transDigit->Signal();
380 iChamber=&(pRICH->Chamber(ich));
381 AliRICHResponse * response=iChamber->GetResponseModel();
382 Int_t adcmax= (Int_t) response->MaxAdc();
385 // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2)
386 //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY()));
387 Int_t pedestal = iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY());
389 //printf("Pedestal:%d\n",pedestal);
391 Float_t treshold = (pedestal + 4*2.2);
393 Float_t meanNoise = gRandom->Gaus(2.2, 0.3);
394 Float_t noise = gRandom->Gaus(0, meanNoise);
395 q+=(Int_t)(noise + pedestal);
397 // magic number to be parametrised !!!
404 if ( q >= adcmax) q=adcmax;
405 fDigits[0]=transDigit->PadX();
406 fDigits[1]=transDigit->PadY();
408 fDigits[3]=transDigit->Physics();
409 fDigits[4]=transDigit->Hit();
411 Int_t nptracks = transDigit->GetNTracks();
413 // this was changed to accomodate the real number of tracks
414 if (nptracks > kMAXTRACKSPERRICHDIGIT) {
415 printf("Attention - tracks > 10 %d\n",nptracks);
416 nptracks=kMAXTRACKSPERRICHDIGIT;
419 printf("Attention - tracks > 2 %d \n",nptracks);
420 //printf("cat,ich,ix,iy,q %d %d %d %d %d \n",
421 //icat,ich,digits[0],digits[1],q);
423 for (Int_t tr=0;tr<nptracks;tr++) {
424 tracks[tr]=transDigit->GetTrack(tr);
425 charges[tr]=transDigit->GetCharge(tr);
426 } //end loop over list of tracks for one pad
427 if (nptracks < kMAXTRACKSPERRICHDIGIT ) {
428 for (Int_t t=nptracks; t<kMAXTRACKSPERRICHDIGIT; t++) {
435 //fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]);
438 pRICH->AddDigits(ich,tracks,charges,fDigits);
440 gAlice->TreeD()->Fill();
443 for(Int_t ii=0;ii<kNCH;++ii) {
450 TClonesArray *richDigits;
451 for (Int_t k=0;k<kNCH;k++) {
452 richDigits = pRICH->DigitsAddress(k);
453 Int_t ndigit=richDigits->GetEntriesFast();
454 printf ("Chamber %d digits %d \n",k,ndigit);
456 pRICH->ResetDigits(); /// ??? should it be here???
457 gAlice->TreeD()->Write(0,TObject::kOverwrite);
459 // gAlice->TreeD()->Reset();
460 // delete fList; // deleted in dtor
461 // gObjectTable->Print();