]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSDigitizerV2.cxx
Adding CreateIterator(void) and GetNeighbours() pure virtual methods,
[u/mrichter/AliRoot.git] / MUON / AliMUONSDigitizerV2.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 <TClonesArray.h>
19
20 #include "AliMUONSDigitizerV2.h"
21
22 #include "AliLog.h"
23 #include "AliMUON.h"
24 #include "AliMUONChamber.h"
25 #include "AliMUONData.h"
26 #include "AliMUONDigit.h"
27 #include "AliMUONHit.h"
28 #include "AliMpDEManager.h"
29 #include "AliLoader.h"
30 #include "AliRun.h"
31 #include "AliRunLoader.h"
32 #include "TObjArray.h"
33
34
35 ///
36 /// The sdigitizer performs the transformation from hits (energy deposits by
37 /// the transport code) to sdigits (equivalent of charges on pad).
38 ///
39 /// It does so by converting the energy deposit into a charge and then spreading
40 /// this charge over several pads, according to the response function (a 
41 /// Mathieson distribution, basically).
42 /// 
43 /// See also AliMUONResponseV0, which is doing the real job (in DisIntegrate
44 /// method), while this sdigitizer is just "steering" the process.
45 ///
46 /// Please note that we do *not* merge sdigits after creation, which means
47 /// that after sdigitization, a given pad can have several sdigits. This
48 /// merging is taken care of later on by the digitizer(V3).
49 ///
50
51 ClassImp(AliMUONSDigitizerV2)
52
53 //_____________________________________________________________________________
54 AliMUONSDigitizerV2::AliMUONSDigitizerV2() 
55 : TTask("AliMUONSDigitizerV2","From Hits to SDigits for MUON")
56 {
57   //
58   // ctor.
59   //
60 }
61
62 //_____________________________________________________________________________
63 AliMUONSDigitizerV2::~AliMUONSDigitizerV2()
64 {
65   //
66   // dtor.
67   //
68 }
69
70 //_____________________________________________________________________________
71 void
72 AliMUONSDigitizerV2::Exec(Option_t*)
73 {
74   //
75   // Go from hits to sdigits.
76   //
77   // In the code below, apart from the loop itself (which look complicated
78   // but is really only a loop on each hit in the input file) the main
79   // work is done in AliMUONResponse::DisIntegrate method, which converts
80   // a single hit in (possibly) several sdigits.
81   //
82   
83   AliDebug(1,"");
84   
85   AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
86   AliLoader* fLoader = runLoader->GetLoader("MUONLoader");
87
88   fLoader->LoadHits("READ");
89   
90   AliMUONData muonData(fLoader,"MUON","MUON");
91
92   AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
93     
94   Int_t nofEvents(runLoader->GetNumberOfEvents());
95   for ( Int_t iEvent = 0; iEvent < nofEvents; ++iEvent ) 
96   {    
97     // Loop over events.
98     TObjArray tdlist;
99     tdlist.SetOwner(kTRUE);
100     
101     AliDebug(1,Form("iEvent=%d",iEvent));
102     runLoader->GetEvent(iEvent);
103     TTree* treeS = fLoader->TreeS();
104     AliDebug(1,Form("TreeS=%p",treeS));
105     if ( !treeS )
106     {
107       AliDebug(1,"MakeSDigitsContainer");
108       fLoader->MakeSDigitsContainer();
109       treeS = fLoader->TreeS();
110     }
111     AliDebug(1,Form("TreeS=%p",treeS));
112     muonData.MakeBranch("S");
113     muonData.SetTreeAddress("S");
114     
115     muonData.SetTreeAddress("H");
116     TTree* treeH = fLoader->TreeH();
117     AliDebug(1,Form("TreeH=%p",treeH));
118              
119     Long64_t nofTracks = treeH->GetEntries();
120     for ( Long64_t iTrack = 0; iTrack < nofTracks; ++iTrack )
121     {
122       // Loop over the tracks of this event.
123       treeH->GetEvent(iTrack);
124       TClonesArray* hits = muonData.Hits();
125       Int_t nofHits = hits->GetEntriesFast();
126       for ( Int_t ihit = 0; ihit < nofHits; ++ihit )
127       {
128         // Loop over the hits of this track.
129         AliMUONHit* hit = static_cast<AliMUONHit*>(hits->At(ihit)); 
130         Int_t chamberId = hit->Chamber()-1;
131         AliMUONChamber& chamber = muon->Chamber(chamberId);
132         AliMUONResponse* response = chamber.ResponseModel();
133         
134         // This is the heart of this method : the dis-integration
135         TList digits;        
136         response->DisIntegrate(*hit,digits);
137         
138         TIter next(&digits);
139         AliMUONDigit* d;
140         while ( ( d = (AliMUONDigit*)next() ) )
141         {
142           // Update some sdigit information that could not be known
143           // by the DisIntegrate method
144           d->SetHit(ihit);
145           d->AddTrack(iTrack,d->Signal());
146           tdlist.Add(d);
147         }
148       }
149       muonData.ResetHits();
150     } // end of loop on tracks within an event
151     
152     for ( Int_t i = 0; i <= tdlist.GetLast(); ++i )
153     {
154       AliMUONDigit* d = (AliMUONDigit*)tdlist[i];
155       StdoutToAliDebug(1,d->Print(););
156       if ( d->Signal() > 0 ) // that check would be better in the disintegrate
157         // method, but to compare with old sdigitizer, it has to be there.
158       {
159         muonData.AddSDigit(AliMpDEManager::GetChamberId(d->DetElemId()),*d);
160       }
161     }
162     muonData.Fill("S");
163     fLoader->WriteSDigits("OVERWRITE");
164     
165     muonData.ResetSDigits();
166     fLoader->UnloadSDigits();
167   } // loop on events
168   
169   fLoader->UnloadHits();  
170 }