FairRoot/PandaRoot
PndSdsStripClusterTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndSdsStripClusterTask source file -----
3 // -------------------------------------------------------------------------
4 
5 #include <cmath>
6 
7 #include "TClonesArray.h"
8 #include "TArrayD.h"
9 #include "TGeoManager.h"
10 #include "TGeoMatrix.h"
11 #include "TCanvas.h"
12 #include "TMatrixD.h"
13 #include "TCollection.h"
14 #include "FairRootManager.h"
15 #include "FairRunAna.h"
16 #include "FairRuntimeDb.h"
17 #include "FairGeoNode.h"
18 #include "FairGeoVector.h"
19 #include "FairContFact.h"
20 
21 #include "PndStringSeparator.h"
22 #include "PndSdsStripDigiPar.h"
23 #include "PndSdsStripClusterTask.h"
24 #include "PndSdsMCPoint.h"
25 #include "PndSdsCalcStrip.h"
26 #include "PndSdsDigiStrip.h"
27 #include "PndSdsClusterStrip.h"
28 #include "PndGeoHandling.h"
29 
33 
34 #include <map>
35 
36 // ----- Default constructor -------------------------------------------
38  PndSdsTask("SDS Strip Clustertisation Task"),
39  fPath(),
40  fDigiArray(NULL),
41  fClusterArray(NULL),
42  fHitArray(NULL),
43  fClustBranchName(""),
44  fClusterType(0),
45  fFEcolumns(0),
46  fFErows(0),
47  fChargeCut(1.e8),
48  fRadChannel(0),
49  fRadTime(0),
50  fSingleStripChargeThreshold(0),
51  fEventHeader(NULL),
52  fDigiParameterList(new TList()),
53  fCurrentDigiPar(0),
54  fSensorNamePar(NULL),
55  fChargeDigiParameterList(new TList()),
56  fStripCalcTop(),
57  fStripCalcBot(),
58  fChargeConverter(),
59  fCurrentStripCalcTop(0),
60  fCurrentStripCalcBot(0),
61  fChargeAlgos(0),
62  fCurrentChargeConverter(0),
63  fDigiPar(0),
64  fGeoH(NULL),
65  fCurrentClusterfinder(0),
66  fClusterFinderList(),
67  fFunctor(NULL),
68  eta_rect(NULL),
69  eta_trap(NULL),
70  etahistofile(NULL)
71 {
72  SetPersistency(kTRUE);
73 }
74 
75 // ----- Named constructor -------------------------------------------
77  PndSdsTask(name),
78  fPath(),
79  fDigiArray(NULL),
80  fClusterArray(NULL),
81  fHitArray(NULL),
82  fClustBranchName(""),
83  fClusterType(0),
84  fFEcolumns(0),
85  fFErows(0),
86  fChargeCut(1.e8),
87  fRadChannel(0),
88  fRadTime(0),
89  fSingleStripChargeThreshold(0),
90  fEventHeader(NULL),
91  fDigiParameterList(new TList()),
92  fCurrentDigiPar(0),
93  fSensorNamePar(NULL),
94  fChargeDigiParameterList(new TList()),
95  fStripCalcTop(),
96  fStripCalcBot(),
97  fChargeConverter(),
98  fCurrentStripCalcTop(0),
99  fCurrentStripCalcBot(0),
100  fChargeAlgos(0),
101  fCurrentChargeConverter(0),
102  fDigiPar(0),
103  fGeoH(NULL),
104  fCurrentClusterfinder(0),
105  fClusterFinderList(),
106  fFunctor(NULL),
107  eta_rect(NULL),
108  eta_trap(NULL),
109  etahistofile(NULL)
110 {
111  SetPersistency(kTRUE);
112 }
113 
114 // ----- Destructor ----------------------------------------------------
116 {
119  if (0!=fFunctor) delete fFunctor;
121 }
122 // -------------------------------------------------------------------------
123 
125 {
126  for( std::map<const char*,PndSdsCalcStrip*>::iterator it = fStripCalcTop.begin(); it != fStripCalcTop.end(); it++){
127  if(0 != it->second) delete it->second;
128  it->second = 0;
129  }
130  for( std::map<const char*,PndSdsCalcStrip*>::iterator it = fStripCalcBot.begin(); it != fStripCalcBot.end(); it++){
131  if(0 != it->second) delete it->second;
132  it->second = 0;
133  }
134  if(0 != fChargeAlgos) delete fChargeAlgos;
135  for(std::map<const char*,PndSdsChargeConversion*>::iterator it = fChargeConverter.begin(); it != fChargeConverter.end(); it++){
136  if(0 != it->second) delete it->second;
137  it->second = 0;
138  }
139  for(std::map<const char*,PndSdsStripClusterer*>::iterator it = fClusterFinderList.begin(); it != fClusterFinderList.end(); it++){
140  if(0 != it->second) delete it->second;
141  it->second = 0;
142  }
143 
148 }
149 
150 // -------------------------------------------------------------------------
151 
153 {
154  if ( fGeoH == NULL ) {
156  }
158  return;
159 }
160 
161 void PndSdsStripClusterTask::InitMQ(TList* tempList)
162 {
163  SetBranchNames();
164  fHitArray = new TClonesArray("PndSdsHit",10000);
165  fHitArray->SetName("MVDHitsStrip");
166  fClusterArray = new TClonesArray("PndSdsClusterStrip", 10000);
167  fClusterArray->SetName("MVDStripCluster");
168 
169  fSensorNamePar = (PndSensorNamePar*)tempList->FindObject("PndSensorNamePar");
171  fGeoH->FillSensorMap();
172 
173  SetParContainersMQ(tempList);
174  SetCalculators();
175 }
176 
177 void PndSdsStripClusterTask::ExecMQ(TList* inputList,TList* outputList)
178 {
179 // LOG(INFO) << "PndSdsStripClusterTask::ExecMQ inBranchName " << fInBranchName.Data() << FairLogger::endl;
180 // LOG(INFO) << "InputList: " << inputList->GetEntries() << FairLogger::endl;
181 // TIter next(inputList);
182 // while(TObject* obj = next()){
183 // LOG(INFO) << obj->GetName() << FairLogger::endl;
184 // }
185  fDigiArray = (TClonesArray*) inputList->FindObject("PndSdsDigiStrips");
186  fEventHeader = (FairEventHeader*) inputList->FindObject("EventHeader.");
187  LOG(INFO) << "DigiArray: " << fDigiArray << FairLogger::endl;
188  LOG(INFO) << "DigiArray: " << fDigiArray->GetEntriesFast() << FairLogger::endl;
189 
190 
191  outputList->Add(fClusterArray);
192  outputList->Add(fHitArray);
193  Exec("");
194  return;
195 }
196 
197 //
199 {
200  SetParContainers();
201  SetCalculators();
202  return kSUCCESS;
203 }
204 
206 {
207  // called at the enf of Init()
208  // TODO: Implement more clusterfinders
209  if (fVerbose>1) Info("SetCalculators","sds part");
211  TIter params(fDigiParameterList);
212  while(PndSdsStripDigiPar* digipar=(PndSdsStripDigiPar*)params()){
213  if(0==digipar) {
214  Error("SetCalculators()","A Digi Parameter Set does not exist properly.");
215  continue;
216  }
217  const char* senstype = digipar->GetSensType();
218  if(fVerbose>1){
219  Info("SetCalculators()","Create a Parameter Set for %s sensors",senstype);
220  std::cout<<senstype<<"#"<<std::endl;
221  digipar->Print();
222  }
223  fStripCalcTop[senstype]=new PndSdsCalcStrip(digipar,kTOP);
224  fStripCalcTop[senstype]->SetVerboseLevel(fVerbose);
225  fStripCalcBot[senstype]=new PndSdsCalcStrip(digipar,kBOTTOM);
226  fStripCalcBot[senstype]->SetVerboseLevel(fVerbose);
227  }
230 
231 }
232 
233 // ----- Public method Init --------------------------------------------
235 {
236 
237  SetBranchNames();
238 
239  FairRootManager* ioman = FairRootManager::Instance();
240  if ( ! ioman )
241  {
242  std::cout << "-E- PndSdsStripClusterTask::Init: "
243  << "RootManager not instantiated!" << std::endl;
244  return kFATAL;
245  }
246 
247  fFunctor = new TimeGap();
248 
249  // Get input array
250  fDigiArray = (TClonesArray*) ioman->GetObject(fInBranchName);
251 //
252  if ( ! fDigiArray )
253  {
254  std::cout << "-W- PndSdsPixelClusterTask::Init: "
255  << "No SDSDigi array!" << std::endl;
256  return kERROR;
257  }
258  // set output arrays
259 
260 // fClusterArray = new TClonesArray("PndSdsClusterStrip");
261 // ioman->Register(fClustBranchName, fFolderName, fClusterArray, fPersistance);
262 
263  fClusterArray = ioman->Register(fClustBranchName, "PndSdsClusterStrip", fFolderName, GetPersistency());
264 
265 
266  //fHitArray = new TClonesArray("PndSdsHit");
267  fHitArray = ioman->Register(fOutBranchName, "PndSdsHit", fFolderName, GetPersistency());
268 
269  SetInBranchId();
270 
271  SetCalculators();
272 
273  fPath = getenv("VMCWORKDIR");
274  fPath += "/macro/params/interstrippos_vs_eta_histos.root";
275 
276  etahistofile = new TFile(fPath,"READ");
277  eta_rect = (TH2F*)etahistofile->Get("posvseta rect");
278  eta_trap = (TH2F*)etahistofile->Get("posvseta trap");
279 
280  Info("Init","Initialisation successfull");
281  return kSUCCESS;
282 }
283 // -------------------------------------------------------------------------
284 
285 // ----- Public method Exec --------------------------------------------
287 {
288  if (fVerbose > 2)
289  std::cout<<" **Starting PndSdsStripClusterTask::Exec()**"<<std::endl;
290  std::vector<PndSdsDigiStrip> digiStripArray;
291  // Reset output array
292 // fClusterArray = FairRootManager::Instance()->GetTClonesArray(fClustBranchName);
293  if ( ! fClusterArray ) Fatal("Exec", "No ClusterArray");
294  fClusterArray->Delete();
295 
296 // fHitArray = FairRootManager::Instance()->GetTClonesArray(fOutBranchName);
297  if ( ! fHitArray ) Fatal("Exec", "No HitArray");
298  fHitArray->Delete();
299 
300  // Get input array
301 
302  if (FairRunAna::Instance() != 0 && FairRunAna::Instance()->IsTimeStamp()){
303  fDigiArray->Clear();
304  fDigiArray = FairRootManager::Instance()->GetData(fInBranchName, fFunctor, (1./40.0) * 1000.); //FairRootManager::Instance()->GetEventTime() +
305  if(fVerbose > 1)
306  std::cout << "-I- PndSdsStripClusterTask::Exec Digis: " << fDigiArray->GetEntries() << std::endl;
307  }
308 // else
309 // fDigiArray = (TClonesArray*)FairRootManager::Instance()->GetObject(fInBranchName);
310 
311 // std::cout << "Requested Time: " << FairRootManager::Instance()->GetEventTime() + 10 << std::endl;
312 // for (int i = 0; i < fDigiArray->GetEntries(); i++){
313 // std::cout << i << ": " << ((PndSdsDigiStrip*)fDigiArray->At(i))->GetTimeStamp() << std::endl;
314 // }
315 
316  //std::cout << "-I- PndSdsStripClusterTask:: fDigiArray->Size(): " << fDigiArray->GetEntriesFast() << std::endl;
317  //fDigiArray = (TClonesArray*) ioman->GetObject(fInBranchName);
318  if ( ! fDigiArray )
319  {
320  std::cout << "-W- PndSdsStripClusterTask::Init: "
321  << "No SDSDigi array!" << std::endl;
322  return;
323  }
324 
325  // when we have no digis, we can end the event here.
326  if (fDigiArray->GetEntriesFast() == 0) return;
328 
329  // Setup
331 
332  std::vector< PndSdsClusterStrip* > clusters;
333  std::vector< Int_t > topclusters;// contains index to fClusterArray
334  std::vector< Int_t > botclusters;// contains index to fClusterArray
335  std::vector< Int_t > oneclustertop;
336  std::vector< Int_t > oneclusterbot;
337  std::vector< Int_t > leftDigis;
338  Int_t mcindex, clindex, botIndex, topIndex;
339  //Int_t detID = FairRootManager::Instance()->GetBranchId(fInBranchName); //unused??
340  Int_t clDetID = -1;
341  if (FairRootManager::Instance() != 0)
342  clDetID = FairRootManager::Instance()->GetBranchId(fClustBranchName);
343  Double_t mycharge;
344  TVector2 meantopPoint, meanbotPoint, onsensorPoint;
345  TVector3 hitPos,hitErr;
346  TMatrixD hitCov(3,3);
347  Int_t clusterOffset = 0;
348  PndSdsHit* tmphit;
349 
350  // ------- SEARCH ------
351  TIter parsetiter(fDigiParameterList);
352  while ( PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)parsetiter() )
353  { // loop over all parameter sets and their filled finders (representing sensor types)
354  SetCurrentCalculators(digipar);
355 
357  // fetch ids in 'clusters' to the top and bot side
358  topclusters = fCurrentClusterfinder->GetTopClusterIDs();
359  botclusters = fCurrentClusterfinder->GetBotClusterIDs();
360  if(fVerbose > 2) {
361  leftDigis = fCurrentClusterfinder->GetLeftDigiIDs();
362  if (0<leftDigis.size()){
363  std::cout << "There are "<<leftDigis.size()<<" Digis not assigned to"
364  << " clusters:\n";
365  for(unsigned int s=0;s<leftDigis.size();s++)
366  {
367  std::cout<<leftDigis[s]<<"|";
368  }
369  std::cout<<std::endl;
370  } else std::cout<<"All Digis assigned to clusters"<<std::endl;
371  }
372  // Fill the ClonesArray for output TODO: do this better, don't copy objects around
373  // save array size before we fill
374  clusterOffset = fClusterArray->GetEntriesFast();
375  for(std::vector< PndSdsClusterStrip* >::iterator clit= clusters.begin(); clit!=clusters.end(); ++clit)
376  {
377  clindex = fClusterArray->GetEntriesFast();
378  PndSdsClusterStrip* myCluster = new((*fClusterArray)[clindex]) PndSdsClusterStrip(*(*clit));
379 
380  if (FairRunAna::Instance() != 0 && FairRunAna::Instance()->IsTimeStamp()){
381  myCluster->ResetLinks();
382  for(UInt_t i = 0; i < (UInt_t)myCluster->GetClusterSize(); i++){
383  PndSdsDigiStrip* tempDigi = (PndSdsDigiStrip*)fDigiArray->At(myCluster->GetDigiIndex(i));
384  myCluster->AddLink(FairLink(tempDigi->GetEntryNr()));
385  }
386  }
387  }
388 
389  // std::cout << "-I- PndSdsStripClusterTask:: fClusterArray size: " << fClusterArray->GetEntries() << std::endl;
390 
391  //printout for checking
392  if(fVerbose > 2) {
393  std::cout << "Check.. Offset: " << clusterOffset << std::endl;
394  std::cout << "Top Clusters: ";
395  for (std::vector< Int_t>::iterator itTop = topclusters.begin();
396  itTop!=topclusters.end(); ++itTop)
397  {
398  std::cout<<*itTop<<" | ";
399  }
400  std::cout<<std::endl;
401  std::cout<<"Bot Clusters: ";
402  for (std::vector< Int_t>::iterator itBot = botclusters.begin();
403  itBot!=botclusters.end(); ++itBot)
404  {
405  std::cout<<*itBot<<" | ";
406  }
407  std::cout<<std::endl;
408  }
409 
410  // begin the hit reconstruction
411  // loop structure:
412  //
413  //top clusters
414  // |-calculate chargeweighted mean
415  // |-bot clusters
416  // |-|-calc chargew. mean
417  // |-|-calc the crossing strip points
418  // |-|-fill hit array
419 
420  // ----- merge top/bot clusters to hits -----
421  // loop on clusters from the top side
422  for (std::vector< Int_t>::iterator itTop = topclusters.begin();
423  itTop!=topclusters.end(); ++itTop)
424  {
425  topIndex= *itTop + clusterOffset; // index in fClusterArray
426  Double_t topcharge = 0., meantopstrip=0.,meantoperr=0., timestamp=0., timestampError=0. ;
427  PndSdsClusterStrip* aTopCluster=clusters[*itTop];
428  oneclustertop = aTopCluster->GetClusterList();
429  if(oneclustertop.size()<1) continue;
430  PndSdsDigiStrip* atopDigi = ((PndSdsDigiStrip*)fDigiArray->At(oneclustertop[0]));
431  Int_t sensorIDtop = atopDigi->GetSensorID();
432 
433  //if (kFALSE==SelectSensorParams(detName)) continue; // Invalid parameters, skip here.
434  CalcMeanCharge(aTopCluster,meantopstrip,meantoperr,topcharge, timestamp, timestampError);
435 
436  if(oneclustertop.size()==1 && topcharge < fSingleStripChargeThreshold) {
437  std::cout<<"-W- PndSdsClusterTask::Exec: Single strip charge ("<<topcharge<<" e-) falls below the threshold of "<<fSingleStripChargeThreshold<<"e- : skipping. "<<endl;
438  continue;
439  }
440  if(topcharge <= 0) { // not a sane charge
441  Error("Exec() - Hit combination","Not a sane top charge (%f) calculated, skip cluster %i",topcharge, *itTop);
442  continue;
443  }
444  if(meantopstrip < 0) { // not a sane strip number
445  Error("Exec() - Hit combination","Not a sane top mean (%f) calculated, skip cluster %i",meantopstrip, *itTop);
446  continue;
447  }
448  fCurrentStripCalcTop->CalcStripPointOnLine(meantopstrip, meantopPoint);
449  // loop on bottom side
450  for (std::vector< Int_t>::iterator itBot = botclusters.begin();
451  itBot!=botclusters.end(); ++itBot)
452  {
453  botIndex = *itBot + clusterOffset; // index in fClusterArray
454  Double_t botcharge = 0., meanbotstrip=0., meanboterr=0.;
455  PndSdsClusterStrip* aBotCluster = clusters[*itBot];
456  oneclusterbot = aBotCluster->GetClusterList();
457  if(oneclusterbot.size()<1)continue;
458  PndSdsDigiStrip* abotDigi = ((PndSdsDigiStrip*)fDigiArray->At(oneclusterbot[0]));
459  Int_t sensorIDbot = abotDigi->GetSensorID();
460 
461  //go to the next cluster if we didn't hit the same sensor
462  if(sensorIDbot != sensorIDtop) continue;
463 
464  CalcMeanCharge(aBotCluster,meanbotstrip,meanboterr,botcharge, timestamp, timestampError);
465 
466  if(oneclusterbot.size() == 1 && botcharge < fSingleStripChargeThreshold) {
467  std::cout<<"-W- PndSdsClusterTask::Exec: Single strip charge ("<<botcharge<<" e-) falls below the threshold of "<<fSingleStripChargeThreshold<<"e- : skipping. "<<endl;
468  continue;
469  }
470  if(botcharge <= 0) { // not a sane charge
471  Error("Exec() - Hit combination","Not a sane bot charge (%f) calculated, skip cluster %i",botcharge, *itBot);
472  continue;
473  }
474  if(meanbotstrip < 0) { // not a sane strip number
475  Error("Exec() - Hit combination","Not a sane bot mean (%f) calculated, skip cluster %i",meanbotstrip, *itBot);
476  continue;
477  }
478 
479  if(fVerbose > 2) {
480  std::cout<<"Charges: Ctop = "<<topcharge<<" | Cbot = "<<botcharge
481  <<" | difference bot-top = "<<botcharge-topcharge
482  <<" | Cut at "<<fChargeCut<<std::endl;
483  }
484 
485  if(fChargeCut>0 && fabs(botcharge-topcharge)<fChargeCut)
486  {// look if the charges are not too differently
487  mycharge = (botcharge + topcharge) / 2.;
488  fCurrentStripCalcBot->CalcStripPointOnLine(meanbotstrip, meanbotPoint);
489  mcindex=-1; // reset
490  for(Int_t mcI = 0; mcI<atopDigi->GetNIndices();mcI++){
491  if (atopDigi->GetIndex(mcI) > -1) {
492  for(Int_t mcIb = 0; mcIb<abotDigi->GetNIndices();mcIb++){
493  if (abotDigi->GetIndex(mcIb) == atopDigi->GetIndex(mcI)) {
494  mcindex = abotDigi->GetIndex(mcIb);
495  break;
496  }
497  }
498  }
499  }
500  Bool_t test = Backmap(meantopPoint, meantoperr, meanbotPoint, meanboterr, hitPos, hitCov,sensorIDtop);
501  if (kFALSE==test) continue;
502 
503  // --- add hit to list ---
504  Int_t i = fHitArray->GetEntriesFast();
505  hitErr.SetXYZ(sqrt(hitCov[0][0]),sqrt(hitCov[1][1]),sqrt(hitCov[2][2]));
506  tmphit = new((*fHitArray)[i]) PndSdsHit(clDetID,sensorIDtop,hitPos,hitErr,
507  topIndex,mycharge,oneclusterbot.size()+oneclustertop.size(),mcindex);
508  tmphit->SetBotIndex(botIndex);
509  if (FairRootManager::Instance() != 0){
510  tmphit->SetLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), fClusterType, topIndex));
511  tmphit->AddLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), fClusterType, botIndex));
512  }
513  tmphit->SetCov(hitCov);
514  tmphit->SetTimeStamp(timestamp);
515  tmphit->SetTimeStampError(timestampError);
516  if (fVerbose > 1)
517  tmphit->Print();
518  } else
519  if (fVerbose > 2) std::cout<<"Strip charge contents too different"<<std::endl;
520  }// loop bot clusters
521  }// loop top clusters
522  for (size_t i = 0; i < clusters.size(); i++){
523  delete (clusters[i]);
524  }
525  clusters.clear();
526  }//loop finders
527  fHitArray->Sort();
528  if (fVerbose > 1)
529  std::cout << "-I- PndSdsStripClusterTask: " << fClusterArray->GetEntriesFast()
530  << " Mvd Clusters and " << fHitArray->GetEntriesFast()<<" Hits calculated."
531  << " out of " <<fDigiArray->GetEntriesFast()<< " Digis"<< std::endl;
532  return;
533 }
534 
535 // -------------------------------------------------------------------------
537 {
538  TString detpath = fGeoH->GetPath(sensorID);
539  if( !(detpath.Contains("Strip")) )
540  return kFALSE;
541  TIter parsetiter(fDigiParameterList);
542  while ( PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)parsetiter() )
543  {
544  const char* sensortype = digipar->GetSensType();
545  if(detpath.Contains(sensortype)) {
546  SetCurrentCalculators(digipar);
547  return kTRUE;
548  }
549  }
550  // no suiting object found
551  if (fVerbose > 1) std::cout<<"detector name does not contain a valid parameter name."<<std::endl;
552  if (fVerbose > 2) std::cout<<" DetName : "<<detpath<<std::endl;
553  return kFALSE;
554 }
555 // -------------------------------------------------------------------------
556 
558 {
559  const char* sensortype = digipar->GetSensType();
560  fCurrentStripCalcTop = fStripCalcTop[sensortype];
561  fCurrentStripCalcBot = fStripCalcBot[sensortype];
564  fCurrentDigiPar = digipar;
567  fChargeCut = digipar->GetChargeCut();
569  return;
570 }
571 
572 // -------------------------------------------------------------------------
574 {
575  //recursively clean the digis in the clusterfinder objects each event
576  for(std::map<const char*,PndSdsStripClusterer*>::iterator CFiter = fClusterFinderList.begin();
577  CFiter != fClusterFinderList.end(); CFiter++)
578  {
579  (CFiter->second)->Reinit();
580  }
581 }
582 // -------------------------------------------------------------------------
584 {
585  // Info("FillClusterFinders","Here! fCurrntClusterfinder:%p",fCurrentClusterfinder);
587  // a std::map is a SORTED container, it is sorted by the identifier
588  Int_t sensorID;
589  Int_t strip;
590  SensorSide side;
591  PndSdsDigiStrip* myDigi=0;
592  Bool_t tester=kFALSE;
593  // Sort Digi indice into the clusterfinder
594  if (fDigiArray->GetEntriesFast() == 0) return;
595  if(fVerbose>2) Info("FillClusterFinders","adding these digis to the finders:");
596  for (Int_t iDigi = 0; iDigi < fDigiArray->GetEntriesFast(); iDigi++)
597  { // sort digis by sensor name and stripnumber
598  myDigi = (PndSdsDigiStrip*)(fDigiArray->At(iDigi));
599  if(fVerbose>2) {std::cout<<"Digi "<<iDigi<<" "; myDigi->Print(); std::cout << fGeoH->GetPath(myDigi->GetSensorID()) << std::endl;}
600  sensorID = myDigi->GetSensorID();
601  tester=SelectSensorParams(sensorID);
602  if (kFALSE==tester) continue; // Invalid parameters, skip here.
603  //we use the top side as "first" side
604  fCurrentStripCalcTop->CalcFeChToStrip(myDigi->GetFE(), myDigi->GetChannel(), strip, side);
605  // Time stamp measured in ns, cropped to integer for clusterfinding
606  //fCurrentClusterfinder->AddDigi(sensorID,side,(Int_t)myDigi->GetTimeStamp(),strip,iDigi);
607  fCurrentClusterfinder->AddDigi(sensorID,side,1,strip,iDigi);
608  }
609  // make sure the digi array is distributed well
611 }
612 
613 // -------------------------------------------------------------------------
615  TVector2 point1, TVector2 dir1,
616  TVector2 point2, TVector2 dir2) const
617 {
618  Double_t dx, dy, s, M, x, y;
619  dx = point2.X() - point1.X();
620  dy = point2.Y() - point1.Y();
621 
622  M = dir1.X()*dir2.Y() - dir1.Y()*dir2.X();
623 
624  if(M !=0.)
625  {
626  s = dir1.Y()*dx/M - dir1.X()*dy/M;
627  x = point2.X() + dir2.X()*s;
628  y = point2.Y() + dir2.Y()*s;
629  }
630  else
631  {
632  std::cout<<"Warning in PndSdsStripClusterTask::CalcLineCross(): M=0 setting (x,y) to 0"<<std::endl;
633  x=0.;y=0.;
634  }
635 
636  TVector2 result(x,y);
637  return result;
638 }
639 
641 {
642 }
643 
644 void PndSdsStripClusterTask::CalcMeanCharge(PndSdsClusterStrip* onecluster, Double_t &meanstrip, Double_t &meanerr, Double_t &charge, Double_t &timestamp, Double_t &timestampError)
645 {
646  meanstrip=0;
647  meanerr=0;
648  charge=0;
649  timestamp=0;
650  timestampError = 0;
651  Int_t nDigis = 0;
652 
653 // if (fCurrentDigiPar->GetClusterMean() == 0)
654 // {
655 // // Calculate mean position in position channels weighted by the charges
656 // Int_t strip;
657 // SensorSide side;
658 // Double_t tempcharge;
659 // std::vector<Int_t> oneclusterlist = onecluster->GetClusterList();
660 // for (std::vector<Int_t>::iterator itDigi = oneclusterlist.begin();
661 // itDigi != oneclusterlist.end(); ++itDigi)
662 // { // calculate the mean charge and stripnumber
663 // PndSdsDigiStrip* myDigi = (PndSdsDigiStrip*)fDigiArray->At(*itDigi);
664 // std::cout << "Digi: " << *myDigi << std::endl;
665 // fCurrentStripCalcTop->CalcFeChToStrip(myDigi->GetFE(), myDigi->GetChannel(), strip, side);
666 // tempcharge = fCurrentChargeConverter->DigiValueToCharge(*myDigi);
667 // std::cout << "TempCharge: " << tempcharge << std::endl;
668 // charge += tempcharge;
669 // meanstrip += tempcharge * strip;
670 // meanerr += tempcharge*tempcharge; // this is stupid, to be removed one day
671 // Double_t var = myDigi->GetTimeStampError() * myDigi->GetTimeStampError();
672 // timestamp += myDigi->GetTimeStamp()/var;
673 // timestampError += 1/var;
674 // nDigis++;
675 // }
676 // meanstrip = meanstrip/charge;
677 // std::cout << "Charge: " << charge << std::endl;
678 // // this error treatment is: dx = dpitch * sqrt(weigthsquares)
679 // meanerr = sqrt(meanerr/(charge*charge));
680 // if (nDigis > 0){
681 // timestamp /= timestampError;
682 // timestampError = sqrt(timestampError / nDigis);
683 // }
684 // return;
685 // } else {
686 // // //TODO: Apply other clusterfinder mean & error algorithms
687 // // if(onecluster->GetSensorSide()==kTOP) fCurrentChargeAlgos->SetCalcStrip(fCurrentStripCalcTop);
688 // // else fCurrentChargeAlgos->SetCalcStrip(fCurrentStripCalcBot);
689 // // fChargeAlgos->SetChargeConverter(fCurrentChargeConverter); // done somewhere else
690 // std::pair<Double_t,Double_t> result = fChargeAlgos->CenterOfGravity(onecluster);
691 // meanstrip=result.first;
692 // meanerr=result.second;
693 // std::vector<Int_t> oneclusterlist = onecluster->GetClusterList();
694 // for (std::vector<Int_t>::iterator itDigi = oneclusterlist.begin();
695 // itDigi != oneclusterlist.end(); ++itDigi)
696 // {
697 // PndSdsDigiStrip* myDigi = (PndSdsDigiStrip*)fDigiArray->At(*itDigi);
698 // std::cout << "Digi: " << * myDigi << std::endl;
699 // std::cout << "TempCharge: " << fCurrentChargeConverter->DigiValueToCharge(*myDigi) << std::endl;
700 // charge += fCurrentChargeConverter->DigiValueToCharge(*myDigi);
701 // Double_t var = myDigi->GetTimeStampError() * myDigi->GetTimeStampError();
702 // timestamp += myDigi->GetTimeStamp()/var;
703 // timestampError += 1/var;
704 // nDigis++;
705 // }
706 // if (nDigis > 0){
707 // timestamp /= timestampError;
708 // timestampError = sqrt(timestampError / nDigis);
709 // }
710 //
711 // std::cout << "Charge: " << charge << std::endl;
712 // return;
713 // }
714 
715  Int_t centroidMod = fCurrentDigiPar->GetClusterMean();
716  PndSdsDigiStrip* tmpdigi=0;
717 
718  std::pair<Double_t,Double_t> result;
719 
720  switch(centroidMod){ // Select a method by the number of the CenteroidAlgorithm
721 
722  case 1:
723  // Binary (hightest signal)
724  result = fChargeAlgos->Binary(onecluster);
725  break;
726 
727  case 2:
728  //Center of Gravity, Binary for cluster size 1
729  result = fChargeAlgos->CenterOfGravity(onecluster);
730  break;
731 
732  case 3:
733  // Eta Algorithm for cluster size 2, Binary for cluster size 1, else CoG
734  tmpdigi = (PndSdsDigiStrip*)(fDigiArray->At(onecluster->GetDigiIndex(0)));
735  if(fGeoH->GetPath(tmpdigi->GetSensorID()).Contains("Fwd"))
736  result = fChargeAlgos->Eta(onecluster, eta_trap);
737  else result = fChargeAlgos->Eta(onecluster, eta_rect);
738  break;
739 
740  case 4:
741  // Head-Tail, Binary for cluster size 1
742  result = fChargeAlgos->HeadTail(onecluster);
743  break;
744 
745  //Center of Gravity, Binary for cluster size 1
746  default:
747  result = fChargeAlgos->CenterOfGravity(onecluster);
748  break;
749  }
750 
751  meanstrip=result.first;
752  meanerr=result.second;
753 
754  std::vector<Int_t> oneclusterlist = onecluster->GetClusterList();
755  for (std::vector<Int_t>::iterator itDigi = oneclusterlist.begin();
756  itDigi != oneclusterlist.end(); ++itDigi)
757  {
758  tmpdigi = (PndSdsDigiStrip*)fDigiArray->At(*itDigi);
759  if(fVerbose>3) Info("CalcMeanCharge:","Added charge of digi %i in cluster is %f",nDigis,fCurrentChargeConverter->DigiValueToCharge(*tmpdigi));
760  charge += fCurrentChargeConverter->DigiValueToCharge(*tmpdigi);
761  Double_t var = tmpdigi->GetTimeStampError() * tmpdigi->GetTimeStampError();
762  timestamp += tmpdigi->GetTimeStamp()/var;
763  timestampError += 1/var;
764  nDigis++;
765  }
766  if (nDigis > 0){
767  timestamp /= timestampError;
768  timestampError = sqrt(timestampError / nDigis);
769  }
770  return;
771 }
772 
773 
774 
775 Bool_t PndSdsStripClusterTask::Backmap( TVector2 meantopPoint, Double_t meantoperr, TVector2 meanbotPoint, Double_t meanboterr,
776  TVector3 &hitPos, TMatrixD &hitCov, Int_t &sensorID)
777 {
778  // BACKMAPPING
779  // get the backmapped point
780 
781  TVector3 localpos;
782  TMatrixD locCov(3,3);
783  Double_t t, b;
784 
785  Double_t errZ = 2.*fGeoH->GetSensorDimensionsShortId(sensorID).Z()/TMath::Sqrt(12.0);
786 
787  TVector2 onsensorPoint =
789  // here we assume the sensor system to be in the _Middle_ of the volume
790  localpos.SetXYZ( onsensorPoint.X(), onsensorPoint.Y(), 0.);
791 
792  // let's see if we're still on the sensor (cut combinations with noise off)
793  if(fabs(localpos.X()) > fabs(fCurrentDigiPar->GetTopAnchor().X())) return kFALSE;
794  if(fabs(localpos.Y()) > fabs(fCurrentDigiPar->GetTopAnchor().Y())) return kFALSE;
795 
796  //do the transformation from sensor to lab frame
797  hitPos = fGeoH->LocalToMasterShortId(localpos,sensorID);
798 
799  // calculate the errors corresponding to a skewed system,
800  // directions orthogonal to strip orientation
803  locCov[0][0]=t*t+b*b;
806  locCov[1][1]=t*t+b*b;
807  locCov[2][2]=errZ*errZ;
808 
809  //do the transformation from sensor to lab frame
810  hitCov = fGeoH->LocalToMasterErrorsShortId(locCov,sensorID);
811  //hitCov = locCov;
812  return kTRUE;
813 }
814 
815 
817 
std::ostream & Print(std::ostream &out=std::cout) const
std::pair< Double_t, Double_t > HeadTail(const PndSdsCluster *Cluster)
int fVerbose
Definition: poormantracks.C:24
std::vector< Int_t > GetClusterList() const
Definition: PndSdsCluster.h:38
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
double dy
PndSdsChargeWeightingAlgorithms * fChargeAlgos
Int_t GetClusterSize() const
Definition: PndSdsCluster.h:39
Int_t GetSensorID() const
Definition: PndSdsDigi.h:59
virtual void Print(const Option_t *opt=0) const
Definition: PndSdsHit.cxx:66
Int_t GetClusterMean() const
Double_t GetSingleChargeCut() const
TString fOutBranchName
Definition: PndSdsTask.h:40
Int_t i
Definition: run_full.C:25
TTree * b
PndGeoHandling * fGeoH
Definition: anasim.C:34
const char * GetSensType() const
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Bool_t SelectSensorParams(Int_t sensorID)
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Int_t GetIndex(int i=0) const
Definition: PndSdsDigi.h:63
PndSdsCalcStrip * fCurrentStripCalcTop
virtual void SetParContainers()
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
TLorentzVector s
Definition: Pnd2DStar.C:50
Class for digitised strip hits.
virtual void InitMQ(TList *tempList)
void SetPersistency(Bool_t val=kTRUE)
std::vector< Int_t > GetLeftDigiIDs() const
Bool_t Backmap(TVector2 meantopPoint, Double_t toperr, TVector2 meanbotPoint, Double_t boterr, TVector3 &hitpos, TMatrixD &hitCov, Int_t &sensorID)
Class for calculating strip indices from wafer hits.
Int_t GetFE() const
Definition: PndSdsDigi.h:57
const TVector2 GetStripDirection() const
TString GetPath(Int_t shortID)
for a given shortID the path is returned
Double_t GetOrient() const
virtual Double_t DigiValueToCharge(Double_t digi)=0
Converts a given digitized charge into charge in electrons.
TVector3 GetSensorDimensionsShortId(Int_t shortId)
std::map< const char *, PndSdsStripClusterer * > fClusterFinderList
void SetChargeConverter(PndSdsChargeConversion *ChargeConverter)
Double_t GetChargeCut() const
std::map< const char *, PndSdsCalcStrip * > fStripCalcBot
TMatrixD LocalToMasterErrorsShortId(const TMatrixD &local, const Int_t &shortId)
Class to access the naming information of the MVD.
Int_t GetDigiIndex(Int_t i) const
Definition: PndSdsCluster.h:40
int strip
Definition: anaMvdDigi.C:135
std::vector< Int_t > GetBotClusterIDs() const
Double_t GetSkew() const
Double_t
TString fInBranchName
Definition: PndSdsTask.h:39
void AddDigi(Int_t sensorID, SensorSide side, Int_t timestamp, Int_t strip, Int_t iDigi)
virtual void SetBranchNames()=0
virtual void ExecMQ(TList *inputList, TList *outputList)
Digitization Parameter Class for MVD-Strip part.
SensorSide
std::pair< Double_t, Double_t > CenterOfGravity(const PndSdsCluster *Cluster)
TString fFolderName
Definition: PndSdsTask.h:41
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
std::vector< Int_t > GetTopClusterIDs() const
virtual void SetParContainersMQ(TList *)
void SetBotIndex(Int_t id)
Definition: PndSdsHit.h:86
static PndGeoHandling * Instance()
Double_t meanerr[nsteps]
Definition: dedx_bands.C:65
TString name
std::map< const char *, PndSdsCalcStrip * > fStripCalcTop
Calculator objects.
PndSensorNamePar * fSensorNamePar
double dx
void SetCurrentCalculators(PndSdsStripDigiPar *digipar)
void SetVerbose(Int_t v)
PndSdsStripDigiPar * fCurrentDigiPar
virtual std::vector< PndSdsClusterStrip * > SearchClusters()=0
void CalcFeChToStrip(Int_t fe, Int_t channel, Int_t &strip, enum SensorSide &side) const
Double_t x
std::pair< Double_t, Double_t > Eta(const PndSdsCluster *Cluster, const TH2F *PosVsEta)
std::map< const char *, PndSdsChargeConversion * > fChargeConverter
std::pair< Double_t, Double_t > Binary(const PndSdsCluster *Cluster)
Double_t GetBotPitch() const
ClassImp(PndAnaContFact)
TVector3 LocalToMasterShortId(const TVector3 &local, const Int_t &shortId)
TTree * t
Definition: bump_analys.C:13
Int_t GetNIndices() const
Definition: PndSdsDigi.h:64
Double_t y
Int_t GetChannel() const
TVector2 GetTopAnchor() const
TList * fDigiParameterList
Digitization Parameters.
void SetCov(TMatrixD cov)
Definition: PndSdsHit.cxx:70
PndSdsCalcStrip * fCurrentStripCalcBot
PndSdsChargeConversion * fCurrentChargeConverter
void CalcMeanCharge(PndSdsClusterStrip *onecluster, Double_t &meanstrip, Double_t &meanerr, Double_t &charge, Double_t &timestamp, Double_t &timestampError)
Double_t GetTopPitch() const
virtual void Exec(Option_t *opt)
PndSdsStripClusterer * fCurrentClusterfinder
Geometry name handling.
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52
Unique match between SensorID and path in TGeoManager.
TVector2 CalcLineCross(TVector2 point1, TVector2 dir1, TVector2 point2, TVector2 dir2) const
void CalcStripPointOnLine(const Double_t strip, TVector2 &point) const