FairRoot/PandaRoot
PndMixBackgroundEvents.cxx
Go to the documentation of this file.
2 
3 #include "PndSttHit.h"
4 #include "PndSttTrack.h"
5 #include "PndSttPoint.h"
6 #include "PndSttHelixHit.h"
7 #include "PndSttSingleStraw.h"
8 #include "PndSttTube.h"
9 #include "PndSttMapCreator.h"
10 
11 #include "PndSdsHit.h"
12 #include "PndSdsMCPoint.h"
13 
14 #include "PndTrackCand.h"
15 #include "PndTrackCandHit.h"
16 #include "PndTrack.h"
17 
18 #include "FairRootManager.h"
19 #include "FairRunAna.h"
20 #include "FairRuntimeDb.h"
21 #include "FairTrackParP.h"
22 
23 #include "TFile.h"
24 #include "TGeoManager.h"
25 #include "TClonesArray.h"
26 #include "TGeoVolume.h"
27 #include "TVector3.h"
28 #include "TRandom3.h"
29 #include "TH1F.h"
30 #include "TMath.h"
31 #include "TCanvas.h"
32 #include "TGeoTube.h"
33 
34 #include <iostream>
35 #include <cmath>
36 
37 
38 using namespace std;
39 
40 
41 
42 const Double_t
43  PndMixBackgroundEvents::MVDTYPICALTIME=10., // in nsec; time after which the Mvd hit disappears.
45  PndMixBackgroundEvents::STTdriftVEL = 0.0025, // in cm/nsec
47 
48 
49 
50 // ----- Default constructor -------------------------------------------
51 PndMixBackgroundEvents::PndMixBackgroundEvents() : FairTask("Mixing bkgrnd hits to Stt-Mvd") {
52  fInteractionRate = 20.;
53  fPersistence = kTRUE;
54  fVerbose = 0;
55 // IVOLTE=-1;
56 // istampa=2;
57 
59 
60 }
61 // -------------------------------------------------------------------------
62 
63 PndMixBackgroundEvents::PndMixBackgroundEvents(Int_t verbose) : FairTask("STT Stt-Mvd Tracking") {
64  fInteractionRate = 20.;
65  fPersistence = kTRUE;
66  fVerbose = verbose;
67 // IVOLTE=-1;
68 // istampa=2;
69 
71 
72 }
73 // -------------------------------------------------------------------------
74 
75 
76 // ----- Destructor ----------------------------------------------------
78  delete filedigirun;
79  delete filerecorun;
80 }
81 // -------------------------------------------------------------------------
82 
83 //--------------- begin PndMixBackgroundEvents::Initialization_ClassVariables
84 
86 {
87  // this is only for initializing the Class Variables.
88 
89  size_t len;
90 
91  // Bool_t
92 
93  fPersistence = false;
94 
95  // char :
96 
97  len = sizeof(fSttBkgFilename);
98  memset (fSttBkgFilename,0,len);
99 
100  len = sizeof(fMvdBkgFilename);
101  memset (fMvdBkgFilename,0,len);
102 
103 
104  // pointers
105 
106  filedigirun=NULL;
107  filerecorun=NULL;
108  fMCTrackArray=NULL;
110  fMvdPixelHitArray=NULL;
113  fMvdStripHitArray=NULL;
116  fSttHitArray=NULL;
117  fSttHitBkgArray=NULL;
118  fSttParameters=NULL;
119  fSttTubeArray=NULL;
120  treedigibkg=NULL ;
121  treerecobkg=NULL ;
122 
123  return;
124 }
125 //--------------- end PndMixBackgroundEvents::Initialization_ClassVariables
126 
127 // ----- Public method Init --------------------------------------------
129 
130 
131  // Get RootManager
132  FairRootManager* ioman = FairRootManager::Instance();
133  if ( ! ioman ) {
134  cout << "-E- PndMixBackgroundEvents::Init: "
135  << "RootManager not instantiated, return!" << endl;
136  return kFATAL;
137  }
138 // ----- maps of STT tubes
139  // CHECK added
141  fSttTubeArray = mapper->FillTubeArray();
142  //---------------------------------------------------- end map
143 
144 
145 
146 //----------------- input TClones Arrays -----------------------------------------
147 
148 
149 
150 
151  // Get input array hit di STT after digi
152  fSttHitArray = (TClonesArray*) ioman->GetObject("STTHit");
153  if ( ! fSttHitArray ) {
154  cout << "-W- PndMixBackgroundEvents::Init: "
155  << "No STTHit array, return!" << endl;
156  return kERROR;
157  }
158 
159 // ------------------------- get the Mvd hit input Array
160 
161  fMvdPixelHitArray = (TClonesArray*) ioman->GetObject("MVDHitsPixel");
162  if ( !fMvdPixelHitArray){
163  std::cout << "-W- PndMixBackgroundEvents::Init: " << "No MVD Pixel hitArray, return!" << std::endl;
164  return kERROR;
165  }
166 
167  fMvdStripHitArray = (TClonesArray*) ioman->GetObject("MVDHitsStrip");
168 
169  if ( !fMvdStripHitArray){
170  std::cout << "-W- PndMixBackgroundEvents::Init: " << "No MVD Strip hitArray, return!" << std::endl;
171  return kERROR;
172  }
173 
174  // Background input Arrays
175 
176  // opend background digi file for Stt background hits.
177  filedigirun = new TFile(fSttBkgFilename);
178  treedigibkg = (TTree*) filedigirun->Get("pndsim");
179  nTotalBkgEvents = (Int_t) treedigibkg->GetEntriesFast();
180 
181  // Background STT hits -----
182  treedigibkg->SetBranchAddress("STTHit",&fSttHitBkgArray);
183  if ( ! fSttHitBkgArray ) {
184  cout << "-W- PndMixBackgroundEvents::Init: "
185  << "No STT Background Hit array, return!" << endl;
186  return kERROR;
187  }
188 
189  treedigibkg->SetBranchAddress("MVDHitsPixel",&fMvdPixelHitBkgArray);
190 
191  if ( !fMvdPixelHitBkgArray){
192  std::cout << "-W- PndMixBackgroundEvents::Init: " << "No MVD Pixel Background hitArray, return!"
193  << std::endl;
194  return kERROR;
195  }
196 
197  treedigibkg->SetBranchAddress("MVDHitsStrip",&fMvdStripHitBkgArray);
198 
199 
200  if ( !fMvdStripHitBkgArray){
201  std::cout << "-W- PndMixBackgroundEvents::Init: " << "No MVD Strip Background hitArray, return!"
202  << std::endl;
203  return kERROR;
204  }
205  int nnn = treedigibkg->GetEntriesFast();
206 
207  if( nnn != nTotalBkgEvents) {
208  cout<<"from PndMixBackgroundEvents : total evts in digi file != total evets in reco file, return!"
209  <<endl;
210  return kERROR;
211  }
212 
213 
214 //----------------- Output TClone Arrays -----------------------------------------
215 
216 
217 // ---------------------- new output array of Stt hits + mixed background
218 
219  fSttHitandBckgrndArray = new TClonesArray("PndSttHit"); // PndSttHit is the class tipe.
220  ioman->Register("STTHitMix","SttHitandBckgrnd",fSttHitandBckgrndArray, kTRUE);
221 // ---------------------- new output array of Mvd hits + mixed background
222  // Pixels
223  fMvdPixelHitandBckgrndArray = new TClonesArray("PndSdsHit"); // PndSdsHit is the class tipe.
224  ioman->Register("MVDHitsPixelMix","MvdPixelHitandBckgrnd",fMvdPixelHitandBckgrndArray, kTRUE);
225  // Strips
226  fMvdStripHitandBckgrndArray = new TClonesArray("PndSdsHit"); // PndSdsHit is the class tipe.
227  ioman->Register("MVDHitsStripMix","MvdStripHitandBckgrnd",fMvdStripHitandBckgrndArray, kTRUE);
228 
229 
230  return kSUCCESS;
231 
232 }
233 
234 // --------------- end of InitStatus PndMixBackgroundEvents::Init --------------------
235 
236 // CHECK added
238  FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
239  fSttParameters = (PndGeoSttPar*) rtdb->getContainer("PndGeoSttPar");
240 }
241 
242 
243 
244 
245 
246 // ----- Public method Exec --------------------------------------------
247 // ----- Public method Exec --------------------------------------------
248 // ----- Public method Exec --------------------------------------------
249 // ----- Public method Exec --------------------------------------------
250 // ----- Public method Exec --------------------------------------------
251 // ----- Public method Exec --------------------------------------------
252 // ----- Public method Exec --------------------------------------------
253 // ----- Public method Exec --------------------------------------------
254 // ----- Public method Exec --------------------------------------------
255 // ----- Public method Exec --------------------------------------------
256 // ----- Public method Exec --------------------------------------------
257 // ----- Public method Exec --------------------------------------------
258 // ----- Public method Exec --------------------------------------------
259 // ----- Public method Exec --------------------------------------------
261 
262 
263 //---------------- declaration of variables
264  bool yesno;
265 
266  UShort_t nBkgEventsToAdd;
267 
268  Int_t i,
269  iaddPix,
270  iaddStrip,
271  iaddStt,
272  ichosen,
273  iPix,
274  iStrip,
275  iStt,
276  j,
277  //k, //[R.K. 01/2017] unused variable?
278  k1,
279  k2,
280  k3;
281 
282  Double_t modified,
283  times[NMAXBCKGRND];
284 
285  //PndSttTube * pSttTube; //[R.K. 01/2017] unused variable?
286 
287  PndSttHit * pSttHit;
288 
289  PndSdsHit * pMvdPixelHit,
290  * pMvdStripHit;
291 
292  TVector3 pp,qq;
293 
294  TVector3& pos = pp,
295  dpos = qq;
296 
297 // TRandom3 rannn;
298 
299 
300 //---------- fetching background info -----------------
301 
302 // IVOLTE++;
303 
304  BackgroundNandT(&nBkgEventsToAdd,times);
305 
306 //----------- end background info -----------------
307 
308 
309 //----------- Now load the output TClones arrays -----------------------
310 
311 
312  fSttHitandBckgrndArray->Delete();
313 
314 
315  // physical event Stt hits --
316  for( iStt= 0; iStt< fSttHitArray->GetEntriesFast(); iStt++){
317  pSttHit = (PndSttHit *) fSttHitArray->At(iStt);
318  PndSttHit * temp = new ((*fSttHitandBckgrndArray)[iStt]) PndSttHit;
319  *temp = *pSttHit;
320  temp->SetDetectorID(FairRootManager::Instance()->GetBranchId("STTHitMix"));
321 
322  } // end of for( iStt= 0; iStt< fSttHitArray
323 
324 
325  // physics event Mvd Pixel hits --
326 
327  fMvdPixelHitandBckgrndArray->Delete();
328 
329  for( iPix= 0; iPix< fMvdPixelHitArray->GetEntriesFast(); iPix++){
330  pMvdPixelHit = (PndSdsHit *) fMvdPixelHitArray->At(iPix);
331 
332  pp = pMvdPixelHit->GetPosition();
333  pMvdPixelHit->PositionError(dpos);
334  new ((*fMvdPixelHitandBckgrndArray)[iPix])
335  PndSdsHit(
336  FairRootManager::Instance()->GetBranchId("MVDHitsPixelMix"),
337 // FairRootManager::Instance()->GetBranchId("MVDHitsPixel"),
338  pMvdPixelHit->GetSensorID(),
339  pos,
340  dpos,
341  pMvdPixelHit->GetClusterIndex(),
342  pMvdPixelHit->GetCharge(),
343  pMvdPixelHit->GetNDigiHits(),
344  pMvdPixelHit->GetRefIndex()
345  );
346 
347 
348  } // end of for( iPix= 0; iPix< fMvdPixelHitArray
349 
350  fMvdStripHitandBckgrndArray->Delete();
351  for( iStrip= 0; iStrip< fMvdStripHitArray->GetEntriesFast(); iStrip++){
352  pMvdStripHit = (PndSdsHit *) fMvdStripHitArray->At(iStrip);
353  pp = pMvdStripHit->GetPosition();
354  pMvdStripHit->PositionError(dpos);
355  new ((*fMvdStripHitandBckgrndArray)[iStrip])
356  PndSdsHit(
357  FairRootManager::Instance()->GetBranchId("MVDHitsStripMix"),
358 // FairRootManager::Instance()->GetBranchId("MVDHitsStrip"),
359  pMvdStripHit->GetSensorID(),
360  pos,
361  dpos,
362  pMvdStripHit->GetClusterIndex(),
363  pMvdStripHit->GetCharge(),
364  pMvdStripHit->GetNDigiHits(),
365  pMvdStripHit->GetRefIndex()
366  );
367 
368  } // end of for( i= 0; i< fSttHitArray->Ge
369 
370 
371  // background hits --
372 
373  iaddStt=0;
374  iaddPix=0;
375  iaddStrip=0;
376  k1 = fSttHitArray->GetEntriesFast();
377  k2 = fMvdPixelHitArray->GetEntriesFast();
378  k3 = fMvdStripHitArray->GetEntriesFast();
379 
380 //nBkgEventsToAdd=1;
381 // cout<<"from PndMixBackgroundEvents : in this evt "<<nBkgEventsToAdd<<" evts of bkg are added, with the following times :\n";
382 //for(int ipro=0;ipro<nBkgEventsToAdd;ipro++){
383 // cout<<"\tt = "<<times[ipro]<<endl;
384 //}
385 
386  for(j=0;j<nBkgEventsToAdd;j++){
387 
388  ichosen = (Int_t) (nTotalBkgEvents * rannn.Rndm());
389  if(ichosen==nTotalBkgEvents) ichosen = ichosen-2;
390 //ichosen=0;
391  treedigibkg->GetEntry(ichosen);
392 
393  // background Stt hits --
394  for( i= 0; i<fSttHitBkgArray->GetEntriesFast() ; i++){
395  pSttHit = (PndSttHit *) fSttHitBkgArray->At(i);
396  yesno = ModifyIsochrone(pSttHit->GetIsochrone(),times[j],&modified);
397 
398  if( yesno ) {
399  pSttHit->SetRefIndex(-10); // because this is background hit.
400  pSttHit->SetIsochrone(modified); // because this is background hit.
401  PndSttHit * temp = new ((*fSttHitandBckgrndArray)[k1+iaddStt]) PndSttHit;
402  *temp = *pSttHit;
403  temp->SetDetectorID(FairRootManager::Instance()->GetBranchId("STTHitMix"));
404  iaddStt++;
405  }
406  } // end of for( i= 0;
407 
408 //times[j]=0;
409  if( fabs(times[j])<MVDTYPICALTIME) { // Mvd hits live only 10 nsec.
410  // background Pixel hits --
411  for( i= 0; i<fMvdPixelHitBkgArray->GetEntriesFast() ; i++){
412  pMvdPixelHit = (PndSdsHit *) fMvdPixelHitBkgArray->At(i);
413  pMvdPixelHit->SetRefIndex(-10); // because this is background hit.
414 
415  pp = pMvdPixelHit->GetPosition();
416  pMvdPixelHit->PositionError(dpos);
417  new ((*fMvdPixelHitandBckgrndArray)[k2+iaddPix])
418  PndSdsHit(
419  FairRootManager::Instance()->GetBranchId(
420  "MVDHitsPixelMix"),
421 // "MVDHitsPixel"),
422  pMvdPixelHit->GetSensorID(),
423  pos,
424  dpos,
425  pMvdPixelHit->GetClusterIndex(),
426  pMvdPixelHit->GetCharge(),
427  pMvdPixelHit->GetNDigiHits(),
428  pMvdPixelHit->GetRefIndex()
429  );
430  iaddPix++;
431  } // end of for( i= 0;
432  // background Strip hits --
433  for( i= 0; i<fMvdStripHitBkgArray->GetEntriesFast() ; i++){
434  pMvdStripHit = (PndSdsHit *) fMvdStripHitBkgArray->At(i);
435  pMvdStripHit->SetRefIndex(-10); // because this is background hit.
436 
437  pp = pMvdStripHit->GetPosition();
438  pMvdStripHit->PositionError(dpos);
439  new ((*fMvdStripHitandBckgrndArray)[k3+iaddStrip])
440  PndSdsHit(
441  FairRootManager::Instance()->GetBranchId(
442  "MVDHitsStripMix"),
443 // "MVDHitsStrip"),
444  pMvdStripHit->GetSensorID(),
445  pos,
446  dpos,
447  pMvdStripHit->GetClusterIndex(),
448  pMvdStripHit->GetCharge(),
449  pMvdStripHit->GetNDigiHits(),
450  pMvdStripHit->GetRefIndex()
451  );
452  iaddStrip++;
453 
454  } // end of for( i= 0;
455  } // end of if( fabs(times[j])
456 
457  } // end of for(j=0;j<nBkgEventsToAdd;j++)
458 
459 
460 // ----------------------------------------------------------------------
461 
462 
463 
464 return;
465 
466 }
467 
468 
469 //---------------------- end of PndMixBackgroundEvents::Exec
470 
471 
472 
473 //---------------------- begin of PndMixBackgroundEvents::BackgroundNandT
474 
475 
477  UShort_t *nBkgEventsToAdd,
478  Double_t *times
479  )
480  {
481 
482 
483  Double_t Trange;
484 
485  // negative times
486  *nBkgEventsToAdd=0;
487  Trange = rran.Exp(1000./fInteractionRate) ;// fInteractionRate is in MHz, dtime is in nsec.
488  while ( Trange < MAXSTTdriftTIME){
489  times[(*nBkgEventsToAdd)] = -Trange;
490  Trange += rran.Exp(1000./fInteractionRate) ; // fInteractionRate is in MHz.
491  (*nBkgEventsToAdd)++;
492  }
493 
494 
495  // positive times
496  Trange = rran.Exp(1000./fInteractionRate) ; // fInteractionRate is in MHz, dtime is in nsec.
497  while ( Trange < MAXSTTdriftTIME){
498  times[(*nBkgEventsToAdd)] = Trange;
499  Trange += rran.Exp(1000./fInteractionRate) ; // fInteractionRate is in MHz.
500  (*nBkgEventsToAdd)++;
501  }
502 
503  if( *nBkgEventsToAdd > NMAXBCKGRND ) *nBkgEventsToAdd=NMAXBCKGRND;
504  return;
505  }
506 
507 //---------------------- begin of PndMixBackgroundEvents::ModifyIsochrone
508 
510  Double_t isochrone,
511  Double_t time, // nanosec
512  Double_t *modified
513  )
514  {
515  // STTdriftVEL in cm/nsec is 0.0025 cm/nsec;
516  // isochrone here is in reality a drift radius.
517  *modified = isochrone + time*STTdriftVEL;
518  if( *modified > STRAWRADIUS || *modified < 0.) return false;
519  else return true;
520 
521  }
522 
523 //---------------------- end of PndMixBackgroundEvents::ModifyIsochrone
524 
525 
526 
527 
528 
529 
TVector3 pos
int fVerbose
Definition: poormantracks.C:24
Int_t GetNDigiHits() const
Definition: PndSdsHit.h:92
Int_t i
Definition: run_full.C:25
TVector3 GetPosition() const
Definition: PndSdsHit.h:93
TClonesArray * fMvdStripHitandBckgrndArray
#define verbose
static const UShort_t NMAXBCKGRND
void SetIsochrone(Double_t isochrone)
Definition: PndSttHit.h:69
Double_t GetCharge() const
Definition: PndSdsHit.h:91
static const Double_t MAXSTTdriftTIME
virtual void Exec(Option_t *opt)
Double_t GetIsochrone() const
Definition: PndSttHit.h:62
Double_t
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TClonesArray * FillTubeArray()
static const Double_t STRAWRADIUS
void BackgroundNandT(UShort_t *nBkgEventsToAdd, Double_t *times)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TClonesArray * fMvdPixelHitandBckgrndArray
static const Double_t MVDTYPICALTIME
bool ModifyIsochrone(Double_t isochrone, Double_t time, Double_t *modified)
ClassImp(PndAnaContFact)
Int_t GetClusterIndex() const
Definition: PndSdsHit.h:94
Int_t GetSensorID() const
Definition: PndSdsHit.h:90
static const Double_t STTdriftVEL