]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/AliMUONSDigitizerV2.cxx
updated vertex selection
[u/mrichter/AliRoot.git] / MUON / AliMUONSDigitizerV2.cxx
... / ...
CommitLineData
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#include <TParticle.h>
20
21#include "AliMUONSDigitizerV2.h"
22
23#include "AliMUON.h"
24#include "AliMUONChamber.h"
25#include "AliMUONVDigit.h"
26#include "AliMUONHit.h"
27#include "AliMUONVDigitStore.h"
28#include "AliMUONVHitStore.h"
29#include "AliMUONCalibrationData.h"
30#include "AliMUONResponseTrigger.h"
31
32#include "AliMpCDB.h"
33#include "AliMpDEManager.h"
34
35#include "AliLog.h"
36#include "AliCDBManager.h"
37#include "AliLoader.h"
38#include "AliRun.h"
39#include "AliRunLoader.h"
40#include "AliStack.h"
41
42//-----------------------------------------------------------------------------
43/// The sdigitizer performs the transformation from hits (energy deposits by
44/// the transport code) to sdigits (equivalent of charges on pad).
45///
46/// It does so by converting the energy deposit into a charge and then spreading
47/// this charge over several pads, according to the response function (a
48/// Mathieson distribution, basically).
49///
50/// See also AliMUONResponseV0, which is doing the real job (in DisIntegrate
51/// method), while this sdigitizer is just "steering" the process.
52///
53/// Please note that we do *not* merge sdigits after creation, which means
54/// that after sdigitization, a given pad can have several sdigits. This
55/// merging is taken care of later on by the digitizer(V3).
56//-----------------------------------------------------------------------------
57
58ClassImp(AliMUONSDigitizerV2)
59
60//_____________________________________________________________________________
61AliMUONSDigitizerV2::AliMUONSDigitizerV2()
62: TTask("AliMUONSDigitizerV2","From Hits to SDigits for MUON")
63{
64 ///
65 /// ctor.
66 ///
67
68 // Load mapping
69 if ( ! AliMpCDB::LoadMpSegmentation() ) {
70 AliFatal("Could not access mapping from OCDB !");
71 }
72}
73
74//_____________________________________________________________________________
75AliMUONSDigitizerV2::~AliMUONSDigitizerV2()
76{
77 ///
78 /// dtor.
79 ///
80}
81
82//_____________________________________________________________________________
83void
84AliMUONSDigitizerV2::Exec(Option_t*)
85{
86 ///
87 /// Go from hits to sdigits.
88 ///
89 /// In the code below, apart from the loop itself (which look complicated
90 /// but is really only a loop on each hit in the input file) the main
91 /// work is done in AliMUONResponse::DisIntegrate method, which converts
92 /// a single hit in (possibly) several sdigits.
93 ///
94
95 AliDebug(1,"");
96
97 AliRunLoader* runLoader = AliRunLoader::Instance();
98 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
99
100 loader->LoadHits("READ");
101
102 AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
103
104 AliMUONCalibrationData *calibrationData = 0x0;
105
106 if(muon->GetTriggerEffCells()){
107 Int_t runnumber = AliCDBManager::Instance()->GetRun();
108 calibrationData = new AliMUONCalibrationData(runnumber);
109 for (Int_t chamber = 10; chamber < 14; chamber++) {
110 ((AliMUONResponseTrigger *) (muon->Chamber(chamber).ResponseModel()))->InitTriggerEfficiency(calibrationData->TriggerEfficiency()); // Init trigger efficiency
111 }
112 }
113
114 Int_t nofEvents(runLoader->GetNumberOfEvents());
115
116 TString classname = muon->DigitStoreClassName();
117
118 AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(classname.Data());
119
120 if (!sDigitStore)
121 {
122 AliFatal(Form("Could not create digitstore of class %s",classname.Data()));
123 }
124
125 AliDebug(1,Form("Will use digitStore of type %s",sDigitStore->ClassName()));
126
127 for ( Int_t iEvent = 0; iEvent < nofEvents; ++iEvent )
128 {
129 // Loop over events.
130 TObjArray tdlist;
131 tdlist.SetOwner(kTRUE);
132
133 AliDebug(1,Form("iEvent=%d",iEvent));
134 runLoader->GetEvent(iEvent);
135
136 // for pile up studies
137 runLoader->LoadKinematics();
138 AliStack* stack = runLoader->Stack();
139 Int_t nparticles = (Int_t) stack->GetNtrack();
140 float T0=10; // time of the triggered event
141 // loop to find the time of the triggered event (this may change)
142 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle) {
143 float t = stack->Particle(iparticle)->T();
144 if (TMath::Abs(t)<TMath::Abs(T0)) T0 = t;
145 }
146
147 loader->MakeSDigitsContainer();
148
149 TTree* treeS = loader->TreeS();
150
151 if ( !treeS )
152 {
153 AliFatal("");
154 }
155
156 sDigitStore->Connect(*treeS);
157
158 TTree* treeH = loader->TreeH();
159
160 AliMUONVHitStore* hitStore = AliMUONVHitStore::Create(*treeH);
161 hitStore->Connect(*treeH);
162
163 Long64_t nofTracks = treeH->GetEntries();
164
165 for ( Long64_t iTrack = 0; iTrack < nofTracks; ++iTrack )
166 {
167 // Loop over the tracks of this event.
168 treeH->GetEvent(iTrack);
169
170 AliMUONHit* hit;
171 TIter next(hitStore->CreateIterator());
172 Int_t ihit(0);
173
174 while ( ( hit = static_cast<AliMUONHit*>(next()) ) )
175 {
176 Int_t chamberId = hit->Chamber()-1;
177 Float_t age = hit->Age()-T0;
178
179 AliMUONChamber& chamber = muon->Chamber(chamberId);
180 AliMUONResponse* response = chamber.ResponseModel();
181
182 // This is the heart of this method : the dis-integration
183 TList digits;
184 response->DisIntegrate(*hit,digits);
185
186 TIter nextd(&digits);
187 AliMUONVDigit* d;
188 while ( ( d = (AliMUONVDigit*)nextd() ) )
189 {
190 // Update some sdigit information that could not be known
191 // by the DisIntegrate method
192 d->SetHit(ihit);
193 d->SetTime(age);
194 d->AddTrack(hit->GetTrack(),d->Charge());
195 tdlist.Add(d);
196 }
197 ++ihit;
198 }
199 hitStore->Clear();
200 } // end of loop on tracks within an event
201
202 TIter next(&tdlist);
203 AliMUONVDigit* d;
204
205 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
206 {
207 if ( d->Charge() > 0 ) // that check would be better in the disintegrate
208 // method, but to compare with old sdigitizer, it has to be there.
209 {
210 AliMUONVDigit* added = sDigitStore->Add(*d,AliMUONVDigitStore::kMerge);
211 if (!added)
212 {
213 AliError("Could not add digit to digitStore");
214 }
215 }
216 }
217
218 treeS->Fill();
219
220 loader->WriteSDigits("OVERWRITE");
221
222 sDigitStore->Clear();
223
224 loader->UnloadSDigits();
225
226 delete hitStore;
227
228 } // loop on events
229
230 loader->UnloadHits();
231
232 delete sDigitStore;
233
234 if(calibrationData) delete calibrationData;
235}