CbmRoot
CbmTofAnaTestbeam_Template.cxx
Go to the documentation of this file.
1 // ------------------------------------------------------------------
2 // ----- CbmTofAnaTestbeam -----
3 // ----- Created 12/04/2014 by nh -----
4 // ------------------------------------------------------------------
5 
6 #include "CbmTofAnaTestbeam.h"
7 
8 // TOF Classes and includes
9 #include "CbmMatch.h"
10 #include "CbmTofAddress.h" // in cbmdata/tof
11 #include "CbmTofCell.h" // in tof/TofData
12 #include "CbmTofDetectorId_v12b.h" // in cbmdata/tof
13 #include "CbmTofDetectorId_v14a.h" // in cbmdata/tof
14 #include "CbmTofDigi.h" // in cbmdata/tof
15 #include "CbmTofDigiBdfPar.h" // in tof/TofParam
16 #include "CbmTofDigiExp.h" // in cbmdata/tof
17 #include "CbmTofDigiPar.h" // in tof/TofParam
18 #include "CbmTofGeoHandler.h" // in tof/TofTools
19 #include "CbmTofHit.h" // in cbmdata/tof
20 
21 // CBMroot classes and includes
22 
23 
24 // FAIR classes and includes
25 #include "FairLogger.h"
26 #include "FairRootManager.h"
27 #include "FairRunAna.h"
28 #include "FairRuntimeDb.h"
29 
30 // ROOT Classes and includes
31 #include "Riostream.h"
32 #include "TClonesArray.h"
33 #include "TFile.h"
34 #include "TH1.h"
35 #include "TH2.h"
36 #include "TMath.h"
37 #include "TROOT.h"
38 #include "TRandom.h"
39 #include "TString.h"
40 
41 //___________________________________________________________________
42 //
43 // CbmTofAnaTestbeam
44 //
45 // Task for analysis of Testbeam data
46 //
47 // ------------------------------------------------------------------
49  : FairTask("HadronAnalysis")
50  , fEvents(0)
51  , fGeoHandler(new CbmTofGeoHandler())
52  , fTofId(NULL)
53  , fChannelInfo(NULL)
54  , iNbSmTot(0)
55  , fvTypeSmOffs()
56  , iNbRpcTot(0)
57  , fvSmRpcOffs()
58  , iNbChTot(0)
59  , fvRpcChOffs()
60  , fDigiPar(NULL)
61  , fDigiBdfPar(NULL)
62  , fTofDigisColl(NULL)
63  , fTofDigiMatchColl(NULL)
64  , fTofHitsColl(NULL)
65  , fStart()
66  , fStop() {
67  cout << "CbmTofTests: Task started " << endl;
68 }
69 // ------------------------------------------------------------------
70 
71 // ------------------------------------------------------------------
72 CbmTofAnaTestbeam::CbmTofAnaTestbeam(const char* name, Int_t verbose)
73  : FairTask(name, verbose)
74  , fEvents(0)
75  , fGeoHandler(new CbmTofGeoHandler())
76  , fTofId(NULL)
77  , fChannelInfo(NULL)
78  , iNbSmTot(0)
79  , fvTypeSmOffs()
80  , iNbRpcTot(0)
81  , fvSmRpcOffs()
82  , iNbChTot(0)
83  , fvRpcChOffs()
84  , fDigiPar(NULL)
85  , fDigiBdfPar(NULL)
86  , fTofDigisColl(NULL)
87  , fTofDigiMatchColl(NULL)
88  , fTofHitsColl(NULL)
89  , fStart()
90  , fStop() {}
91 // ------------------------------------------------------------------
92 
93 // ------------------------------------------------------------------
95  // Destructor
96 }
97 // ------------------------------------------------------------------
98 /************************************************************************************/
99 // FairTasks inherited functions
100 InitStatus CbmTofAnaTestbeam::Init() {
101  if (kFALSE == RegisterInputs()) return kFATAL;
102 
103  // fTofId = new ( CbmTofDetectorId )CbmTofDetectorId_v14a();
104  if (kFALSE == InitParameters()) return kFATAL;
105 
106  if (kFALSE == LoadGeometry()) return kFATAL;
107 
108  if (kFALSE == CreateHistos()) return kFATAL;
109 
110  return kSUCCESS;
111 }
112 
114  LOG(info) << " CbmTofAnaTestbeam => Get the digi parameters for tof";
115  return;
116  // Get Base Container
117  FairRunAna* ana = FairRunAna::Instance();
118  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
119 
120  fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
121 
122  fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
123 }
124 
125 void CbmTofAnaTestbeam::Exec(Option_t* /*option*/) {
126  // Task execution
127 
128  LOG(debug) << " CbmTofAnaTestbeam => New event";
129 
130  fStart.Set();
131  FillHistos();
132  fStop.Set();
133 
134 
135  if (0 == (fEvents % 100) && 0 < fEvents) {
136  cout << "-I- CbmTofAnaTestbeam::Exec : "
137  << "event " << fEvents << " processed." << endl;
138  }
139  fEvents += 1;
140 }
141 
143  // Normalisations
144  cout << "CbmTofAnaTestbeam::Finish up with " << fEvents << " analyzed events "
145  << endl;
146 
147  WriteHistos();
148  // Prevent them from being sucked in by the CbmHadronAnalysis WriteHistograms method
149  DeleteHistos();
150 }
151 
152 /************************************************************************************/
153 // Functions common for all clusters approximations
155  FairRootManager* fManager = FairRootManager::Instance();
156 
157  fTofDigisColl = (TClonesArray*) fManager->GetObject("CbmTofDigiExp");
158 
159  if (NULL == fTofDigisColl)
160  fTofDigisColl = (TClonesArray*) fManager->GetObject("CbmTofDigi");
161 
162  if (NULL == fTofDigisColl) {
163  LOG(error) << "CbmTofAnaTestbeam::RegisterInputs => Could not get the "
164  "TofDigi TClonesArray!!!";
165  return kFALSE;
166  } // if( NULL == fTofDigisColl)
167 
168  fTofHitsColl = (TClonesArray*) fManager->GetObject("TofHit");
169  if (NULL == fTofHitsColl) {
170  LOG(error) << "CbmTofAnaTestbeam::RegisterInputs => Could not get the "
171  "TofHit TClonesArray!!!";
172  return kFALSE;
173  } // if( NULL == fTofHitsColl)
174 
175  fTofDigiMatchColl = (TClonesArray*) fManager->GetObject("TofDigiMatch");
176  if (NULL == fTofDigiMatchColl) {
177  LOG(error) << "CbmTofAnaTestbeam::RegisterInputs => Could not get the "
178  "Match TClonesArray!!!";
179  return kFALSE;
180  } // if( NULL == fTofDigiMatchColl)
181 
182  return kTRUE;
183 }
184 /************************************************************************************/
186 
187  // Initialize the TOF GeoHandler
188  Bool_t isSimulation = kFALSE;
189  LOG(info) << "CbmTofAnaTestbeam::InitParameters - Geometry, Mapping, ... ";
190  // Get Base Container
191  FairRun* ana = FairRun::Instance();
192  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
193 
194  Int_t iGeoVersion = fGeoHandler->Init(isSimulation);
195  if (k14a > iGeoVersion) {}
196 
197  fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
198  if (0 == fDigiPar) {
199  LOG(error) << "CbmTofAnaTestbeam::InitParameters => Could not obtain the "
200  "CbmTofDigiPar ";
201  return kFALSE;
202  }
203 
204  fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
205  if (0 == fDigiBdfPar) {
206  LOG(error) << "CbmTofAnaTestbeam::InitParameters => Could not obtain the "
207  "CbmTofDigiBdfPar ";
208  return kFALSE;
209  }
210 
211  return kTRUE;
212 }
213 /************************************************************************************/
215  // Count the total number of channels and
216  // generate an array with the global channel index of the first channe in each RPC
217 
218  return kTRUE;
219 }
220 /************************************************************************************/
221 // ------------------------------------------------------------------
223  // Create histogramms
224 
225  TDirectory* oldir =
226  gDirectory; // <= To prevent histos from being sucked in by the param file of the TRootManager!
227  gROOT
228  ->cd(); // <= To prevent histos from being sucked in by the param file of the TRootManager !
229 
230  // define histos here
231 
232 
233  gDirectory->cd(
234  oldir
235  ->GetPath()); // <= To prevent histos from being sucked in by the param file of the TRootManager!
236 
237  return kTRUE;
238 }
239 
240 // ------------------------------------------------------------------
242  // Constants, TODO => put as parameter !!!
243 
244  Int_t kTOF = 6;
245 
246  // Declare variables outside the loop
247  CbmTofHit* pTofHit;
248 
249  Int_t iNbTofDigis, iNbTofHits;
250 
251 
252  iNbTofDigis = fTofDigisColl->GetEntriesFast();
253  iNbTofHits = fTofHitsColl->GetEntriesFast();
254 
255  // Digis info
256  Double_t dTotalDataSize = 0;
257  if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
258  CbmTofDigiExp* pDigi;
259  for (Int_t iDigInd = 0; iDigInd < iNbTofDigis; iDigInd++) {
260  pDigi = (CbmTofDigiExp*) fTofDigisColl->At(iDigInd);
261 
262  Int_t iSmType = pDigi->GetType();
263  Int_t iSm = pDigi->GetSm();
264  Int_t iRpc = pDigi->GetRpc();
265  Int_t iCh = pDigi->GetChannel();
266  // First Get X/Y position info
267  /*
268  CbmTofDetectorInfo xDetInfo(kTOF, iSmType, iSm, iRpc, 0, iCh + 1);
269  Int_t iChId = fTofId->SetDetectorInfo( xDetInfo );
270  fChannelInfo = fDigiPar->GetCell( iChId );
271 
272  Double_t dX = fChannelInfo->GetX();
273  Double_t dY = fChannelInfo->GetY();
274  Double_t dZ = fChannelInfo->GetZ();
275  /*
276  fhDigiMapXY->Fill( dX, dY );
277  fhDigiMapXZ->Fill( dX, dZ );
278  fhDigiMapYZ->Fill( dY, dZ );
279  */
280  } // for( Int_t iDigInd = 0; iDigInd < iNbTofDigis; iDigInd++ )
281  } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
282 
283  // Hits info
284  Int_t iNbMixedHits = 0;
285  for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
286  pTofHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
287 
288  // Need a method to reconvert position in a "central channel"
289  // fhHitRateCh->Fill();
290 
291  Double_t dX = pTofHit->GetX();
292  Double_t dY = pTofHit->GetY();
293  Double_t dZ = pTofHit->GetZ();
294  /*
295  fhHitMapXY->Fill( dX, dY );
296  fhHitMapXZ->Fill( dX, dZ );
297  fhHitMapYZ->Fill( dY, dZ );
298  */
299  } // for( Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++)
300  return kTRUE;
301 }
302 // ------------------------------------------------------------------
303 
305  // TODO: add sub-folders
306 
307  // Write histogramms to the file
308  TDirectory* oldir = gDirectory;
309  TFile* fHist = new TFile("./tofTests.hst.root", "RECREATE");
310  fHist->cd();
311 
312  // Mapping
313  /*
314  fhDigiMapXY->Write();
315  fhDigiMapXZ->Write();
316  fhDigiMapYZ->Write();
317  fhHitMapXY->Write();
318  fhHitMapXZ->Write();
319  fhHitMapYZ->Write();
320  */
321 
322  gDirectory->cd(oldir->GetPath());
323 
324  fHist->Close();
325 
326  return kTRUE;
327 }
329  // Test class performance
330 
331  // Mapping
332  /*
333  delete fhDigiMapXY;
334  delete fhDigiMapXZ;
335  delete fhDigiMapYZ;
336 
337  delete fhHitMapXY;
338  delete fhHitMapXZ;
339  delete fhHitMapYZ;
340  */
341 
342  return kTRUE;
343 }
344 
CbmTofDigiBdfPar.h
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
CbmTofAnaTestbeam::~CbmTofAnaTestbeam
virtual ~CbmTofAnaTestbeam()
Definition: CbmTofAnaTestbeam.cxx:647
CbmTofAnaTestbeam::fDigiBdfPar
CbmTofDigiBdfPar * fDigiBdfPar
Definition: CbmTofAnaTestbeam.h:329
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
CbmTofAnaTestbeam::SetParContainers
virtual void SetParContainers()
Inherited from FairTask.
Definition: CbmTofAnaTestbeam.cxx:696
CbmTofAnaTestbeam::fTofHitsColl
TClonesArray * fTofHitsColl
Definition: CbmTofAnaTestbeam.h:332
CbmTofDigi.h
CbmTofAnaTestbeam
Definition: CbmTofAnaTestbeam.h:44
CbmTofDigiPar.h
CbmMatch.h
CbmTofAnaTestbeam::WriteHistos
Bool_t WriteHistos()
Definition: CbmTofAnaTestbeam.cxx:7924
CbmTofAnaTestbeam::Init
virtual InitStatus Init()
Definition: CbmTofAnaTestbeam.cxx:653
CbmTofAnaTestbeam::fGeoHandler
CbmTofGeoHandler * fGeoHandler
Definition: CbmTofAnaTestbeam.h:308
CbmTofAnaTestbeam::fEvents
Int_t fEvents
Definition: CbmTofAnaTestbeam.h:305
CbmTofGeoHandler.h
CbmTofAnaTestbeam::CreateHistos
Bool_t CreateHistos()
Definition: CbmTofAnaTestbeam.cxx:1449
CbmTofDetectorId_v14a.h
ClassImp
ClassImp(CbmTofAnaTestbeam)
CbmTofAnaTestbeam::fDigiPar
CbmTofDigiPar * fDigiPar
Definition: CbmTofAnaTestbeam.h:328
CbmTofGeoHandler
Definition: CbmTofGeoHandler.h:30
CbmTofDetectorId_v12b.h
CbmTofAnaTestbeam::InitParameters
Bool_t InitParameters()
Initialize other parameters not included in parameter classes.
Definition: CbmTofAnaTestbeam.cxx:1193
CbmTofAnaTestbeam::LoadGeometry
Bool_t LoadGeometry()
Definition: CbmTofAnaTestbeam.cxx:708
k14a
@ k14a
Definition: CbmTofGeoHandler.h:17
CbmTofAnaTestbeam::fTofDigiMatchColl
TClonesArray * fTofDigiMatchColl
Definition: CbmTofAnaTestbeam.h:333
CbmTofAddress.h
CbmTofGeoHandler::Init
Int_t Init(Bool_t isSimulation=kFALSE)
Definition: CbmTofGeoHandler.cxx:39
CbmTofDigiBdfPar
Parameters class for the CBM ToF digitizer using beam data distributions.
Definition: CbmTofDigiBdfPar.h:30
CbmTofCell.h
CbmTofAnaTestbeam::fStop
TTimeStamp fStop
Definition: CbmTofAnaTestbeam.h:711
CbmTofAnaTestbeam::fStart
TTimeStamp fStart
Definition: CbmTofAnaTestbeam.h:710
fTofHitsColl
TClonesArray * fTofHitsColl
Definition: CbmHadronAnalysis.cxx:52
CbmTofDigiBdfPar::UseExpandedDigi
Bool_t UseExpandedDigi() const
Definition: CbmTofDigiBdfPar.h:85
NicaCbmDetectorID::kTOF
const UInt_t kTOF
Definition: CbmDetectorID.h:15
CbmTofAnaTestbeam::Finish
virtual void Finish()
Definition: CbmTofAnaTestbeam.cxx:861
CbmTofDigiPar
Definition: CbmTofDigiPar.h:18
CbmTofAnaTestbeam::FillHistos
Bool_t FillHistos()
Definition: CbmTofAnaTestbeam.cxx:4123
CbmTofAnaTestbeam::RegisterInputs
Bool_t RegisterInputs()
Definition: CbmTofAnaTestbeam.cxx:945
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
CbmTofAnaTestbeam::Exec
virtual void Exec(Option_t *option)
Definition: CbmTofAnaTestbeam.cxx:769
CbmTofAnaTestbeam::DeleteHistos
Bool_t DeleteHistos()
Definition: CbmTofAnaTestbeam.cxx:8261
CbmTofAnaTestbeam::fTofDigisColl
TClonesArray * fTofDigisColl
Definition: CbmTofAnaTestbeam.h:331
CbmTofAnaTestbeam::CbmTofAnaTestbeam
CbmTofAnaTestbeam()
Definition: CbmTofAnaTestbeam.cxx:174
CbmTofAnaTestbeam.h