1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.1.4.2 2000/04/10 11:37:42 kowal2
20 Digits handling in a new data structure
24 //-----------------------------------------------------------------------------
27 // Author: Marian Ivanov
29 // Implementation of class TTPCDigitsH
31 //-----------------------------------------------------------------------------
32 ////////////////////////////////////////////////
33 // Manager class for AliTPCDigitsH //
34 ////////////////////////////////////////////////
38 // other include files follow here
44 #include "AliDisplay.h"
47 #include "TCanvasImp.h"
48 #include "TPaveText.h"
55 //*KEEP,TClonesArray,T=C++.
56 #include "TClonesArray.h"
59 #include "GParticle.h"
61 #include "AliTPCParam.h"
63 #include "AliTPCDigitsH.h"
66 R__EXTERN TSystem * gSystem;
67 R__EXTERN AliRun * gAlice;
71 ClassImp(AliTPCDigitsH)
73 AliTPCDigitsH::AliTPCDigitsH()
77 <img src="gif/TPCDigitsH.gif">
89 fEventN = 0; //event nuber connected to digit tree
101 AliTPCDigitsH::~AliTPCDigitsH()
106 AliTPCDigitsH::AliTPCDigitsH(const AliTPCDigitsH &)
110 AliTPCDigitsH & AliTPCDigitsH::operator = (const AliTPCDigitsH &)
114 void AliTPCDigitsH::SetDParam(AliTPCD * dig)
119 fTPCParam = &(fDParam->GetParam());
128 AliTPCParam *& AliTPCDigitsH::GetParam()
134 void AliTPCDigitsH::CloseFiles()
145 // cout<<"FIN Delete error. Contact autor of root \n";
158 // cout<<"Out Delete error. Contact autor of root \n";
166 Bool_t AliTPCDigitsH::SetIO(const char * inFile, const char* outFile )
168 /// Set input and output file
169 /// control permisions and so on
170 /// if all is OK then set flag fbIOState = kTRUE
174 // important ---- it close previious open file if this file exist
177 if (fin == fout) fout = NULL;
185 // cout<<"Fin Delete error. Contact autor of root \n";
189 // important ---- it close previous open file if this file exist
199 // cout<<"Fout Delete error. Contact autor of root \n";
204 //close the files if exist in root enviroment
205 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject((char*)inFile);
206 if (file) file->Close();
207 file = (TFile*)gROOT->GetListOfFiles()->FindObject((char*)outFile);
208 if (file) file->Close();
209 //if input file is the output file
212 if (gSystem->AccessPathName((char*)inFile, kWritePermission ) == kFALSE)
213 fin = new TFile((char*)inFile,"UPDATE","trees with digits");
216 cout<<"Input file couldn't be open for writing \n";
217 cout<<"Loook if the file exiest or if you have permision to write \n";
228 if (gSystem->AccessPathName((char*)inFile, kReadPermission ) == kFALSE)
229 fin = new TFile((char*)inFile,"UPDATE","trees with digits");
232 cout<<"Input file couldn't be open\n";
233 cout<<"Maybe the file is not open \n";
238 cout<<"Input file couldn't be open\n";
239 cout<<"Probably not root file \n";
244 if (gSystem->AccessPathName((char*)outFile, kWritePermission) == kFALSE)
245 fout = new TFile((char *)outFile,"UPDATE");
247 fout = new TFile((char *)outFile,"NEW");
251 cout<<"Output file couldn't be open\n";
254 //if input and output file is OK set state variable to true
259 Bool_t AliTPCDigitsH::SetEventN(Int_t EventN=0)
263 cout<<"Warning: Input file not open !!! \n";
267 if (EventN>-1) fEventN = EventN;
274 gAlice = (AliRun*) fin->Get("gAlice");
276 cout<<" Warning : AliRun objects not found in input file \n.";
279 gAlice->GetEvent(fEventN);
280 fParticles = gAlice->Particles();
290 Bool_t AliTPCDigitsH::SetTree(Int_t eventn )
294 if ( fbIOState == kFALSE)
296 cout<<"IO files not adjusted \n FIX IT!!!";
300 if (fDParam->SetTree(eventn)==0){
302 cout<<"Input tree doesn't exist !!! \n";
305 fDigits = fDParam->GetArray();
306 ftree = fDParam->GetTree();
311 void AliTPCDigitsH::SetSecRowTime(Int_t sec , Int_t row , Int_t TimeN, Float_t TimeStart, Float_t TimeStop )
316 fTimeStart = TimeStart;
317 fTimeStop = TimeStop;
320 void AliTPCDigitsH::SetParticles(Int_t sec = -1, Int_t row = -1 ,
321 Int_t size1 = 30000,Int_t size2=300,
324 if (sec>0) fsec = sec;
325 if (row>-1) frow =row;
328 // create particles histograms
329 sprintf(s,"Sector %d Row %d\n",fsec,frow);
330 sprintf(sh,"Particles%d_%d",fsec,frow);
331 fHParticles = new TH1F(sh,s,size1,4,size1);
333 sprintf(s,"Sector %d Row %d\n",fsec,frow);
334 sprintf(sh,"All particles%d_%d",fsec,frow);
335 fHAllP = new TH1F(sh,s,200,1,25);
337 sprintf(s,"Sector %d Row %d\n",fsec,frow);
338 sprintf(sh,"Secondary Particles%d_%d",fsec,frow);
339 fHSecondaryP = new TH1F(sh,s,200,1,25);
343 cout<<"Input file not open, open file before \n";
348 Int_t sectors_by_rows=(Int_t)ftree->GetEntries();
349 GParticle * particle;
350 // loop over all sectors and rows
351 for (Int_t n=0; n<sectors_by_rows; n++)
353 if (!ftree->GetEvent(n)) continue;
354 AliTPCdigit *dig=(AliTPCdigit*)fDigits->UncheckedAt(0);
355 if (fsec < dig->fSector) break;
356 if (fsec != dig->fSector) continue;
357 if (frow != dig->fPadRow) continue;
359 Int_t ndigits=fDigits->GetEntriesFast();
360 //loop over all digits in sector pad
361 for (Int_t ndig=0; ndig<ndigits; ndig++)
364 dig=(AliTPCdigit*)fDigits->UncheckedAt(ndig);
365 fHParticles->Fill(dig->fTracks[0]);
366 // get pointer to particle information and fill All and secondary histo
367 particle = (GParticle*) fParticles->UncheckedAt(dig->fTracks[0]);
368 fHAllP->Fill(particle->GetKF());
369 // Int_t id = particle->GetKF();
370 x = (Float_t)particle->GetVx();
371 y = (Float_t)particle->GetVy();
372 if ( (x*x+y*y ) > 1 )
373 fHSecondaryP->Fill(particle->GetKF());
376 fHParticles->Fill(dig->fTracks[1]);
377 particle = (GParticle*) fParticles->UncheckedAt(dig->fTracks[1]);
378 fHAllP->Fill(particle->GetKF());
379 x = (Float_t)particle->GetVx();
380 y = (Float_t)particle->GetVy();
381 if ( (x*x+y*y ) > 1 )
382 fHSecondaryP->Fill(particle->GetKF());
383 fHParticles->Fill(dig->fTracks[2]);
384 particle = (GParticle*) fParticles->UncheckedAt(dig->fTracks[2]);
385 fHAllP->Fill(particle->GetKF());
386 x = (Float_t)particle->GetVx();
387 y = (Float_t)particle->GetVy();
388 if ( (x*x+y*y ) > 1 )
389 fHSecondaryP->Fill(particle->GetKF());
393 //make histogram with multiplicity
397 sprintf(s,"Number of AliDigits over threshold per one track in sector %d Row %d\n (all three most important track recorded)",fsec,frow);
399 sprintf(s,"Number of AliDigits over threshold per sector %d Row %d\n (only most important track)",fsec,frow);
400 sprintf(sh,"His_%d_%d",fsec,frow);
401 fHPartMultiplicity = new TH1F(sh,s,size2,1,size2);
402 for (Int_t i=1;i<size1;i++)
404 Int_t mul=Int_t(fHParticles->GetBinContent(i));
405 if (mul>0) fHPartMultiplicity->Fill(mul);
410 fHParticles->Write();
411 fHPartMultiplicity->Write();
412 //fHSecondaryP->Write();
419 void AliTPCDigitsH::Anal()
421 if (fbIOState == kFALSE)
423 cout<<"Input output problem. \n Do you initialize IO files ? \n";
426 if (fbDigState == kFALSE)
428 cout<<"Input file doesn't enhalt selected tree \n";
433 //if we dont want let histogram in memory then we delete old histogram
434 if ( (fH2Digit) && (fbDelHisto == kTRUE) )
442 // cout<<"Delete error. Contact autor of root \n";
448 sprintf(s,"Sector %d Row %d\n",fsec,frow);
449 sprintf(sh,"h%d_%d",fsec,frow);
451 if ( (fout) && (fbDelHisto == kFALSE) )
453 fH2Digit = (AliH2F *) fout->Get(sh);
454 if (fH2Digit) return;
457 Int_t n_of_pads =fTPCParam->GetNPads(fsec,frow);
459 fH2Digit = new AliH2F(sh, s, fTimeN, fTimeStart, fTimeStop, n_of_pads, 0, n_of_pads-1);
463 cout<<"Input file not open, open file before \n";
468 Int_t sectors_by_rows=(Int_t)ftree->GetEntries();
469 //loop over all sectors and rows
470 for (Int_t n=0; n<sectors_by_rows; n++) {
471 if (!ftree->GetEvent(n)) continue;
472 AliTPCdigit *dig=(AliTPCdigit*)fDigits->UncheckedAt(0);
473 if (fsec < dig->fSector) break;
474 if (fsec != dig->fSector) continue;
475 if (frow != dig->fPadRow) continue;
477 Int_t ndigits=fDigits->GetEntriesFast();
478 //loop over all digits in sector pad
479 for (Int_t ndig=0; ndig<ndigits; ndig++) {
480 dig=(AliTPCdigit*)fDigits->UncheckedAt(ndig);
481 fH2Digit->Fill(dig->fTime,dig->fPad,dig->fSignal);
484 if (fout) fout->cd();
489 void AliTPCDigitsH::Draw(Option_t * opt1 ="cont1" , Option_t * opt2 = "error",
490 Option_t * opt3 = "L" )
501 fcanvas = new TCanvas("dh","Digits Histograms",700,900);
511 // cout<<"Delete error. Contact autor of root \n";
515 fTitle = new TPaveText(0.2,0.96,0.8,0.995);
516 fTitle->AddText("Occupancy calculation for TPC");
519 fpad1 = new TPad("pad1","",0.05,0.7,0.95,0.95,21);
521 fpad2 = new TPad("pad2","",0.05,0.4,0.95,0.65,21);
523 fpad3 = new TPad("pad3","",0.05,0.05,0.95,0.35,21);
527 // pad1->TPaveText::title.SetSize(0.1);
530 fH2DigitBW->Draw(o1);
531 fH2DigitBW->SetXTitle("time bin");
532 fH2DigitBW->SetYTitle("pad number");
535 fH1Occu->Fit("pol0");
539 fH1Occu->SetXTitle("time bin");
540 fH1Occu->SetYTitle("occupancy");
546 fH1Digit->SetXTitle("time bin");
547 fH1Digit->SetYTitle("ADC amplitude ");
552 void AliTPCDigitsH::DeleteHisto(const Text_t *namecycle)
554 if (fout) fout->Delete(namecycle);
557 void AliTPCDigitsH::SetHisto(Int_t pad = 1 )
560 Int_t n_of_pads = fTPCParam->GetNPads(fsec,frow);
561 if (pad > (n_of_pads-1))
563 cout<<"Pad number is greater then actula number of pads in thi row \n";
564 cout<<"Noch einmal \n";
571 // if ( (fH1Digit) && (fbDelHisto == kTRUE))
575 // // delete fH1Digit;
579 // cout<<"Delete error. Contact autor of root \n";
586 sprintf(s,"example sector %d Row %d Pad %d",fsec,frow,fpad);
587 sprintf(sh,"h%d_%d_%d",fsec,frow,fpad);
588 fH2DigitBW = new AliH2F("bw", "", fTimeN, fTimeStart, fTimeStop, n_of_pads, 0, n_of_pads-1);
589 fH1Digit = new TH1F(sh,s,fTimeN,fTimeStart,fTimeStop);
591 for (Int_t i = 0;i<fTimeN;i++)
593 Int_t index = fH2Digit->GetBin(i,pad);
594 Float_t weight = fH2Digit->GetBinContent(index);
595 fH1Digit->Fill(i,weight);
599 sprintf(s,"Occupancy in sector %d Row %d threshold = %d",fsec,frow,fThreshold);
600 sprintf(sh,"hoccu%d_%d_%d",fsec,frow,fpad);
601 fH1Occu = new TH1F(sh,s,fOccuN,fTimeStart,fTimeStop);
603 for (Int_t i = 0;i<fOccuN;i++)
607 for (int itime = i*(fTimeN/fOccuN); itime<(i+1)*(fTimeN/fOccuN);itime++)
609 for (Int_t ipad = 0; ipad < n_of_pads; ipad++)
611 Int_t index = fH2Digit->GetBin(itime,ipad);
612 if ( (ipad>3) && ((ipad+3)<n_of_pads)){
614 if (fH2Digit->GetBinContent(index) >fThreshold) over++ ;
616 if (fH2Digit->GetBinContent(index) >fThreshold)
617 fH2DigitBW->Fill(itime,ipad,1);
619 fH2DigitBW->Fill(itime,ipad,0);
622 Float_t occu = ((Float_t)over) /((Float_t) (all));
623 // Float_t time = ((fTimeStop-fTimeStart)/fOccuN)*i+fTimeStart;
625 fH1Occu->SetBinContent(i,occu);
626 // Int_t index = fH1Occu->GetBin(i);
627 Float_t error = sqrt( ((Float_t) ((over)/25+1)) )/((Float_t)(all)/25.);
628 fH1Occu->SetBinError(i,error);
637 void AliTPCDigitsH::Streamer(TBuffer & R__b)
639 if (R__b.IsReading()) {
640 // Version_t R__v = R__b.ReadVersion();
642 R__b.WriteVersion(AliTPCDigitsH::IsA());