changes for the PWG2 train (M.Chojnacki)
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
2ab0c725 17
4c039060 18
fe4da5cc 19///////////////////////////////////////////////////////////////////////////////
04366a57 20// //
21// An overview of the basic philosophy of the ITS code development //
22// and analysis is show in the figure below. //
23//Begin_Html //
24/*
a92b2b7d 25<img src="picts/ITS/ITS_Analysis_schema.gif">
fe4da5cc 26</pre>
27<br clear=left>
28<font size=+2 color=red>
58005f18 29<p>Roberto Barbera is in charge of the ITS Offline code (1999).
fe4da5cc 30<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
31</font>
32<pre>
33*/
34//End_Html
58005f18 35//
36// AliITS. Inner Traking System base class.
37// This class contains the base procedures for the Inner Tracking System
38//
39//Begin_Html
40/*
a92b2b7d 41<img src="picts/ITS/AliITS_Class_Diagram.gif">
58005f18 42</pre>
43<br clear=left>
44<font size=+2 color=red>
45<p>This show the class diagram of the different elements that are part of
46the AliITS class.
47</font>
48<pre>
49*/
50//End_Html
51//
52// Version: 0
53// Written by Rene Brun, Federico Carminati, and Roberto Barbera
54//
55// Version: 1
56// Modified and documented by Bjorn S. Nilsen
57// July 11 1999
58//
3bd79107 59// Version: 2
60// Modified and documented by A. Bologna
61// October 18 1999
62//
58005f18 63// AliITS is the general base class for the ITS. Also see AliDetector for
64// futher information.
65//
fe4da5cc 66///////////////////////////////////////////////////////////////////////////////
88cb7938 67
143d1056 68#include <stdlib.h>
caf37aec 69#include <TClonesArray.h>
9c74c52b 70#include <TFile.h>
7d62fb64 71#include <TParticle.h>
d5da1ecf 72#include <TString.h>
88cb7938 73#include <TTree.h>
88cb7938 74#include <TVirtualMC.h>
7d62fb64 75#include "AliDetector.h"
3bd79107 76#include "AliITS.h"
7d62fb64 77#include "AliITSDetTypeSim.h"
f77f13c8 78#include "AliITSDDLRawData.h"
88cb7938 79#include "AliITSLoader.h"
88cb7938 80#include "AliITShit.h"
81#include "AliITSmodule.h"
7d62fb64 82#include "AliITSpListItem.h"
83#include "AliITSsimulation.h"
84#include "AliITSsimulationFastPoints.h"
5d12ce38 85#include "AliMC.h"
7d62fb64 86#include "AliITSRecPoint.h"
0b5bf101 87#include "AliITSsegmentationSPD.h"
88#include "AliITSsegmentationSDD.h"
dee45d79 89#include "AliITSsimulationSDD.h"
90#include "AliITSCalibrationSDD.h"
8b3448d3 91#include "AliITSCalibrationSSD.h"
0b5bf101 92#include "AliITSsegmentationSSD.h"
93#include "AliITSRawStreamSPD.h"
94#include "AliITSRawStreamSSD.h"
95#include "AliITSRawStreamSDD.h"
0b5bf101 96#include "AliRawReader.h"
f77f13c8 97#include "AliRun.h"
7d62fb64 98#include "AliLog.h"
ef7ff1f9 99#include "AliITSInitGeometry.h"
ad7f2bfa 100#include "AliITSFOSignalsSPD.h"
828e06c7 101
3bd79107 102ClassImp(AliITS)
3bd79107 103
2aea926d 104//______________________________________________________________________
ed9289c8 105AliITS::AliITS() : AliDetector(),
106fDetTypeSim(0),
107fEuclidOut(0),
108fOpt("All"),
109fIdN(0),
110fIdSens(0),
111fIdName(0),
012f0f4c 112fITSmodules(0),
c8af5b8f 113fTiming(kFALSE),
afbc83e9 114fSimuParam(0),
115fModA(0),
116fpSDigits(0)
ed9289c8 117{
7d62fb64 118 // Default initializer for ITS
119 // The default constructor of the AliITS class. In addition to
120 // creating the AliITS class it zeros the variables fIshunt (a member
121 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
122 // fIdSens, and fIdName. The AliDetector default constructor
123 // is also called.
124
aa044888 125// SetDetectors(); // default to fOpt="All". This variable not written out.
e939a978 126//PH SetMarkerColor(kRed);
fe4da5cc 127}
2aea926d 128//______________________________________________________________________
c8af5b8f 129AliITS::AliITS(const Char_t *title):
130 AliDetector("ITS",title),
131 fDetTypeSim(0),
132 fEuclidOut(0),
133 fOpt("All"),
134 fIdN(0),
135 fIdSens(0),
136 fIdName(0),
137 fITSmodules(0),
138 fTiming(kFALSE),
afbc83e9 139 fSimuParam(0),
140 fModA(0),
141 fpSDigits(0)
012f0f4c 142{
143 // The standard Constructor for the ITS class.
144 // It also zeros the variables
145 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
146 // the pointers fIdSens and fIdName. To help in displaying hits via the
147 // ROOT macro display.C AliITS also sets the marker color to red. The
148 // variables passes with this constructor, const char *name and *title,
149 // are used by the constructor of AliDetector class. See AliDetector
150 // class for a description of these parameters and its constructor
151 // functions.
152 // Inputs:
153 // Char_t *title Simulation title for the ITS
154 // Outputs:
155 // none.
156 // Return:
157 // none.
158
159 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
160 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
161 //fNhits=0; //done in AliDetector(name,title)
162 SetDetectors(); // default to fOpt="All". This variable not written out.
163 fDetTypeSim = new AliITSDetTypeSim();
164 //PH SetMarkerColor(kRed);
165 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
166 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
167}
168//______________________________________________________________________
c8af5b8f 169AliITS::AliITS(const char *name, const char *title):
170 AliDetector(name,title),
171 fDetTypeSim(0),
172 fEuclidOut(0),
173 fOpt("All"),
174 fIdN(0),
175 fIdSens(0),
176 fIdName(0),
177 fITSmodules(0),
178 fTiming(kFALSE),
afbc83e9 179 fSimuParam(0),
180 fModA(0),
181 fpSDigits(0)
ed9289c8 182{
7d62fb64 183 // The standard Constructor for the ITS class.
184 // It also zeros the variables
185 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
186 // the pointers fIdSens and fIdName. To help in displaying hits via the
187 // ROOT macro display.C AliITS also sets the marker color to red. The
188 // variables passes with this constructor, const char *name and *title,
189 // are used by the constructor of AliDetector class. See AliDetector
190 // class for a description of these parameters and its constructor
191 // functions.
192
7d62fb64 193 fHits = new TClonesArray("AliITShit",1560);
194 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
ed9289c8 195 //fNhits=0; //done in AliDetector(name,title)
7d62fb64 196
7d62fb64 197 SetDetectors(); // default to fOpt="All". This variable not written out.
ed9289c8 198
7d62fb64 199 fDetTypeSim = new AliITSDetTypeSim();
e939a978 200 //PH SetMarkerColor(kRed);
023ae34b 201 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
202 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
fe4da5cc 203
3bd79107 204}
2aea926d 205//______________________________________________________________________
58005f18 206AliITS::~AliITS(){
4a5bebc2 207 // Default destructor for ITS.
2aea926d 208 // The default destructor of the AliITS class. In addition to deleting
7d62fb64 209 // the AliITS class it deletes the memory pointed to by
210 // fIdSens, fIdName, fDetTypeSim and it's contents.
4a5bebc2 211 // Inputs:
212 // none.
213 // Outputs:
214 // none.
215 // Return:
216 // none.
023ae34b 217
88cb7938 218 if (fHits) {
219 fHits->Delete();
220 delete fHits;
221 fHits=0;
222 }
88cb7938 223 if(fITSmodules) {
224 this->ClearModules();
225 delete fITSmodules;
279a35d7 226 fITSmodules = 0;
88cb7938 227 }// end if fITSmodules!=0
228
7d62fb64 229 delete[] fIdName; // Array of TStrings
230 delete[] fIdSens;
773af0c4 231 Int_t size = AliITSgeomTGeo::GetNModules();
7d62fb64 232 if (fDetTypeSim){
233 delete fDetTypeSim;
234 fDetTypeSim = 0;
c8af5b8f 235 }
236 if(fSimuParam){
237 delete fSimuParam;
238 fSimuParam=0;
239 }
afbc83e9 240 if(fModA){
241 if(size>0){
242 for(Int_t j=0; j<size; j++){
243 fModA[j]->Delete();
244 delete fModA[j];
245 }
246 }
247 delete []fModA;
248 }
249 if(fpSDigits){
250 fpSDigits->Delete();
251 delete fpSDigits;
252 }
3bd79107 253}
3bd79107 254
2aea926d 255//______________________________________________________________________
256void AliITS::Init(){
4a5bebc2 257 // Initializer ITS after it has been built
2aea926d 258 // This routine initializes the AliITS class. It is intended to be
259 // called from the Init function in AliITSv?. Besides displaying a banner
260 // indicating that it has been called it initializes the array fIdSens
261 // and sets the default segmentation, response, digit and raw cluster
262 // classes therefore it should be called after a call to CreateGeometry.
4a5bebc2 263 // Inputs:
264 // none.
265 // Outputs:
266 // none.
267 // Return:
268 // none.
3bd79107 269 Int_t i;
2aea926d 270 // Array of TStrings
0e73d04c 271 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
7d62fb64 272
3bd79107 273}
2aea926d 274//______________________________________________________________________
275void AliITS::SetDefaults(){
4a5bebc2 276 // sets the default segmentation, response, digit and raw cluster classes.
277 // Inputs:
278 // none.
279 // Outputs:
280 // none.
281 // Return:
282 // none.
023ae34b 283 AliInfoClass("AliITS::Setting Defaults");
7d62fb64 284 if(!fDetTypeSim) {
285 Error("SetDefaults()","fDetTypeSim is 0!");
286 return;
287 }
288
289 fDetTypeSim->SetDefaults();
c8af5b8f 290 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 291
3bd79107 292}
2aea926d 293//______________________________________________________________________
294void AliITS::SetDefaultSimulation(){
4a5bebc2 295 // sets the default simulation.
296 // Inputs:
297 // none.
298 // Outputs:
299 // none.
300 // Return:
301 // none.
7d62fb64 302 if(!fDetTypeSim) {
303 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
304 return;
305 }
306
307 fDetTypeSim->SetDefaultSimulation();
c8af5b8f 308 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
04366a57 309
04366a57 310}
311
312
2aea926d 313//______________________________________________________________________
88cb7938 314void AliITS::MakeBranch(Option_t* option){
2aea926d 315 // Creates Tree branches for the ITS.
4a5bebc2 316 // Inputs:
317 // Option_t *option String of Tree types S,D, and/or R.
318 // const char *file String of the file name where these branches
319 // are to be stored. If blank then these branches
320 // are written to the same tree as the Hits were
321 // read from.
322 // Outputs:
323 // none.
324 // Return:
325 // none.
7d62fb64 326 if(!fDetTypeSim) {
327 Error("MakeBranch","fDetTypeSim is 0!");
328 return;
329 }
04366a57 330
7d62fb64 331 Bool_t cH = (strstr(option,"H")!=0);
332 Bool_t cS = (strstr(option,"S")!=0);
333 Bool_t cD = (strstr(option,"D")!=0);
334
335 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
336 AliDetector::MakeBranch(option);
337
338 if(cS) MakeBranchS(0);
339 if(cD) MakeBranchD(0);
340
341
342}
343//___________________________________________________________________
344void AliITS::MakeBranchS(const char* fl){
345
346 // Creates Tree Branch for the ITS summable digits.
347 // Inputs:
348 // cont char *fl File name where SDigits branch is to be written
349 // to. If blank it write the SDigits to the same
350 // file in which the Hits were found.
351
352
353 if(!fDetTypeSim){
354 Error("MakeBranchS","fDetTypeSim is 0!");
355 }
356 Int_t buffersize = 4000;
0f812aa0 357 char branchname[31];
7d62fb64 358
359 // only one branch for SDigits.
0f812aa0 360 snprintf(branchname,30,"%s",GetName());
7d62fb64 361
362 if(fLoader->TreeS()){
7d62fb64 363 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
364 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
365 }
366}
367//______________________________________________________________________
368void AliITS::MakeBranchD(const char* file){
369
370 //Make branch for digits
371 if(!fDetTypeSim) {
372 Warning("MakeBranchD","fDetTypeSim is 0!");
373 return;
374 }
023ae34b 375 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 376 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 377 MakeBranchInTreeD(fLoader->TreeD(),file);
378}
379
380//___________________________________________________________________
381void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
382 // Creates Tree branches for the ITS.
383
384 if(!fDetTypeSim){
385 Error("MakeBranchS","fDetTypeSim is 0!");
386 }
023ae34b 387 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 388 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 389
390 const Char_t *det[3] = {"SPD","SDD","SSD"};
a6e0ebfe 391 const Char_t* digclass;
7d62fb64 392 Int_t buffersize = 4000;
0f812aa0 393 Char_t branchname[31];
7d62fb64 394
395 if(!fDetTypeSim->GetDigits()){
396 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
397 }
398 for(Int_t i=0;i<fgkNTYPES;i++){
399 digclass = fDetTypeSim->GetDigitClassName(i);
400 TString classn = digclass;
401 if(!((fDetTypeSim->GetDigits())->At(i))){
402 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
403 }
404 else ResetDigits(i);
0f812aa0 405 if(fgkNTYPES==3) snprintf(branchname,30,"%sDigits%s",GetName(),det[i]);
7d62fb64 406 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
407 TObjArray* dig = DigitsAddress(i);
408 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
409 }
2aea926d 410
fe4da5cc 411}
2aea926d 412//______________________________________________________________________
413void AliITS::SetTreeAddress(){
414 // Set branch address for the Trees.
4a5bebc2 415 // Inputs:
416 // none.
417 // Outputs:
418 // none.
419 // Return:
420 // none.
023ae34b 421
7d62fb64 422 if(!fDetTypeSim) {
423 Error("SetTreeAddress","fDetTypeSim is 0!");
424 return;
425 }
426
023ae34b 427 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 428 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 429
430 TTree *treeS = fLoader->TreeS();
431 TTree *treeD = fLoader->TreeD();
432 if (fLoader->TreeH() && (fHits == 0x0)) {
433 fHits = new TClonesArray("AliITShit", 1560);
434 }
435 AliDetector::SetTreeAddress();
436
437 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
438 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
fe4da5cc 439}
2aea926d 440//______________________________________________________________________
2aea926d 441void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
442 // Add an ITS hit
443 // The function to add information to the AliITShit class. See the
444 // AliITShit class for a full description. This function allocates the
445 // necessary new space for the hit information and passes the variable
446 // track, and the pointers *vol and *hits to the AliITShit constructor
447 // function.
4a5bebc2 448 // Inputs:
449 // Int_t track Track number which produced this hit.
450 // Int_t *vol Array of Integer Hit information. See AliITShit.h
451 // Float_t *hits Array of Floating Hit information. see AliITShit.h
452 // Outputs:
453 // none.
454 // Return:
455 // none.
7d62fb64 456 TClonesArray &lhits = *fHits;
457 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
3bd79107 458}
3bd79107 459
2aea926d 460//______________________________________________________________________
755bb5cb 461void AliITS::FillModules(Int_t /* evnt */,Int_t bgrev,Int_t /* nmodules */,
8e8eae84 462 Option_t *option, const char *filename){
7d62fb64 463 // fill the modules with the sorted by module hits; add hits from
464 // background if option=Add.
465
466 static TTree *trH1; //Tree with background hits
467 static Bool_t first=kTRUE;
468 static TFile *file;
469 const char *addBgr = strstr(option,"Add");
470
7d62fb64 471 if (addBgr ) {
472 if(first) {
473 file=new TFile(filename);
474 } // end if first
475 first=kFALSE;
476 file->cd();
477 file->ls();
478 // Get Hits Tree header from file
479 if(trH1) delete trH1;
480 trH1=0;
481
0f812aa0 482 char treeName[21];
483 snprintf(treeName,20,"TreeH%d",bgrev);
7d62fb64 484 trH1 = (TTree*)gDirectory->Get(treeName);
485 if (!trH1) {
486 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
487 } // end if !trH1
488 // Set branch addresses
489 } // end if addBgr
490
491 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
3bd79107 492
7d62fb64 493 if (addBgr ) {
494 FillModules(trH1,10000000); // Default mask 10M.
495 TTree *fAli=fLoader->GetRunLoader()->TreeK();
496 TFile *fileAli=0;
0f812aa0 497 if (fAli) {
498 fileAli =fAli->GetCurrentFile();
499 fileAli->cd();
500 }
7d62fb64 501 } // end if add
502
503
3bd79107 504}
2aea926d 505//______________________________________________________________________
b4012daf 506void AliITS::FillModules(TTree *treeH, Int_t mask) {
507 // fill the modules with the sorted by module hits;
508 // can be called many times to do a merging
509 // Inputs:
510 // TTree *treeH The tree containing the hits to be copied into
511 // the modules.
512 // Int_t mask The track number mask to indecate which file
513 // this hits came from.
514 // Outputs:
515 // none.
516 // Return:
517 // none.
518
88cb7938 519 if (treeH == 0x0)
520 {
0f812aa0 521 AliError("Tree H is NULL");
522 return;
88cb7938 523 }
b4012daf 524 Int_t lay,lad,det,index;
525 AliITShit *itsHit=0;
526 AliITSmodule *mod=0;
0f812aa0 527 char branchname[21];
528 snprintf(branchname,20,"%s",GetName());
b4012daf 529 TBranch *branch = treeH->GetBranch(branchname);
530 if (!branch) {
88cb7938 531 Error("FillModules","%s branch in TreeH not found",branchname);
532 return;
b4012daf 533 } // end if !branch
534 branch->SetAddress(&fHits);
535 Int_t nTracks =(Int_t) treeH->GetEntries();
536 Int_t iPrimTrack,h;
537 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
88cb7938 538 ResetHits();
539 Int_t nBytes = treeH->GetEvent(iPrimTrack);
540 if (nBytes <= 0) continue;
541 Int_t nHits = fHits->GetEntriesFast();
542 for(h=0; h<nHits; h++){
543 itsHit = (AliITShit *)fHits->UncheckedAt(h);
544 itsHit->GetDetectorID(lay,lad,det);
7d62fb64 545 if (GetITSgeom()) {
546 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
88cb7938 547 } else {
548 index=det-1; // This should not be used.
549 } // end if [You must have fITSgeom for this to work!]
550 mod = GetModule(index);
551 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
552 mod->AddHit(itsHit,iPrimTrack,h);
553 } // end loop over hits
b4012daf 554 } // end loop over tracks
555}
7d62fb64 556
b4012daf 557//______________________________________________________________________
6f5308d9 558Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
7d62fb64 559 // Initialize the modules array.
4a5bebc2 560 // Inputs:
7d62fb64 561 // Int_t size Size of array of the number of modules to be
562 // created. If size <=0 then the number of modules
563 // is gotten from AliITSgeom class kept in fITSgeom.
4a5bebc2 564 // Outputs:
7d62fb64 565 // Int_t &nmodules The number of modules existing.
4a5bebc2 566 // Return:
567 // none.
2ab0c725 568
7d62fb64 569 if(fITSmodules){
570 fITSmodules->Delete();
571 delete fITSmodules;
572 } // end fir fITSmoudles
88cb7938 573
7d62fb64 574 if(!fDetTypeSim) {
575 Error("InitModules","fDetTypeSim is null!");
6f5308d9 576 return kFALSE;
7d62fb64 577 }
c8af5b8f 578 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
828e06c7 579
7d62fb64 580 Int_t nl,indexMAX,index;
581
582 if(size<=0){ // default to using data stored in AliITSgeom
583 if(fDetTypeSim->GetITSgeom()==0) {
584 Error("InitModules","fITSgeom not defined");
6f5308d9 585 return kFALSE;
7d62fb64 586 } // end if fITSgeom==0
587 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
588 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
589 nmodules = indexMAX;
590 fITSmodules = new TObjArray(indexMAX);
591 for(index=0;index<indexMAX;index++){
592 fITSmodules->AddAt( new AliITSmodule(index),index);
593 } // end for index
594 }else{
595 fITSmodules = new TObjArray(size);
596 for(index=0;index<size;index++) {
597 fITSmodules->AddAt( new AliITSmodule(index),index);
598 } // end for index
599
600 nmodules = size;
601 } // end i size<=0
6f5308d9 602 return kTRUE;
2aea926d 603}
604//______________________________________________________________________
605void AliITS::Hits2SDigits(){
606 // Standard Hits to summable Digits function.
4a5bebc2 607 // Inputs:
608 // none.
609 // Outputs:
610 // none.
7d62fb64 611
2aea926d 612
7d62fb64 613 if(!fDetTypeSim) {
614 Error("Hits2SDigits","fDetTypeSim is null!");
ad7f2bfa 615 return;
7d62fb64 616 }
617
618 SetDefaults();
619 fLoader->LoadHits("read");
620 fLoader->LoadSDigits("recreate");
621 AliRunLoader* rl = fLoader->GetRunLoader();
023ae34b 622 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 623 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
624
7d62fb64 625 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
aacedc3e 626 // Do the Hits to Digits operation. Use Standard input values.
627 // Event number from file, no background hit merging , use size from
628 // AliITSgeom class, option="All", input from this file only.
7d62fb64 629 rl->GetEvent(iEvent);
630 if (!fLoader->TreeS()) fLoader->MakeTree("S");
631 MakeBranch("S");
632 SetTreeAddress();
633 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
634 } // end for iEvent
88cb7938 635
7d62fb64 636 fLoader->UnloadHits();
637 fLoader->UnloadSDigits();
638
85a5290f 639}
640//______________________________________________________________________
7d62fb64 641void AliITS::Hits2Digits(){
642
643 //Conversion from hits to digits
644 if(!fDetTypeSim) {
645 Error("Hits2SDigits","fDetTypeSim is 0!");
646 return;
647 }
648
023ae34b 649 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 650 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 651 SetDefaults();
652
653 fLoader->LoadHits("read");
654 fLoader->LoadDigits("recreate");
655 AliRunLoader* rl = fLoader->GetRunLoader();
656 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
657 rl->GetEvent(iEvent);
658 if (!fLoader->TreeD()) fLoader->MakeTree("D");
659 MakeBranch("D");
660 SetTreeAddress();
661 HitsToDigits(iEvent,0,-1," ",fOpt," ");
662 }
663
664 fLoader->UnloadHits();
665 fLoader->UnloadDigits();
666
2aea926d 667}
7d62fb64 668
2aea926d 669//______________________________________________________________________
7d62fb64 670void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
671 Option_t *option,Option_t *opt,
672 const char *filename){
673 // Keep galice.root for signal and name differently the file for
674 // background when add! otherwise the track info for signal will be lost !
675 // the condition below will disappear when the geom class will be
676 // initialized for all versions - for the moment it is only for v5 !
677 // 7 is the SDD beam test version.
4a5bebc2 678 // Inputs:
7d62fb64 679 // Int_t evnt Event to be processed.
680 // Int_t bgrev Background Hit tree number.
681 // Int_t nmodules Not used.
682 // Option_t *option String indicating if merging hits or not. To
683 // merge hits set equal to "Add". Otherwise no
684 // background hits are considered.
685 // Test_t *filename File name containing the background hits..
4a5bebc2 686 // Outputs:
687 // none.
7d62fb64 688 // Return:
689 // none.
2aea926d 690
7d62fb64 691 if(!fDetTypeSim) {
692 Error("HitsToDigits","fDetTypeSim is null!");
693 return;
694 }
023ae34b 695 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 696 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 697 if(!GetITSgeom()) return; // need transformations to do digitization.
698 AliITSgeom *geom = GetITSgeom();
85a5290f 699
7d62fb64 700 const char *all = strstr(opt,"All");
701 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
702 strstr(opt,"SSD")};
703 static Bool_t setDef=kTRUE;
704 if (setDef) SetDefaultSimulation();
705 setDef=kFALSE;
706
707 Int_t nmodules;
708 InitModules(size,nmodules);
709 FillModules(evNumber,bgrev,nmodules,option,filename);
ad7f2bfa 710
711 // Reset Fast-OR signals for this event
712 fDetTypeSim->ResetFOSignals();
7d62fb64 713
714 AliITSsimulation *sim = 0;
715 AliITSmodule *mod = 0;
716 Int_t id;
717 for(Int_t module=0;module<geom->GetIndexMax();module++){
718 id = geom->GetModuleType(module);
719 if (!all && !det[id]) continue;
720 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
721 if (!sim) {
722 Error("HitsToDigits","The simulation class was not "
723 "instanciated for module %d type %s!",module,
724 geom->GetModuleTypeName(module));
725 exit(1);
726 } // end if !sim
727 mod = (AliITSmodule *)fITSmodules->At(module);
728 sim->DigitiseModule(mod,module,evNumber);
729 // fills all branches - wasted disk space
730 fLoader->TreeD()->Fill();
731 ResetDigits();
732 } // end for module
733
734 ClearModules();
a0d76912 735
ad7f2bfa 736 // Add random noise to FO signals
737 if (all || det[0]) { // SPD present
738 fDetTypeSim->ProcessNoiseForFastOr();
739 }
740
741 // Add Fast-OR signals to event (only one object per event)
742 if (all || det[0]) { // SPD present
743 fDetTypeSim->WriteFOSignals();
744 }
745
746
7d62fb64 747 fLoader->TreeD()->GetEntries();
748 fLoader->TreeD()->AutoSave();
749 // reset tree
750 fLoader->TreeD()->Reset();
2aea926d 751}
7d62fb64 752//_____________________________________________________________________
753void AliITS::Hits2PreDigits(){
754 // Turn hits into SDigits
755
756 if(!fDetTypeSim) {
757 Error("Hits2SDigits","fDetTypeSim is 0!");
758 return;
759 }
760
023ae34b 761 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 762 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 763 SetDefaults();
764
765 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
766 0,-1," ",fOpt," ");
767}
768
2aea926d 769//______________________________________________________________________
2aea926d 770void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
aacedc3e 771 Option_t *option,Option_t *opt,
772 const char *filename){
4a5bebc2 773 // Keep galice.root for signal and name differently the file for
2aea926d 774 // background when add! otherwise the track info for signal will be lost !
775 // the condition below will disappear when the geom class will be
4a5bebc2 776 // initialized for all versions - for the moment it is only for v5 !
777 // 7 is the SDD beam test version.
778 // Inputs:
779 // Int_t evnt Event to be processed.
780 // Int_t bgrev Background Hit tree number.
781 // Int_t nmodules Not used.
782 // Option_t *option String indicating if merging hits or not. To
783 // merge hits set equal to "Add". Otherwise no
784 // background hits are considered.
785 // Test_t *filename File name containing the background hits..
786 // Outputs:
787 // none.
788 // Return:
789 // none.
2aea926d 790
7d62fb64 791
792 if(!fDetTypeSim) {
793 Error("HitsToPreDigits","fDetTypeSim is null!");
794 return;
795 }
023ae34b 796 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 797 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 798
799 if(!GetITSgeom()){
800 Error("HitsToPreDigits","fGeom is null!");
801 return; // need transformations to do digitization.
802 }
803 AliITSgeom *geom = GetITSgeom();
804
805 const char *all = strstr(opt,"All");
806 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
807 strstr(opt,"SSD")};
808 static Bool_t setDef=kTRUE;
809 if (setDef) SetDefaultSimulation();
810 setDef=kFALSE;
811
812 Int_t nmodules;
813 InitModules(size,nmodules);
814 FillModules(evNumber,bgrev,nmodules,option,filename);
815
816
817 AliITSsimulation *sim = 0;
818 AliITSmodule *mod = 0;
819 Int_t id,module;
820 for(module=0;module<geom->GetIndexMax();module++){
821 id = geom->GetModuleType(module);
822 if (!all && !det[id]) continue;
823 sim = (AliITSsimulation*)GetSimulationModel(id);
824 if (!sim) {
825 Error("HitsToPreDigits","The simulation class was not "
826 "instanciated for module %d type %s!",module,
827 geom->GetModuleTypeName(module));
828 exit(1);
829 } // end if !sim
830 mod = (AliITSmodule *)fITSmodules->At(module);
831 sim->SDigitiseModule(mod,module,evNumber);
832 // fills all branches - wasted disk space
833 fLoader->TreeS()->Fill();
834 fDetTypeSim->ResetSDigits();
835 } // end for module
836
837 ClearModules();
838
839
840 fLoader->TreeS()->GetEntries();
841 fLoader->TreeS()->AutoSave();
842 fLoader->WriteSDigits("OVERWRITE");
843 // reset tree
844 fLoader->TreeS()->Reset();
2aea926d 845}
7d62fb64 846
847//_____________________________________________________________________
848void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
849 Option_t *opt0,Option_t *opt1,
850 const char *flnm){
851 // keep galice.root for signal and name differently the file for
2aea926d 852 // background when add! otherwise the track info for signal will be lost !
853 // the condition below will disappear when the geom class will be
4a5bebc2 854 // initialized for all versions - for the moment it is only for v5 !
4a5bebc2 855 // Inputs:
856 // Int_t evnt Event to be processed.
857 // Int_t bgrev Background Hit tree number.
7d62fb64 858 // Int_t size Size used by InitModules. See InitModules.
859 // Option_t *opt0 Option passed to FillModules. See FillModules.
860 // Option_t *opt1 String indicating if merging hits or not. To
4a5bebc2 861 // merge hits set equal to "Add". Otherwise no
862 // background hits are considered.
7d62fb64 863 // Test_t *flnm File name containing the background hits..
4a5bebc2 864 // Outputs:
865 // none.
866 // Return:
867 // none.
868
04366a57 869
00a7cc50 870
7d62fb64 871 if(!GetITSgeom()){
872 Error("HitsToPreDigits","fGeom is null!");
873 return; // need transformations to do digitization.
874 }
875 AliITSgeom *geom = GetITSgeom();
876
877 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
878
879 const char *all = strstr(opt1,"All");
880 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
881 strstr(opt1,"SSD")};
882 Int_t nmodules;
883 InitModules(size,nmodules);
884 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
885
886 AliITSsimulation *sim = 0;
887 AliITSmodule *mod = 0;
888 Int_t id,module;
889
890 TTree *lTR = pITSloader->TreeR();
00a7cc50 891 if(!lTR) {
892 pITSloader->MakeTree("R");
893 lTR = pITSloader->TreeR();
894 }
895
7d62fb64 896 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 897 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
898 branch->SetAddress(&ptarray);
7d62fb64 899 //m.b. : this change is nothing but a nice way to make sure
023ae34b 900 //the CPU goes up !
7d62fb64 901 for(module=0;module<geom->GetIndexMax();module++){
902 id = geom->GetModuleType(module);
903 if (!all && !det[id]) continue;
904 sim = (AliITSsimulation*)GetSimulationModel(id);
905 if (!sim) {
906 Error("HitsToFastPoints","The simulation class was not "
a5a317a9 907 "instantiated for module %d type %s!",module,
7d62fb64 908 geom->GetModuleTypeName(module));
909 exit(1);
910 } // end if !sim
911 mod = (AliITSmodule *)fITSmodules->At(module);
912 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
913 lTR->Fill();
f1bfe73f 914 ptarray->Clear();
7d62fb64 915 } // end for module
916
917 ClearModules();
918 fLoader->WriteRecPoints("OVERWRITE");
919 delete ptarray;
2aea926d 920}
7d62fb64 921//_____________________________________________________________________
922Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
923 //------------------------------------------------------------
924 // This function creates ITS clusters
925 //------------------------------------------------------------
926 if(!GetITSgeom()){
927 Error("HitsToPreDigits","fGeom is null!");
928 return 1; // need transformations to do digitization.
929 }
930 AliITSgeom *geom=GetITSgeom();
931 Int_t mmax=geom->GetIndexMax();
932
933 InitModules(-1,mmax);
934 FillModules(hTree,0);
935
7d62fb64 936 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 937 TBranch *branch=cTree->GetBranch("ITSRecPoints");
938 if (!branch) cTree->Branch("ITSRecPoints",&points);
939 else branch->SetAddress(&points);
7d62fb64 940
941 AliITSsimulationFastPoints sim;
942 Int_t ncl=0;
943 for (Int_t m=0; m<mmax; m++) {
944 AliITSmodule *mod=GetModule(m);
945 sim.CreateFastRecPoints(mod,m,gRandom,points);
00a7cc50 946 ncl+=points->GetEntriesFast();
7d62fb64 947 cTree->Fill();
7d62fb64 948 points->Clear();
949 }
950
15e6a32c 951 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
7d62fb64 952
953 //cTree->Write();
954
7d62fb64 955 delete points;
956 return 0;
957}
7d62fb64 958
7d62fb64 959//_____________________________________________________________________
960void AliITS::CheckLabels(Int_t lab[3]) const {
961 //------------------------------------------------------------
962 // Tries to find mother's labels
963 //------------------------------------------------------------
964
965 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
966
967 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
968 for (Int_t i=0;i<3;i++){
969 Int_t label = lab[i];
970 if (label>=0 && label<ntracks) {
971 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
972 if (part->P() < 0.005) {
973 Int_t m=part->GetFirstMother();
974 if (m<0) {
975 continue;
976 }
977 if (part->GetStatusCode()>0) {
978 continue;
979 }
980 lab[i]=m;
981 }
982 }
983 }
984
985}
986
987//______________________________________________________________________
988void AliITS::SDigitsToDigits(Option_t *opt){
ad7f2bfa 989 // Standard Summable digits to Digits function.
990 // Inputs:
991 // none.
992 // Outputs:
993 // none.
994 if (!fDetTypeSim) {
995 AliError("fDetTypeSim is 0!");
996 return;
997 }
7d62fb64 998
ad7f2bfa 999 const char *all = strstr(opt,"All");
1000 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1001 strstr(opt,"SSD")};
1002
1003 // Reset Fast-OR signals for this event
1004 fDetTypeSim->ResetFOSignals();
1005
1006 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1007 SetDefaults();
c8af5b8f 1008 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
ad7f2bfa 1009 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1010
1011 // Add random noise to FO signals
1012 if (all || det[0]) { // SPD present
1013 fDetTypeSim->ProcessNoiseForFastOr();
1014 }
1015 // Add Fast-OR signals to event (only one object per event)
1016 if (all || det[0]) { // SPD present
1017 fDetTypeSim->WriteFOSignals();
1018 }
7d62fb64 1019}
1020
2aea926d 1021//______________________________________________________________________
2aea926d 1022void AliITS::ResetDigits(){
4a5bebc2 1023 // Reset number of digits and the digits array for the ITS detector.
1024 // Inputs:
1025 // none.
1026 // Outputs:
1027 // none.
7d62fb64 1028 if(!fDetTypeSim) {
1029 Error("ResetDigits","fDetTypeSim is 0!");
1030 return;
1031 }
1032
1033 fDetTypeSim->ResetDigits();
3bd79107 1034
1035
2aea926d 1036}
1037//______________________________________________________________________
7d62fb64 1038void AliITS::ResetDigits(Int_t branch){
4a5bebc2 1039 // Reset number of digits and the digits array for this branch.
1040 // Inputs:
1041 // none.
1042 // Outputs:
1043 // none.
828e06c7 1044
7d62fb64 1045 if(!fDetTypeSim) {
1046 Error("ResetDigits","fDetTypeSim is 0!");
1047 return;
1048 }
1049
1050 fDetTypeSim->ResetDigits(branch);
1051
2aea926d 1052}
1053//______________________________________________________________________
1054void AliITS::AddSumDigit(AliITSpListItem &sdig){
4a5bebc2 1055 // Adds the a module full of summable digits to the summable digits tree.
1056 // Inputs:
1057 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1058 // Outputs:
1059 // none.
1060 // Return:
1061 // none.
828e06c7 1062
7d62fb64 1063 if(!fDetTypeSim) {
1064 Error("AddSumDigit","fDetTypeSim is 0!");
1065 return;
1066 }
1067 fDetTypeSim->AddSumDigit(sdig);
1068
828e06c7 1069}
2aea926d 1070//______________________________________________________________________
7d62fb64 1071void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
4a5bebc2 1072 // Add a simulated digit.
1073 // Inputs:
1074 // Int_t id Detector type number.
1075 // AliITSdigit *d Digit to be added to the Digits Tree. See
1076 // AliITSdigit.h
1077 // Outputs:
1078 // none.
1079 // Return:
1080 // none.
2aea926d 1081
7d62fb64 1082 if(!fDetTypeSim) {
1083 Error("AddSimDigit","fDetTypeSim is 0!");
1084 return;
1085 }
1086 fDetTypeSim->AddSimDigit(branch,d);
1087
2aea926d 1088}
1089//______________________________________________________________________
7d62fb64 1090void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
83ec5e27 1091 Int_t *hits,Float_t *charges, Int_t sigexpanded){
7f1a504b 1092 // Add a simulated digit to the list.
1093 // Inputs:
1094 // Int_t id Detector type number.
1095 // Float_t phys Physics indicator. See AliITSdigits.h
1096 // Int_t *digits Integer array containing the digits info. See
1097 // AliITSdigit.h
1098 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1099 // containing the track numbers that contributed to
1100 // this digit.
1101 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1102 // containing the hit numbers, from AliITSmodule, that
1103 // contributed to this digit.
1104 // Float_t *charge Floating point array of the signals contributed
1105 // to this digit by each track.
1106 // Outputs:
1107 // none.
1108 // Return:
1109 // none.
2aea926d 1110
7d62fb64 1111 if(!fDetTypeSim) {
1112 Error("AddSimDigit","fDetTypeSim is 0!");
1113 return;
1114 }
83ec5e27 1115 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
7d62fb64 1116
2aea926d 1117}
0421c3d1 1118//______________________________________________________________________
aacedc3e 1119void AliITS::Digits2Raw(){
1120 // convert digits of the current event to raw data
0421c3d1 1121
7d62fb64 1122 if(!fDetTypeSim) {
1123 Error("Digits2Raw","fDetTypeSim is 0!");
1124 return;
1125 }
023ae34b 1126 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
7d62fb64 1127 SetDefaults();
c8af5b8f 1128 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 1129 fDetTypeSim->GetLoader()->LoadDigits();
1130 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
0421c3d1 1131 if (!digits) {
aacedc3e 1132 Error("Digits2Raw", "no digits tree");
1133 return;
0421c3d1 1134 }
7d62fb64 1135 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
ad7f2bfa 1136
1137 // Get the FO signals for this event
1138 AliITSFOSignalsSPD* foSignals = NULL;
1139 AliRunLoader* runLoader = AliRunLoader::Instance();
1140 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1141 if (!itsLoader) {
1142 AliError("ITS loader is NULL.");
1143 }
a0d76912 1144 else {
1145 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1146 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1147 if(!foSignals) AliError("FO signals not retrieved");
1148 }
1149
ad7f2bfa 1150 Bool_t deleteFOsignalsLater = kFALSE;
1151 if (!foSignals) {
1152 AliError("FO signals not available. No FO bits will be written.");
1153 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1154 deleteFOsignalsLater = kTRUE;
1155 }
1156
1157
979b5a5f 1158 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
d9ed1779 1159 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
0421c3d1 1160 AliITSDDLRawData rawWriter;
d9ed1779 1161
1162 rawWriter.SetSDDRawFormat(rawSDD);
0421c3d1 1163 //Verbose level
1164 // 0: Silent
1165 // 1: cout messages
1166 // 2: txt files with digits
1167 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1168 //it is highly suggested to use this mode only for debugging digits files
1169 //reasonably small, because otherwise the size of the txt files can reach
1170 //quickly several MB wasting time and disk space.
1171 rawWriter.SetVerbose(0);
1172
1173 //SILICON PIXEL DETECTOR
15e6a32c 1174 AliDebug(1,"Formatting raw data for SPD");
ad7f2bfa 1175 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1176 if(deleteFOsignalsLater) delete foSignals;
0421c3d1 1177
1178 //SILICON DRIFT DETECTOR
d9ed1779 1179 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
979b5a5f 1180 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
0421c3d1 1181
1182 //SILICON STRIP DETECTOR
15e6a32c 1183 AliDebug(1,"Formatting raw data for SSD");
0421c3d1 1184 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1185
1186 fLoader->UnloadDigits();
2aea926d 1187}
04366a57 1188//______________________________________________________________________
aacedc3e 1189AliLoader* AliITS::MakeLoader(const char* topfoldername){
1190 //builds ITSgetter (AliLoader type)
1191 //if detector wants to use castomized getter, it must overload this method
1192
64f311fe 1193 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1194 topfoldername));
aacedc3e 1195 fLoader = new AliITSLoader(GetName(),topfoldername);
1196 return fLoader;
2aea926d 1197}
ad7f2bfa 1198//______________________________________________________________________
0b5bf101 1199Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1200{
1201 //
1202 // Converts RAW data to SDigits
1203 //
1204 // Get TreeS
1205 //
afbc83e9 1206 Int_t last = -1;
773af0c4 1207 Int_t size = AliITSgeomTGeo::GetNModules();
afbc83e9 1208 if(!fModA) {
1209 fModA = new TClonesArray*[size];
1210 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1211 }
1212 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1213 if (!loader){
1214 Error("Open","Can not get ITS loader from Run Loader");
1215 return kFALSE;
1216 }
0b5bf101 1217
afbc83e9 1218 TTree* tree = 0;
1219 tree = loader->TreeS();
1220 if (!tree){
1221 loader->MakeTree("S");
0b5bf101 1222 tree = loader->TreeS();
afbc83e9 1223 }
1224 //
1225 // Array for SDigits
1226 //
1227 if(!fpSDigits){
1228 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1229 }
1230 TClonesArray& aSDigits = *fpSDigits;
1231 Int_t bufsize = 32000;
1232 tree->Branch("ITS", &fpSDigits, bufsize);
1233 Int_t npx = 0;
1234 //
1235 // SPD
1236 //
1237 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1238 if(!segSPD){
1239 AliWarning("Set AliITS defaults");
1240 SetDefaults();
1241 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1242 }
1243 npx = segSPD->Npx();
1244 Double_t thr, sigma;
0b5bf101 1245
afbc83e9 1246 AliITSRawStreamSPD inputSPD(rawReader);
1247 while(1){
1248 Bool_t next = inputSPD.Next();
1249 if (!next) break;
0b5bf101 1250
afbc83e9 1251 Int_t module = inputSPD.GetModuleID();
1252 Int_t column = inputSPD.GetColumn();
1253 Int_t row = inputSPD.GetRow();
1254 Int_t index = npx * column + row;
0b5bf101 1255
afbc83e9 1256 if (module >= size) continue;
0b5bf101 1257
afbc83e9 1258 last = (fModA[module])->GetEntries();
1259 TClonesArray& dum = *fModA[module];
1260 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1261 thr += 1.;
1262 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1263 }
1264 rawReader->Reset();
1265
1266 //
1267 // SDD
1268 //
1269 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1270 npx = segSDD->Npx();
1271 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1272 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1273 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1274
1275 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1276 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1277 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1278 Bool_t isZeroSupp=cal->GetZeroSupp();
1279 if(isZeroSupp){
1280 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1281 }else{
1282 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
dee45d79 1283 }
afbc83e9 1284 }
dee45d79 1285
afbc83e9 1286 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1287 inputSDD->SetDDLModuleMap(ddlmap);
1288 while(inputSDD->Next()){
1289 if(inputSDD->IsCompletedModule()==kFALSE &&
1290 inputSDD->IsCompletedDDL()==kFALSE){
1291
1292 Int_t module = inputSDD->GetModuleID();
1293 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1294 Int_t time = inputSDD->GetCoord2();
1295 Int_t signal10 = inputSDD->GetSignal();
1296 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1297
1298 if (module >= size) continue;
1299 last = fModA[module]->GetEntries();
1300 TClonesArray& dum = *fModA[module];
1301 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1302 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
0b5bf101 1303 }
afbc83e9 1304 }
1305 delete inputSDD;
1306 rawReader->Reset();
a4998655 1307
afbc83e9 1308 //
1309 // SSD
1310 //
1311 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1312 npx = segSSD->Npx();
1313 AliITSRawStreamSSD inputSSD(rawReader);
1314 while(1){
1315 Bool_t next = inputSSD.Next();
1316 if (!next) break;
1317
1318 Int_t module = inputSSD.GetModuleID();
773af0c4 1319 if(module<0)AliError(Form("Invalid SSD module %d \n",module));
1320 if(module<0)continue;
afbc83e9 1321 Int_t side = inputSSD.GetSideFlag();
1322 Int_t strip = inputSSD.GetStrip();
1323 Int_t signal = inputSSD.GetSignal();
1324 Int_t index = npx * side + strip;
1325
1326 if (module >= size) continue;
0b5bf101 1327
afbc83e9 1328 last = fModA[module]->GetEntries();
1329 TClonesArray& dum = *fModA[module];
1330 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1331 }
1332 rawReader->Reset();
1333 AliITSpListItem* sdig = 0;
0b5bf101 1334
afbc83e9 1335 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1336 Double_t adcToEv = 1.;
1337 for (Int_t mod = 0; mod < size; mod++)
1338 {
8b3448d3 1339 if(mod>=firstssd) {
1340 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1341 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1342 }
afbc83e9 1343 Int_t nsdig = fModA[mod]->GetEntries();
8b3448d3 1344 for (Int_t ie = 0; ie < nsdig; ie++) {
afbc83e9 1345 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
463ae357 1346 Double_t digsig = sdig->GetSignal();
8b3448d3 1347 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1348 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
afbc83e9 1349 Float_t sig = sdig->GetSignalAfterElect();
1350 if(mod>=firstssd) sig*=adcToEv;
1351 if (sig > 0.) {
1352 sdig = (AliITSpListItem*)aSDigits[ie];
1353 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
0b5bf101 1354 }
afbc83e9 1355 }
0b5bf101 1356
afbc83e9 1357 tree->Fill();
1358 aSDigits.Clear();
1359 fModA[mod]->Clear();
0b5bf101 1360 }
afbc83e9 1361 loader->WriteSDigits("OVERWRITE");
1362 return kTRUE;
0b5bf101 1363}
1364
ef7ff1f9 1365//______________________________________________________________________
1366void AliITS::UpdateInternalGeometry(){
ed9289c8 1367 //reads new geometry from TGeo
012f0f4c 1368// AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1369
108bd0fe 1370 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1371 Int_t minor = 0;
012f0f4c 1372 AliITSInitGeometry initgeom;
1373 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
ef7ff1f9 1374 SetITSgeom(geom);
ef7ff1f9 1375}
ad7f2bfa 1376//______________________________________________________________________
1377AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1378 // create an AliITSTrigger object (and set trigger conditions as input)
1379 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1380}