]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSDigitizerV2.cxx
TOF PID: possibility to know the detector giving the event time measurement (F. Nofer...
[u/mrichter/AliRoot.git] / MUON / AliMUONSDigitizerV2.cxx
CommitLineData
60d3a1d3 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
7ca4655f 18#include <TClonesArray.h>
9da52a4f 19#include <TParticle.h>
7ca4655f 20
60d3a1d3 21#include "AliMUONSDigitizerV2.h"
22
60d3a1d3 23#include "AliMUON.h"
24#include "AliMUONChamber.h"
445096c0 25#include "AliMUONVDigit.h"
60d3a1d3 26#include "AliMUONHit.h"
5ee595ac 27#include "AliMUONVDigitStore.h"
445096c0 28#include "AliMUONVHitStore.h"
7d7d22a6 29#include "AliMUONCalibrationData.h"
30#include "AliMUONResponseTrigger.h"
2a5f75ae 31#include "AliMUONConstants.h"
7d7d22a6 32
a55f49a0 33#include "AliMpCDB.h"
34#include "AliMpDEManager.h"
35
36#include "AliLog.h"
37#include "AliCDBManager.h"
38#include "AliLoader.h"
39#include "AliRun.h"
40#include "AliRunLoader.h"
e41d0a3c 41
42#include "AliHeader.h"
43#include "AliGenCocktailEventHeader.h"
a55f49a0 44
3d1463c8 45//-----------------------------------------------------------------------------
ae6eeca4 46/// The sdigitizer performs the transformation from hits (energy deposits by
47/// the transport code) to sdigits (equivalent of charges on pad).
48///
49/// It does so by converting the energy deposit into a charge and then spreading
50/// this charge over several pads, according to the response function (a
51/// Mathieson distribution, basically).
52///
53/// See also AliMUONResponseV0, which is doing the real job (in DisIntegrate
54/// method), while this sdigitizer is just "steering" the process.
55///
56/// Please note that we do *not* merge sdigits after creation, which means
57/// that after sdigitization, a given pad can have several sdigits. This
58/// merging is taken care of later on by the digitizer(V3).
3d1463c8 59//-----------------------------------------------------------------------------
ae6eeca4 60
60d3a1d3 61ClassImp(AliMUONSDigitizerV2)
62
2a5f75ae 63Float_t AliMUONSDigitizerV2::fgkMaxIntTime = 10.0;
64Float_t AliMUONSDigitizerV2::fgkMaxPosTimeDif = 1.22E-6;
65Float_t AliMUONSDigitizerV2::fgkMaxNegTimeDif = -3.5E-6;
66Float_t AliMUONSDigitizerV2::fgkMinTimeDif = 25E-9;
67
60d3a1d3 68//_____________________________________________________________________________
69AliMUONSDigitizerV2::AliMUONSDigitizerV2()
70: TTask("AliMUONSDigitizerV2","From Hits to SDigits for MUON")
71{
71a2d3aa 72 ///
73 /// ctor.
74 ///
a55f49a0 75
76 // Load mapping
77 if ( ! AliMpCDB::LoadMpSegmentation() ) {
88544f7e 78 AliFatal("Could not access mapping from OCDB !");
79 }
60d3a1d3 80}
81
82//_____________________________________________________________________________
83AliMUONSDigitizerV2::~AliMUONSDigitizerV2()
84{
71a2d3aa 85 ///
86 /// dtor.
87 ///
60d3a1d3 88}
89
90//_____________________________________________________________________________
91void
92AliMUONSDigitizerV2::Exec(Option_t*)
93{
71a2d3aa 94 ///
95 /// Go from hits to sdigits.
96 ///
97 /// In the code below, apart from the loop itself (which look complicated
98 /// but is really only a loop on each hit in the input file) the main
99 /// work is done in AliMUONResponse::DisIntegrate method, which converts
100 /// a single hit in (possibly) several sdigits.
101 ///
60d3a1d3 102
103 AliDebug(1,"");
104
33c3c91a 105 AliRunLoader* runLoader = AliRunLoader::Instance();
445096c0 106 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
60d3a1d3 107
445096c0 108 loader->LoadHits("READ");
60d3a1d3 109
60d3a1d3 110 AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
7d7d22a6 111
112 AliMUONCalibrationData *calibrationData = 0x0;
113
114 if(muon->GetTriggerEffCells()){
115 Int_t runnumber = AliCDBManager::Instance()->GetRun();
116 calibrationData = new AliMUONCalibrationData(runnumber);
117 for (Int_t chamber = 10; chamber < 14; chamber++) {
118 ((AliMUONResponseTrigger *) (muon->Chamber(chamber).ResponseModel()))->InitTriggerEfficiency(calibrationData->TriggerEfficiency()); // Init trigger efficiency
119 }
120 }
121
ae6eeca4 122 Int_t nofEvents(runLoader->GetNumberOfEvents());
445096c0 123
5ee595ac 124 TString classname = muon->DigitStoreClassName();
445096c0 125
5ee595ac 126 AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(classname.Data());
127
128 if (!sDigitStore)
129 {
130 AliFatal(Form("Could not create digitstore of class %s",classname.Data()));
131 }
132
68cf1410 133 AliDebug(1,Form("Will use digitStore of type %s",sDigitStore->ClassName()));
5ee595ac 134
2a5f75ae 135 // average arrival time to chambers, for pileup studies
136
60d3a1d3 137 for ( Int_t iEvent = 0; iEvent < nofEvents; ++iEvent )
138 {
2c6e3e30 139 // Loop over events.
60d3a1d3 140 TObjArray tdlist;
141 tdlist.SetOwner(kTRUE);
142
143 AliDebug(1,Form("iEvent=%d",iEvent));
144 runLoader->GetEvent(iEvent);
445096c0 145
9da52a4f 146 // for pile up studies
9ee1d6ff 147 float t0=fgkMaxIntTime; int aa=0;
e41d0a3c 148 AliHeader* header = runLoader->GetHeader();
149 AliGenCocktailEventHeader* cocktailHeader =
150 dynamic_cast<AliGenCocktailEventHeader*>(header->GenEventHeader());
151 if (cocktailHeader) {
152 AliGenCocktailEventHeader* genEventHeader = (AliGenCocktailEventHeader*) (header->GenEventHeader());
153 TList* headers = genEventHeader->GetHeaders();
154 TIter nextH(headers);
155 AliGenEventHeader *entry;
156 while((entry = (AliGenEventHeader*)nextH())) {
157 float t = entry->InteractionTime();
9ee1d6ff 158 if (TMath::Abs(t)<TMath::Abs(t0)) t0 = t;
159 aa++;
e41d0a3c 160 }
161 } else {
162 AliGenEventHeader* evtHeader =
163 (AliGenEventHeader*)(header->GenEventHeader());
164 float t = evtHeader->InteractionTime();
9ee1d6ff 165 if (TMath::Abs(t)<TMath::Abs(t0)) t0 = t;
166 aa++;
9da52a4f 167 }
168
445096c0 169 loader->MakeSDigitsContainer();
170
171 TTree* treeS = loader->TreeS();
172
60d3a1d3 173 if ( !treeS )
174 {
445096c0 175 AliFatal("");
60d3a1d3 176 }
445096c0 177
178 sDigitStore->Connect(*treeS);
179
180 TTree* treeH = loader->TreeH();
181
182 AliMUONVHitStore* hitStore = AliMUONVHitStore::Create(*treeH);
183 hitStore->Connect(*treeH);
60d3a1d3 184
60d3a1d3 185 Long64_t nofTracks = treeH->GetEntries();
445096c0 186
60d3a1d3 187 for ( Long64_t iTrack = 0; iTrack < nofTracks; ++iTrack )
188 {
2c6e3e30 189 // Loop over the tracks of this event.
60d3a1d3 190 treeH->GetEvent(iTrack);
445096c0 191
192 AliMUONHit* hit;
193 TIter next(hitStore->CreateIterator());
194 Int_t ihit(0);
195
196 while ( ( hit = static_cast<AliMUONHit*>(next()) ) )
60d3a1d3 197 {
2a5f75ae 198 Int_t chamberId = hit->Chamber()-1;
9ee1d6ff 199 Float_t age = hit->Age()-t0;
ea232c10 200
60d3a1d3 201 AliMUONChamber& chamber = muon->Chamber(chamberId);
202 AliMUONResponse* response = chamber.ResponseModel();
2c6e3e30 203
204 // This is the heart of this method : the dis-integration
205 TList digits;
9ee1d6ff 206 if (aa>1){ // if there are pileup events
2a5f75ae 207 Float_t chamberTime = AliMUONConstants::AverageChamberT(chamberId);
208 Float_t timeDif=age-chamberTime;
209 if (timeDif>fgkMaxPosTimeDif || timeDif<fgkMaxNegTimeDif) {
210 continue;
211 }
212 if(TMath::Abs(timeDif)>fgkMinTimeDif){
213 response->DisIntegrate(*hit,digits,timeDif);
214 }
215 else{
216 response->DisIntegrate(*hit,digits,0.);
217 }
218 }
219 else{
220 response->DisIntegrate(*hit,digits,0.);
221 }
2c6e3e30 222
bf0d3528 223 TIter nextd(&digits);
445096c0 224 AliMUONVDigit* d;
bf0d3528 225 while ( ( d = (AliMUONVDigit*)nextd() ) )
60d3a1d3 226 {
2c6e3e30 227 // Update some sdigit information that could not be known
228 // by the DisIntegrate method
60d3a1d3 229 d->SetHit(ihit);
ea232c10 230 d->SetTime(age);
2e2d0c44 231 d->AddTrack(hit->GetTrack(),d->Charge());
60d3a1d3 232 tdlist.Add(d);
233 }
445096c0 234 ++ihit;
60d3a1d3 235 }
445096c0 236 hitStore->Clear();
2c6e3e30 237 } // end of loop on tracks within an event
238
445096c0 239 TIter next(&tdlist);
240 AliMUONVDigit* d;
241
242 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
60d3a1d3 243 {
445096c0 244 if ( d->Charge() > 0 ) // that check would be better in the disintegrate
60d3a1d3 245 // method, but to compare with old sdigitizer, it has to be there.
246 {
445096c0 247 AliMUONVDigit* added = sDigitStore->Add(*d,AliMUONVDigitStore::kMerge);
248 if (!added)
249 {
250 AliError("Could not add digit to digitStore");
251 }
60d3a1d3 252 }
253 }
445096c0 254
255 treeS->Fill();
256
257 loader->WriteSDigits("OVERWRITE");
258
259 sDigitStore->Clear();
260
261 loader->UnloadSDigits();
262
263 delete hitStore;
2c6e3e30 264
60d3a1d3 265 } // loop on events
266
445096c0 267 loader->UnloadHits();
268
269 delete sDigitStore;
7d7d22a6 270
271 if(calibrationData) delete calibrationData;
60d3a1d3 272}