HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoPedMgr.cxx
Go to the documentation of this file.
1 //
4 //
6 //
8 
9 #include <iostream>
10 #include "TBranch.h"
11 #include "HarpoPedMgr.h"
12 #include "HarpoPedsRaw.h"
13 
14 // Constructor
16 {
17  fn = NULL;
18  f = 0;
19 }
20 
21 // Distructor
23 {
24  // we will not distroy pointer to pedistal hire
25  // will be distroed in Run Header
26  // if ( f != 0 ) f->Close();
27 }
28 
29 // Open Femimos Pedistal File
30 void HarpoPedMgr::SetFile(TString * file)
31 {
32  std::cout << "HarpoPedMgr::SetFile " << *file << std::endl;
33  fn = file->Data();
34 }
35 
36 // Serach pedestal and means for given plane
37 HarpoPedestal * HarpoPedMgr::Lookup(Long_t run, Long_t detno)
38 {
39  p = new HarpoPedestal(); // Default values
40 
41  if (f == 0) { // Not Opened ?
42  f = TFile::Open(fn);
43  }
44 
45  if (f == 0) return p; // Open errorr, no ped file
46 
47  HarpoPedsRaw *praw = new HarpoPedsRaw();
48  std::cout << "Lookup " << run << " plane " << detno << " in file " << fn << " (" << f << ")" << std::endl;
49  // f->ls();
50 
51  TTree * t = (TTree *) f->Get("PedsRaw");
52  std::cout << "TTree at " << t << std::endl;
53  t->ResetBranchAddresses();
54 
55  TBranch *brunno = t->GetBranch("nRun");
56  TBranch *bpraw = t->GetBranch("PedsRaw");
57  bpraw->SetAddress(&praw);
58 
59  Int_t nevent = t->GetEntries();
60  std::cout << "N entries "<< nevent << std::endl;
61 
62  for (Int_t i=0;i<nevent;i++) {
63  brunno->GetEvent(i);
64 
65  if (praw->nRun != run) continue;
66  //std::cout << "Run found " << std::endl;
67 
68  t->GetEvent(i);
69  if ( praw->Plane != detno ) continue;
70  //std::cout << "plane found " << std::endl;
71  // Found
72  p->SetPeds(praw->Mean,praw->Sigma);
73  break;
74  }
75  delete f;
76  f=0;
77  delete praw;
78  return p;
79 }
80 
81 
82 // Write on run pedestals to file
84  Int_t plane, Int_t card)
85 {
86 
87  const char *pedfile = "pedsraw.root";
88  HarpoPedsRaw s;
89  s.Clear();
90  s.nRun = run;
91 
92  s.Plane = plane;
93  s.Pass = 1;
94  //?? s.CardNo = 1;
95  s.CardNo = card;
96  s.Pass = 1;
97  for (UInt_t i=0; i < ptr->GetPedLen(); i++) {
98  s.Mean[i] = ptr->GetPed(i);
99  s.Sigma[i] = ptr->GetSigma(i);
100  }
101  //Make a tree
102  TFile f1(pedfile,"RECREATE");
103  TTree *t = new TTree("PedsRaw","Harpo Raw Pedestal Tree");
104  // Create branches in the tree
105  t->Branch("PedsRaw",&s);
106 
107  t->Fill();
108  //Close root file
109  f1.Write();
110  f1.Close();
111 }
112 
113 // EOF HarpoPedMgr.cxx
const char * fn
Definition: HarpoPedMgr.h:38
void WriteRunPedestals(Long_t run, HarpoPedestal *p, Int_t plane, Int_t card=0)
Definition: HarpoPedMgr.cxx:83
HarpoPedestal * Lookup(Long_t run, Long_t detno)
! Serach pedestal and means for given plane
Definition: HarpoPedMgr.cxx:37
void SetFile(TString *file)
Set Femimos Pedistal File Name.
Definition: HarpoPedMgr.cxx:30
virtual ~HarpoPedMgr()
Definition: HarpoPedMgr.cxx:22
HarpoPedMgr()
A class HarpoPedMgr.
Definition: HarpoPedMgr.cxx:15
Double_t Mean[NCHIP *NCHAN]
Definition: HarpoPedsRaw.h:26
Double_t GetPed(UInt_t chan)
! Get Channel Pedestal Mean Value
UInt_t GetPedLen()
Definition: HarpoPedestal.h:32
Double_t GetSigma(UInt_t chan)
! Get Channael Pedestal Sigma Value
Double_t Sigma[NCHIP *NCHAN]
Definition: HarpoPedsRaw.h:27
TFile * f
Definition: HarpoPedMgr.h:39
void SetPeds(Double_t mean[], Double_t sigma[])
! Fill pedestal mean and sigma from external arrray
HarpoPedestal * p
Definition: HarpoPedMgr.h:35