]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSDigitizerV2.cxx
- Reshape the architecture of the Kalman tracking to make it more modular
[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 "AliMUONVDigit.h"
26 #include "AliMUONDigitStoreV1.h"
27 #include "AliMUONHit.h"
28 #include "AliMpDEManager.h"
29 #include "AliLoader.h"
30 #include "AliRun.h"
31 #include "AliRunLoader.h"
32 #include "AliMUONVHitStore.h"
33
34 ///
35 /// The sdigitizer performs the transformation from hits (energy deposits by
36 /// the transport code) to sdigits (equivalent of charges on pad).
37 ///
38 /// It does so by converting the energy deposit into a charge and then spreading
39 /// this charge over several pads, according to the response function (a 
40 /// Mathieson distribution, basically).
41 /// 
42 /// See also AliMUONResponseV0, which is doing the real job (in DisIntegrate
43 /// method), while this sdigitizer is just "steering" the process.
44 ///
45 /// Please note that we do *not* merge sdigits after creation, which means
46 /// that after sdigitization, a given pad can have several sdigits. This
47 /// merging is taken care of later on by the digitizer(V3).
48 ///
49
50 ClassImp(AliMUONSDigitizerV2)
51
52 //_____________________________________________________________________________
53 AliMUONSDigitizerV2::AliMUONSDigitizerV2() 
54 : TTask("AliMUONSDigitizerV2","From Hits to SDigits for MUON")
55 {
56   ///
57   /// ctor.
58   ///
59 }
60
61 //_____________________________________________________________________________
62 AliMUONSDigitizerV2::~AliMUONSDigitizerV2()
63 {
64   ///
65   /// dtor.
66   ///
67 }
68
69 //_____________________________________________________________________________
70 void
71 AliMUONSDigitizerV2::Exec(Option_t*)
72 {
73   ///
74   /// Go from hits to sdigits.
75   ///
76   /// In the code below, apart from the loop itself (which look complicated
77   /// but is really only a loop on each hit in the input file) the main
78   /// work is done in AliMUONResponse::DisIntegrate method, which converts
79   /// a single hit in (possibly) several sdigits.
80   ///
81   
82   AliDebug(1,"");
83   
84   AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
85   AliLoader* loader = runLoader->GetDetectorLoader("MUON");
86
87   loader->LoadHits("READ");
88   
89   AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
90     
91   Int_t nofEvents(runLoader->GetNumberOfEvents());
92   
93   AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
94   
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   
104     loader->MakeSDigitsContainer();
105
106     TTree* treeS = loader->TreeS();
107
108     if ( !treeS )
109     {
110       AliFatal("");
111     }
112
113     sDigitStore->Connect(*treeS);
114     
115     TTree* treeH = loader->TreeH();
116
117     AliMUONVHitStore* hitStore = AliMUONVHitStore::Create(*treeH);
118     hitStore->Connect(*treeH);
119     
120     Long64_t nofTracks = treeH->GetEntries();
121     
122     for ( Long64_t iTrack = 0; iTrack < nofTracks; ++iTrack )
123     {
124       // Loop over the tracks of this event.
125       treeH->GetEvent(iTrack);
126
127       AliMUONHit* hit;
128       TIter next(hitStore->CreateIterator());
129       Int_t ihit(0);
130       
131       while ( ( hit = static_cast<AliMUONHit*>(next()) ) )       
132       {
133         Int_t chamberId = hit->Chamber()-1;
134         AliMUONChamber& chamber = muon->Chamber(chamberId);
135         AliMUONResponse* response = chamber.ResponseModel();
136         
137         // This is the heart of this method : the dis-integration
138         TList digits;        
139         response->DisIntegrate(*hit,digits);
140         
141         TIter next(&digits);
142         AliMUONVDigit* d;
143         while ( ( d = (AliMUONVDigit*)next() ) )
144         {
145           // Update some sdigit information that could not be known
146           // by the DisIntegrate method
147           d->SetHit(ihit);
148           d->AddTrack(iTrack,d->Charge());
149           tdlist.Add(d);
150         }
151         ++ihit;
152       }
153       hitStore->Clear();
154     } // end of loop on tracks within an event
155     
156     TIter next(&tdlist);
157     AliMUONVDigit* d;
158     
159     while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
160     {
161       if ( d->Charge() > 0 ) // that check would be better in the disintegrate
162         // method, but to compare with old sdigitizer, it has to be there.
163       {
164         AliMUONVDigit* added = sDigitStore->Add(*d,AliMUONVDigitStore::kMerge);
165         if (!added)
166         {
167           AliError("Could not add digit to digitStore");
168         }
169       }
170     }
171
172     treeS->Fill();
173     
174     loader->WriteSDigits("OVERWRITE");
175     
176     sDigitStore->Clear();
177     
178     loader->UnloadSDigits();
179     
180     delete hitStore;
181     
182   } // loop on events
183   
184   loader->UnloadHits();  
185   
186   delete sDigitStore;
187 }