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.1 2001/07/27 15:41:01 jchudoba
19 merging/digitization classes
25 #include <TObjArray.h>
27 #include <TDirectory.h>
30 #include "AliMUONDigitizer.h"
31 #include "AliMUONConstants.h"
32 #include "AliMUONChamber.h"
33 #include "AliHitMap.h"
34 #include "AliMUONHitMapA1.h"
36 #include "AliMUONHit.h"
37 #include "AliMUONPadHit.h"
38 #include "AliMUONDigit.h"
39 #include "AliMUONTransientDigit.h"
42 #include "AliRunDigitizer.h"
44 ClassImp(AliMUONDigitizer)
46 //___________________________________________
47 AliMUONDigitizer::AliMUONDigitizer() :AliDigitizer()
49 // Default ctor - don't use it
50 cerr<<"Error: AliMUONDigitizer default ctor must not be used"<<endl;
53 //___________________________________________
54 AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager)
55 :AliDigitizer(manager)
57 // ctor which should be used
67 cerr<<"AliMUONDigitizer::AliMUONDigitizer"
68 <<"(AliRunDigitizer* manager) was processed"<<endl;
71 //------------------------------------------------------------------------
72 AliMUONDigitizer::~AliMUONDigitizer()
75 if (fTrH1) delete fTrH1;
76 if (fHits) delete fHits;
77 if (fPadHits) delete fPadHits;
78 if (fHitMap) delete fHitMap;
79 if (fTDList) delete fTDList;
80 if (fTrList) delete fTrList;
81 if (fAddress) delete fAddress;
84 //------------------------------------------------------------------------
85 Bool_t AliMUONDigitizer::Exists(const AliMUONPadHit *mergable)
87 AliMUONPadHit *padhit = (AliMUONPadHit*) mergable;
88 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
91 //------------------------------------------------------------------------
92 void AliMUONDigitizer::Update(AliMUONPadHit *mergable)
94 AliMUONPadHit *padhit = (AliMUONPadHit*) mergable;
95 AliMUONTransientDigit* pdigit;
96 Int_t ipx = padhit->PadX(); // pad number on X
97 Int_t ipy = padhit->PadY(); // pad number on Y
98 Int_t iqpad = Int_t(padhit->QPad()); // charge per pad
100 pdigit = (AliMUONTransientDigit*) fHitMap[fNch]->GetHit(ipx, ipy);
103 (*pdigit).AddSignal(iqpad);
104 (*pdigit).AddPhysicsSignal(iqpad);
105 // update list of tracks
107 TObjArray* fTrList = (TObjArray*)pdigit->TrackList();
108 Int_t lastEntry = fTrList->GetLast();
109 TVector *pTrack = (TVector*)fTrList->At(lastEntry);
110 TVector &ptrk = *pTrack;
111 TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
112 Int_t lastTrack = Int_t(ptrk(0));
114 if (trinfo(0) != kBgTag) {
115 if (lastTrack == fTrack) {
116 Int_t lastCharge = Int_t(ptrk(1));
118 fTrList->RemoveAt(lastEntry);
119 trinfo(1) = lastCharge;
120 fTrList->AddAt(&trinfo,lastEntry);
122 fTrList->Add(&trinfo);
125 if (lastTrack != -1) fTrList->Add(&trinfo);
129 //------------------------------------------------------------------------
130 void AliMUONDigitizer::CreateNew(AliMUONPadHit *mergable)
132 // Create new AliMUONTransientDigit and add it to the fTDList
134 AliMUONPadHit *padhit = (AliMUONPadHit*) mergable;
135 AliMUONTransientDigit* pdigit;
137 Int_t ipx = padhit->PadX(); // pad number on X
138 Int_t ipy = padhit->PadY(); // pad number on Y
139 fTDList->AddAtAndExpand(
140 new AliMUONTransientDigit(fNch,fDigits),fCounter);
141 fHitMap[fNch]->SetHit(ipx, ipy, fCounter);
143 pdigit = (AliMUONTransientDigit*)fTDList->At(fTDList->GetLast());
145 TObjArray *fTrList = (TObjArray*)pdigit->TrackList();
146 TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
147 fTrList->Add(&trinfo);
151 //------------------------------------------------------------------------
152 Bool_t AliMUONDigitizer::Init()
156 fHits = new TClonesArray("AliMUONHit",1000);
157 fPadHits = new TClonesArray("AliMUONPadHit",1000);
162 //------------------------------------------------------------------------
163 void AliMUONDigitizer::Digitize()
166 // keep galice.root for signal and name differently the file for
167 // background when add! otherwise the track info for signal will be lost !
169 AliMUONChamber* iChamber;
170 AliSegmentation* segmentation;
172 if (GetDebug()>2) cerr<<" AliMUONDigitizer::Digitize() starts"<<endl;
173 fTDList = new TObjArray;
174 if(!fAddress) fAddress = new TClonesArray("TVector",10000);
176 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
178 cerr<<"AliMUONDigitizer::Digitize Error:"
179 <<" module MUON not found in the input file"<<endl;
182 pMUON->MakeBranchInTreeD(fManager->GetTreeD());
183 fHitMap= new AliHitMap* [AliMUONConstants::NCh()];
184 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {fHitMap[i] = 0;}
187 // loop over cathodes
191 for (int icat = 0; icat < 2; icat++) {
193 Int_t * nmuon = new Int_t [AliMUONConstants::NCh()];
194 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
195 iChamber = &(pMUON->Chamber(i));
196 // if (!(iChamber->Nsec() == 1 && icat == 1)) {
197 segmentation = iChamber->SegmentationModel(icat+1);
198 fHitMap[i] = new AliMUONHitMapA1(segmentation, fTDList);
204 // Loop over files to digitize
206 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
208 // Connect MUON branches
211 TBranch *branch2 = 0;
212 TTree *treeH = fManager->GetInputTreeH(inputFile);
214 cerr<<" inputFile , cathode = "<<inputFile<<" "
216 cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
218 if (treeH && fHits) {
219 branch = treeH->GetBranch("MUON");
222 branch->SetAddress(&fHits);
225 Error("Digitize","branch MUON was not found");
227 if (GetDebug()>2) cerr<<" branch = "<<branch<<endl;
229 if (treeH && fPadHits) {
230 branch2 = treeH->GetBranch("MUONCluster");
232 branch2->SetAddress(&fPadHits);
234 Error("Digitize","branch MUONCluster was not found");
236 if (GetDebug()>2) cerr<<" branch2 = "<<branch2<<endl;
242 Int_t ntracks = (Int_t) treeH->GetEntries();
244 for (fTrack = 0; fTrack < ntracks; fTrack++) {
245 if (GetDebug()>2) cerr<<" fTrack = "<<fTrack<<endl;
247 cerr<<" branch->GetEntry(fTrack) "<<branch->GetEntry(fTrack)<<endl;
248 cerr<<" branch2->GetEntry(fTrack) "<<branch2->GetEntry(fTrack)<<endl;
254 for(int i = 0; i < fHits->GetEntriesFast(); ++i)
256 mHit = (AliMUONHit*) (*fHits)[i];
257 fNch = mHit->Chamber()-1; // chamber number
258 iChamber = &(pMUON->Chamber(fNch));
259 if (fNch > AliMUONConstants::NCh()-1) {
260 cerr<<"AliMUONDigitizer: ERROR: "
261 <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
262 <<fNch<<", "<< AliMUONConstants::NCh()<<endl;
266 // Loop over pad hits
267 for (AliMUONPadHit* mPad =
268 (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHits);
270 mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHits))
272 Int_t cathode = mPad->Cathode(); // cathode number
273 Int_t ipx = mPad->PadX(); // pad number on X
274 Int_t ipy = mPad->PadY(); // pad number on Y
275 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
276 if (cathode != (icat+1)) continue;
278 new((*fAddress)[fCountadr++]) TVector(2);
280 TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
281 Int_t mask = fManager->GetMask(inputFile);
282 trinfo(0) = (Float_t)(fTrack + mask); // tag background
283 // trinfo(0) = (Float_t)fTrack;
284 if (inputFile == 0) {
285 trinfo(1) = (Float_t)iqpad;
293 if (inputFile == 0) {
298 if (mHit->Particle() == kMuonPlus ||
299 mHit->Particle() == kMuonMinus) {
300 fDigits[5] = (mPad->HitNumber()) + mask;
301 } else fDigits[5] = -1;
303 // build the list of fired pads and update the info,
304 // fDigits is input for Update(mPad)
310 } // end if Exists(mPad)
311 } //end loop over clusters
315 if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
319 Int_t nentries = fTDList->GetEntriesFast();
321 for (Int_t nent = 0; nent < nentries; nent++) {
322 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
323 if (address == 0) continue;
324 Int_t ich = address->Chamber();
325 Int_t q = address->Signal();
326 iChamber = &(pMUON->Chamber(ich));
328 // Digit Response (noise, threshold, saturation, ...)
329 AliMUONResponse * response = iChamber->ResponseModel();
330 q = response->DigitResponse(q);
334 fDigits[0] = address->PadX();
335 fDigits[1] = address->PadY();
336 fDigits[2] = address->Cathode();
338 fDigits[4] = address->Physics();
339 fDigits[5] = address->Hit();
341 TObjArray* fTrList = (TObjArray*)address->TrackList();
342 Int_t nptracks = fTrList->GetEntriesFast();
344 // this was changed to accomodate the real number of tracks
347 cerr<<"Attention - nptracks > 10 "<<nptracks<<endl;
350 if (nptracks > 2 && GetDebug() >2) {
351 cerr<<"Attention - nptracks > 2 "<<nptracks<<endl;
352 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
354 for (Int_t tr = 0; tr < nptracks; tr++) {
355 TVector *ppP = (TVector*)fTrList->At(tr);
357 cerr<<"Error: ppP = "<<ppP<<endl;
361 tracks[tr] = Int_t(pp(0));
362 charges[tr] = Int_t(pp(1));
363 } //end loop over list of tracks for one pad
364 // Sort list of tracks according to charge
366 SortTracks(tracks,charges,nptracks);
368 if (nptracks < 10 ) {
369 for (Int_t i = nptracks; i < 10; i++) {
376 pMUON->AddDigits(ich,tracks,charges,fDigits);
380 fManager->GetTreeD()->Fill();
382 pMUON->ResetDigits(); //
386 for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
393 } //end loop over cathodes
395 cerr<<"DDDDD: writing the TreeD: "
396 <<fManager->GetTreeD()->GetName()<<endl;
397 fManager->GetTreeD()->Write();
401 if (fAddress) fAddress->Delete();
402 if (fHits) fHits->Delete();
403 if (fPadHits) fPadHits->Delete();
404 // gObjectTable->Print();
409 void AliMUONDigitizer::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
412 // Sort the list of tracks contributing to a given digit
413 // Only the 3 most significant tracks are acctually sorted
417 // Loop over signals, only 3 times
422 Int_t idx[3] = {-2,-2,-2};
423 Int_t jch[3] = {-2,-2,-2};
424 Int_t jtr[3] = {-2,-2,-2};
435 if((i == 1 && j == idx[i-1])
436 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
438 if(charges[j] > qmax) {
446 jch[i]=charges[jmax];
465 void AliMUONDigitizer::MixWith(char* HeaderFile, char* SDigitsFile){
469 cout << "Specify header file to merge"<< endl;
474 for(inputs = 0; inputs < fNinputs ; inputs++){
475 if(strcmp(((TObjString *)fHeaderFiles->At(inputs))->GetString(),HeaderFile) == 0 ){
476 cout << "Entry already exists, do not add" << endl ;
481 fHeaderFiles->Expand(fNinputs+1) ;
482 new((*fHeaderFiles)[fNinputs]) TObjString(HeaderFile) ;
485 file = new TFile(((TObjString *) fHeaderFiles->At(fNinputs))->GetString()) ;