]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONMerger.cxx
Added protected copy constructors and assignment operators. (I. Hrivnacova)
[u/mrichter/AliRoot.git] / MUON / AliMUONMerger.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 #include <Riostream.h> 
19 #include <TTree.h> 
20 #include <TObjArray.h>
21 #include <TFile.h>
22 #include <TDirectory.h>
23 #include <TPDGCode.h>
24
25 #include "AliHitMap.h"
26 #include "AliMUON.h"
27 #include "AliMUONChamber.h"
28 #include "AliMUONConstants.h"
29 #include "AliMUONDigit.h"
30 #include "AliMUONHit.h"
31 #include "AliMUONHitMapA1.h"
32 #include "AliMUONMerger.h"
33 #include "AliMUONPadHit.h"
34 #include "AliMUONTransientDigit.h"
35 #include "AliRun.h"
36
37 ClassImp(AliMUONMerger)
38
39 //----------------------------------------------------------------------
40 AliMUONMerger::AliMUONMerger()
41 {
42 // Default constructor    
43     fEvNrSig = 0;
44     fEvNrBgr = 0;
45     fMerge   = kDigitize;
46     fFnBgr   = 0;
47     fHitMap  = 0;
48     fList    = 0;
49     fTrH1    = 0;
50     fHitsBgr = 0;
51     fPadHitsBgr = 0;
52     fHitMap     = 0;
53     fList       = 0;
54     fBgrFile    = 0;
55     fDebug      = 0;
56 }
57
58 //----------------------------------------------------------------------
59 AliMUONMerger::AliMUONMerger(const AliMUONMerger&)
60 {
61 // Protected copy constructor
62
63   Fatal("AliMUONMergerModule", "Not implemented.");
64 }
65
66 //------------------------------------------------------------------------
67 AliMUONMerger::~AliMUONMerger()
68 {
69 // Destructor
70     if (fTrH1)       delete fTrH1;
71     if (fHitsBgr)    delete fHitsBgr;
72     if (fPadHitsBgr) delete fPadHitsBgr;
73     if (fHitMap)     delete [] fHitMap;
74     if (fList)       delete fList;
75     if (fBgrFile)    delete fBgrFile;
76 }
77
78 //----------------------------------------------------------------------
79 AliMUONMerger&  AliMUONMerger::operator=(const AliMUONMerger& rhs)
80 {
81 // Protected assignement operator
82
83   if (this == &rhs) return *this;
84
85   Fatal("operator=", "Not implemented.");
86     
87   return *this;  
88 }    
89           
90 //------------------------------------------------------------------------
91 Bool_t AliMUONMerger::Exists(const AliMUONPadHit *padhit) const
92 {
93 // test if the given padhit was already fired
94     return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
95 }
96
97 //------------------------------------------------------------------------
98 void AliMUONMerger::Update(AliMUONPadHit *padhit)
99 {
100 // add new contribution to the fired padhit
101     AliMUONTransientDigit *pdigit = 
102       static_cast<AliMUONTransientDigit*>(
103       fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
104
105     // update charge
106     //
107     Int_t iqpad    = padhit->QPad();        // charge per pad
108     pdigit->AddSignal(iqpad);
109     pdigit->AddPhysicsSignal(iqpad);            
110
111     // update list of tracks
112     //
113     Int_t track, charge;   
114     if (fSignal) {
115       track = fTrack;
116       charge = iqpad;
117     } else {
118       track = kBgTag;
119       charge = kBgTag;
120     }
121     pdigit->UpdateTrackList(track,charge);
122 }
123
124 //------------------------------------------------------------------------
125 void AliMUONMerger::CreateNew(AliMUONPadHit *padhit)
126 {
127 // add new transient digit to the list, update hit map
128     fList->AddAtAndExpand(
129         new AliMUONTransientDigit(fNch,fDigits),fCounter);
130     fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
131     AliMUONTransientDigit* pdigit = 
132       static_cast<AliMUONTransientDigit*>(fList->Last());
133     // list of tracks
134     Int_t track, charge;
135     if (fSignal) {
136       track = fTrack;
137       charge = padhit->QPad();
138     } else {
139       track = kBgTag;
140       charge = kBgTag;
141     }
142     pdigit->AddToTrackList(track,charge);
143     fCounter++;
144 }
145
146
147 //------------------------------------------------------------------------
148 void AliMUONMerger::Init()
149 {
150 // Initialisation
151     // open only once the background file !!
152     if (fMerge && !fBgrFile) fBgrFile = InitBgr();
153 }
154
155
156
157 //------------------------------------------------------------------------
158 TFile* AliMUONMerger::InitBgr()
159 {
160 // Initialise background event
161     TFile *file = new TFile(fFnBgr);
162 // add error checking later
163     printf("\n AliMUONMerger has opened %s file with background event \n", fFnBgr);
164     fHitsBgr     = new TClonesArray("AliMUONHit",1000);
165     fPadHitsBgr  = new TClonesArray("AliMUONPadHit",1000);
166     return file;
167 }
168
169 //------------------------------------------------------------------------
170 void AliMUONMerger::Digitise()
171 {
172
173     // keep galice.root for signal and name differently the file for 
174     // background when add! otherwise the track info for signal will be lost !
175   // Obsolete sep 2003 Gines MARTINEZ 
176   //    AliMUONChamber*   iChamber;
177 //      AliSegmentation*  segmentation;
178
179 //      fList = new TObjArray;
180
181 //      AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
182 //      fHitMap= new AliHitMap* [AliMUONConstants::NCh()];
183 //      if (fMerge ) {
184 //      fBgrFile->cd();
185 //          //
186 //      // Get Hits Tree header from file
187 //      //if(fHitsBgr) fHitsBgr->Clear();     // Useless because line 327
188 //      //if(fPadHitsBgr) fPadHitsBgr->Clear(); // Useless because line 328
189 //      if(fTrH1) delete fTrH1;
190 //      fTrH1 = 0;
191         
192 //      char treeName[20];
193 //      sprintf(treeName,"TreeH%d",fEvNrBgr);
194 //      fTrH1 = (TTree*)gDirectory->Get(treeName);
195 //      if (!fTrH1) {
196 //          printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr);
197 //      }
198 //          //
199 //      // Set branch addresses
200 //      TBranch *branch;
201 //      char branchname[20];
202 //      sprintf(branchname,"%s",pMUON->GetName());
203 //      if (fTrH1 && fHitsBgr) {
204 //          branch = fTrH1->GetBranch(branchname);
205 //          if (branch) branch->SetAddress(&fHitsBgr);
206 //      }
207 //      if (fTrH1 && fPadHitsBgr) {
208 //          branch = fTrH1->GetBranch("MUONCluster");
209 //          if (branch) branch->SetAddress(&fPadHitsBgr);
210 //      }
211 //      }
212 //      //
213 //      // loop over cathodes
214 //      //
215 //      fSignal = kTRUE;
216 //      for (int icat = 0; icat < 2; icat++) { 
217 //      fCounter = 0;
218 //      for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
219 //          iChamber = &(pMUON->Chamber(i));
220 //          if (iChamber->Nsec() == 1 && icat == 1) {
221 //              continue;
222 //          } else {
223 //              segmentation = iChamber->SegmentationModel(icat+1);
224 //          }
225 //          fHitMap[i] = new AliMUONHitMapA1(segmentation, fList);
226 //      }
227
228 //  //
229 //  //   Loop over tracks
230 //  //
231
232 //  /******************************************************************/
233 //        TTree* treeH = pMUON->TreeH();
234 //        if (treeH == 0x0)
235 //         {
236 //           cerr<<"AliMUONMerger::Exec: Can not get TreeH"<<endl;
237 //           return;
238 //         }
239 //  /******************************************************************/     
240
241         
242         
243 //      Int_t ntracks = (Int_t) treeH->GetEntries();
244 //      treeH->SetBranchStatus("*",0); // switch off all branches
245 //          treeH->SetBranchStatus("MUON*",1); // switch on only MUON
246
247 //      for (fTrack = 0; fTrack < ntracks; fTrack++) {
248 //          gAlice->ResetHits();
249 //          treeH->GetEntry(fTrack,0);
250 //  //
251 //  //   Loop over hits
252 //          for(AliMUONHit* mHit = (AliMUONHit*)pMUON->FirstHit(-1); 
253 //              mHit;
254 //              mHit = (AliMUONHit*)pMUON->NextHit()) 
255 //          {
256 //              fNch = mHit->Chamber()-1;  // chamber number
257 //              if (fNch > AliMUONConstants::NCh()-1) continue;
258 //              iChamber = &(pMUON->Chamber(fNch));
259                 
260 //  //
261 //  // Loop over pad hits
262 //              for (AliMUONPadHit* mPad =
263 //                       (AliMUONPadHit*)pMUON->FirstPad(mHit,pMUON->PadHits());
264 //                   mPad;
265 //                   mPad = (AliMUONPadHit*)pMUON->NextPad(pMUON->PadHits()))
266 //              {
267 //                  Int_t cathode  = mPad->Cathode();      // cathode number
268 //                  if (cathode != (icat+1)) continue;
269 //                  Int_t iqpad    = Int_t(mPad->QPad());  // charge per pad
270 //  //              segmentation = iChamber->SegmentationModel(cathode);
271 //                  fDigits[0] = mPad->PadX();  
272 //                  fDigits[1] = mPad->PadY();
273 //                  if (!(fHitMap[fNch]->ValidateHit(fDigits[0], fDigits[1]))) continue;
274 //                  fDigits[2] = icat;
275 //                  fDigits[3] = iqpad;
276 //                  fDigits[4] = iqpad;
277 //                  if (mHit->Particle() == kMuonPlus ||
278 //                      mHit->Particle() == kMuonMinus) {
279 //                      fDigits[5] = mPad->HitNumber();
280 //                  } else fDigits[5] = -1;
281
282 //                  // build the list of fired pads and update the info
283
284 //                  if (!Exists(mPad)) {
285 //                      CreateNew(mPad);
286 //                  } else {
287 //                      Update(mPad);
288 //                  } //  end if pdigit
289 //              } //end loop over clusters
290 //          } // hit loop
291 //      } // track loop
292
293 //      // open the file with background
294        
295 //      if (fMerge) {
296 //              fSignal = kFALSE;
297 //          ntracks = (Int_t)fTrH1->GetEntries();
298 //  //
299 //  //   Loop over tracks
300 //  //
301 //          for (fTrack = 0; fTrack < ntracks; fTrack++) {
302
303 //              if (fHitsBgr)       fHitsBgr->Clear();
304 //              if (fPadHitsBgr)    fPadHitsBgr->Clear();
305
306 //              fTrH1->GetEvent(fTrack);
307 //  //
308 //  //   Loop over hits
309 //              AliMUONHit* mHit;
310 //              for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i) 
311 //              {       
312 //                  mHit   = (AliMUONHit*) (*fHitsBgr)[i];
313 //                  fNch   = mHit->Chamber()-1;  // chamber number
314 //                  iChamber = &(pMUON->Chamber(fNch));
315 //  //
316 //  // Loop over pad hits
317 //                  for (AliMUONPadHit* mPad =
318 //                           (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHitsBgr);
319 //                       mPad;
320 //                       mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHitsBgr))
321 //                  {
322 //                      Int_t cathode  = mPad->Cathode();     // cathode number
323 //                      Int_t ipx      = mPad->PadX();        // pad number on X
324 //                      Int_t ipy      = mPad->PadY();        // pad number on Y
325 //                      Int_t iqpad    = Int_t(mPad->QPad()); // charge per pad
326 //                      if (!(fHitMap[fNch]->ValidateHit(ipx, ipy))) continue;
327
328 //                      if (cathode != (icat+1)) continue;
329 //                      fDigits[0] = ipx;
330 //                      fDigits[1] = ipy;
331 //                      fDigits[2] = icat;
332 //                      fDigits[3] = iqpad;
333 //                      fDigits[4] = 0;
334 //                      fDigits[5] = -1;
335                         
336 //                      // build the list of fired pads and update the info
337 //                      if (!Exists(mPad)) {
338 //                          CreateNew(mPad);
339 //                      } else {
340 //                          Update(mPad);
341 //                      } //  end if !Exists
342 //                  } //end loop over clusters
343 //              } // hit loop
344 //          } // track loop
345
346 //          TTree *treeK = gAlice->TreeK();
347 //              TFile *file = NULL;
348             
349 //          if (treeK) file = treeK->GetCurrentFile();
350 //          file->cd();
351 //      } // if fMerge
352
353 //      Int_t tracks[kMAXTRACKS];
354 //      Int_t charges[kMAXTRACKS];
355 //      Int_t nentries = fList->GetEntriesFast();
356         
357 //      for (Int_t nent = 0; nent < nentries; nent++) {
358 //          AliMUONTransientDigit *address = (AliMUONTransientDigit*)fList->At(nent);
359 //          if (address == 0) continue; 
360 //          Int_t ich = address->Chamber();
361 //          Int_t   q = address->Signal(); 
362 //          iChamber = &(pMUON->Chamber(ich));
363 //  //
364 //  //  Digit Response (noise, threshold, saturation, ...)
365 //          AliMUONResponse * response = iChamber->ResponseModel();
366 //          q = response->DigitResponse(q,address);
367             
368 //          if (!q) continue;
369             
370 //          fDigits[0] = address->PadX();
371 //          fDigits[1] = address->PadY();
372 //          fDigits[2] = address->Cathode();
373 //          fDigits[3] = q;
374 //          fDigits[4] = address->Physics();
375 //          fDigits[5] = address->Hit();
376             
377 //          Int_t nptracks = address->GetNTracks();
378
379 //          if (nptracks > kMAXTRACKS) {
380 //              if (fDebug>0)
381 //                printf("\n Attention - nptracks > kMAXTRACKS %d \n", nptracks);
382 //              nptracks = kMAXTRACKS;
383 //          }
384 //          if (nptracks > 2) {
385 //              if (fDebug>0) {
386 //                printf("Attention - nptracks > 2  %d \n",nptracks);
387 //                printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
388 //              }
389 //          }
390 //          for (Int_t tr = 0; tr < nptracks; tr++) {
391 //              tracks[tr]   = address->GetTrack(tr);
392 //              charges[tr]  = address->GetCharge(tr);
393 //          }      //end loop over list of tracks for one pad
394 //              // Sort list of tracks according to charge
395 //          if (nptracks > 1) {
396 //              SortTracks(tracks,charges,nptracks);
397 //          }
398 //          if (nptracks < kMAXTRACKS ) {
399 //              for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
400 //                  tracks[i]  = 0;
401 //                  charges[i] = 0;
402 //              }
403 //          }
404             
405 //          // fill digits
406 //          pMUON->AddDigits(ich,tracks,charges,fDigits);
407 //      }
408 //      gAlice->TreeD()->Fill();
409 //      pMUON->ResetDigits();
410 //      fList->Delete();
411
412         
413 //      for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
414 //          if (fHitMap[ii]) {
415 //              delete fHitMap[ii];
416 //              fHitMap[ii] = 0;
417 //          }
418 //      }
419 //      } //end loop over cathodes
420 //      delete [] fHitMap;
421 //      delete fList;
422     
423 //  no need to delete ... and it makes a crash also
424 //    if (fHitsBgr)    fHitsBgr->Delete();
425 //    if (fPadHitsBgr) fPadHitsBgr->Delete();
426     // gObjectTable->Print();
427 }
428
429
430
431 void AliMUONMerger::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
432 {
433   //
434   // Sort the list of tracks contributing to a given digit
435   // Only the 3 most significant tracks are acctually sorted
436   //
437   
438   //
439   //  Loop over signals, only 3 times
440   //
441   
442   Int_t qmax;
443   Int_t jmax;
444   Int_t idx[3] = {-2,-2,-2};
445   Int_t jch[3] = {-2,-2,-2};
446   Int_t jtr[3] = {-2,-2,-2};
447   Int_t i,j,imax;
448   
449   if (ntr<3) imax=ntr;
450   else imax=3;
451   for(i=0;i<imax;i++){
452     qmax=0;
453     jmax=0;
454     
455     for(j=0;j<ntr;j++){
456       
457       if((i == 1 && j == idx[i-1]) 
458          ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
459       
460       if(charges[j] > qmax) {
461         qmax = charges[j];
462         jmax=j;
463       }       
464     } 
465     
466     if(qmax > 0) {
467       idx[i]=jmax;
468       jch[i]=charges[jmax]; 
469       jtr[i]=tracks[jmax]; 
470     }
471     
472   } 
473   
474   for(i=0;i<3;i++){
475     if (jtr[i] == -2) {
476          charges[i]=0;
477          tracks[i]=0;
478     } else {
479          charges[i]=jch[i];
480          tracks[i]=jtr[i];
481     }
482   }
483 }
484
485
486