|
| 1 | +/****************************************************************************** |
| 2 | + * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * |
| 3 | + * Copyright (C) 2019-2025 Members of R3B Collaboration * |
| 4 | + * * |
| 5 | + * This software is distributed under the terms of the * |
| 6 | + * GNU General Public Licence (GPL) version 3, * |
| 7 | + * copied verbatim in the file "LICENSE". * |
| 8 | + * * |
| 9 | + * In applying this license GSI does not waive the privileges and immunities * |
| 10 | + * granted to it by virtue of its status as an Intergovernmental Organization * |
| 11 | + * or submit itself to any jurisdiction. * |
| 12 | + ******************************************************************************/ |
| 13 | + |
| 14 | +#include "R3BPWCal2Hit.h" |
| 15 | +#include "TClonesArray.h" |
| 16 | +#include "TMath.h" |
| 17 | +#include "TObjArray.h" |
| 18 | +#include "TRandom.h" |
| 19 | + |
| 20 | +#include "FairLogger.h" |
| 21 | +#include "FairRootManager.h" |
| 22 | +#include "FairRunAna.h" |
| 23 | +#include "FairRuntimeDb.h" |
| 24 | + |
| 25 | +#include "TGeoManager.h" |
| 26 | +#include "TGeoMatrix.h" |
| 27 | + |
| 28 | +#include "R3BPWCalData.h" |
| 29 | +#include <list> |
| 30 | +#include <vector> |
| 31 | + |
| 32 | +R3BPWCal2Hit::R3BPWCal2Hit() |
| 33 | + : FairTask("R3B PW Cal to Hit") |
| 34 | + , fParCont(NULL) |
| 35 | + , fPWCalDataCA(NULL) |
| 36 | + , fPWHitDataCA(NULL) |
| 37 | + , fOnline(kFALSE) |
| 38 | +{ |
| 39 | +} |
| 40 | + |
| 41 | +R3BPWCal2Hit::~R3BPWCal2Hit() |
| 42 | +{ |
| 43 | + LOG(info) << "R3BPWCal2Hit: Delete instance"; |
| 44 | + if (fPWHitDataCA) |
| 45 | + delete fPWHitDataCA; |
| 46 | +} |
| 47 | + |
| 48 | +void R3BPWCal2Hit::SetParContainers() {} |
| 49 | + |
| 50 | +InitStatus R3BPWCal2Hit::Init() |
| 51 | +{ |
| 52 | + |
| 53 | + // Parameter Container |
| 54 | + // Reading PWHitPar from FairRuntimeDb |
| 55 | + FairRuntimeDb* rtdb = FairRuntimeDb::instance(); |
| 56 | + if (!rtdb) |
| 57 | + { |
| 58 | + LOG(error) << "R3BPWCal2Hit:: FairRuntimeDb not opened"; |
| 59 | + } |
| 60 | + |
| 61 | + FairRootManager* rootManager = FairRootManager::Instance(); |
| 62 | + if (!rootManager) |
| 63 | + { |
| 64 | + LOG(fatal) << "R3BPWCal2Hit::FairRootManager not found"; |
| 65 | + return kFATAL; |
| 66 | + } |
| 67 | + |
| 68 | + fHitPar = dynamic_cast<R3BPWHitPar*>(rtdb->getContainer("PWHitPar")); |
| 69 | + if (!fHitPar) |
| 70 | + { |
| 71 | + LOG(error) << "R3BPWCal2Hit::Init() Couldn't get handle on PWHitPar container"; |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + LOG(info) << "R3BPWCal2Hit:: PWHitPar container open"; |
| 76 | + } |
| 77 | + |
| 78 | + fPWCalDataCA = dynamic_cast<TClonesArray*>(rootManager->GetObject("R3BPWCalData")); |
| 79 | + if (!fPWCalDataCA) |
| 80 | + { |
| 81 | + LOG(error) << "R3BPWCal2HitPar::Init() R3BPWCalData not found"; |
| 82 | + return kFATAL; |
| 83 | + } |
| 84 | + |
| 85 | + // Register output array |
| 86 | + fPWHitDataCA = new TClonesArray("R3BPWHitData"); |
| 87 | + rootManager->Register("R3BPWHitData", "PW Bar Hit", fPWHitDataCA, !fOnline); |
| 88 | + |
| 89 | + fParCont = fHitPar->GetCalParams(); |
| 90 | + |
| 91 | + return kSUCCESS; |
| 92 | +} |
| 93 | + |
| 94 | +InitStatus R3BPWCal2Hit::ReInit() |
| 95 | +{ |
| 96 | + SetParContainers(); |
| 97 | + return kSUCCESS; |
| 98 | +} |
| 99 | + |
| 100 | +void R3BPWCal2Hit::Exec(Option_t* opt) |
| 101 | +{ |
| 102 | + Reset(); |
| 103 | + // loop over si data |
| 104 | + Int_t nHits = fPWCalDataCA->GetEntries(); |
| 105 | + UInt_t iDetector = 0; |
| 106 | + double charge_left = -1000; |
| 107 | + double charge_right = -1000; |
| 108 | + double time_left = 0; |
| 109 | + double time_right = 0; |
| 110 | + UInt_t ibar = 0; |
| 111 | + |
| 112 | + for (Int_t i = 0; i < nHits; i++) |
| 113 | + { |
| 114 | + auto map1 = dynamic_cast<R3BPWCalData*>(fPWCalDataCA->At(i)); |
| 115 | + iDetector = map1->GetDetId(); |
| 116 | + |
| 117 | + if (iDetector == 0) |
| 118 | + { |
| 119 | + charge_right = map1->GetTot0(); |
| 120 | + time_right = map1->GetTime0(); |
| 121 | + ibar = map1->GetChannelId(); |
| 122 | + |
| 123 | + charge_left = map1->GetTot1(); |
| 124 | + time_left = map1->GetTime1(); |
| 125 | + |
| 126 | + double position = double(ibar - 1) * (2.3 + 0.2) - 6.35; // relative to pad plane coordinates |
| 127 | + double charge = (charge_left + charge_right) / 2.; |
| 128 | + double time = (time_left + time_right) / 2. + fParCont->GetAt(ibar - 1); |
| 129 | + |
| 130 | + auto tof = time; // will be later relative to start (diamond) |
| 131 | + AddHitBar(iDetector, ibar, time, position, charge, tof); |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +R3BPWHitData* R3BPWCal2Hit::AddHitBar(UInt_t detId, UInt_t channel, double time, double pos, double charge, double tof) |
| 137 | +{ |
| 138 | + |
| 139 | + TClonesArray& clref = *fPWHitDataCA; |
| 140 | + Int_t size = clref.GetEntriesFast(); |
| 141 | + return new (clref[size]) R3BPWHitData(detId, channel, time, pos, charge, tof); |
| 142 | +} |
| 143 | + |
| 144 | +void R3BPWCal2Hit::Reset() |
| 145 | +{ |
| 146 | + LOG(debug) << "Clearing PWHitStructure Structure"; |
| 147 | + if (fPWHitDataCA) |
| 148 | + { |
| 149 | + fPWHitDataCA->Clear(); |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +ClassImp(R3BPWCal2Hit); |
0 commit comments