All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrigInfo_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TrigInfo
3 // Plugin Type: analyzer (art v2_08_04)
4 // File: TrigInfo_module.cc
5 //
6 // Generated at Thu Feb 1 13:27:27 2018 by Andrea Falcone using cetskelgen
7 // from cetlib version v3_01_01.
8 ////////////////////////////////////////////////////////////////////////
9 
10 // ##########################
11 // ### Framework includes ###
12 // ##########################
13 #include "art/Framework/Core/EDAnalyzer.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "fhiclcpp/ParameterSet.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "art/Framework/Principal/SubRun.h"
19 #include "art/Framework/Principal/Handle.h"
20 #include "canvas/Persistency/Common/Ptr.h"
21 #include "canvas/Persistency/Common/PtrVector.h"
22 #include "art/Framework/Services/Registry/ServiceHandle.h"
23 #include "art_root_io/TFileService.h"
24 #include "art_root_io/TFileDirectory.h"
25 #include "canvas/Persistency/Common/FindOneP.h"
26 #include "canvas/Persistency/Common/FindManyP.h"
27 #include "canvas/Utilities/InputTag.h"
28 #include "messagefacility/MessageLogger/MessageLogger.h"
29 //#include "cetlib/maybe_ref.h"
30 
31 // ########################
32 // ### LArSoft includes ###
33 // ########################
35 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
44 #include "lardata/ArtDataHelper/TrackUtils.h" // lar::util::TrackPitchInView()
48 
51 
53 
54 #include "nusimdata/SimulationBase/MCParticle.h"
55 #include "nusimdata/SimulationBase/MCTruth.h"
56 #include "nusimdata/SimulationBase/MCNeutrino.h"
57 
58 #include "nug4/ParticleNavigation/ParticleList.h"
59 
62 
63 // #####################
64 // ### ROOT includes ###
65 // #####################
66 #include "TComplex.h"
67 #include "TFile.h"
68 #include "TH2D.h"
69 #include "TF1.h"
70 #include "TTree.h"
71 #include "TTimeStamp.h"
72 
73 ////////////////////////////////// Define some constant variable //////////////////////////////
74 const int nPMTs = 360;
75 //const int PMTs_per_TPC = 90;
76 const int MaxPhotons = 5000;
77 //const double QE = 0.06;
78 
79 namespace sim{
80  class ParticleList;
81 }
82 
83 namespace icarus {
84  class TrigInfo;
85 }
86 
87 
88 class icarus::TrigInfo : public art::EDAnalyzer {
89 public:
90  explicit TrigInfo(fhicl::ParameterSet const & p);
91  // The compiler-generated destructor is fine for non-base
92  // classes without bare pointers or other resource use.
93 
94  // Plugins should not be copied or assigned.
95  TrigInfo(TrigInfo const &) = delete;
96  TrigInfo(TrigInfo &&) = delete;
97  TrigInfo & operator = (TrigInfo const &) = delete;
98  TrigInfo & operator = (TrigInfo &&) = delete;
99 
100  // Required functions.
101  void analyze(art::Event const & e) override;
102  // Selected optional functions.
103  void beginJob() override;
104  //void reconfigure(fhicl::ParameterSet const & p);
105 
106 private:
107 //TRandom* Ran;
108 
109 TTree* fTree;
110 
111 ////////////////////////////////// Variable in th tree//////////////////////////////
112 
113 int event;
114 
116 
119 
121 
123 
124 double PMTx[nPMTs];
125 double PMTy[nPMTs];
126 double PMTz[nPMTs];
127 
129 int TPC[nPMTs];
130 
134 
136 
137 int nHit;
139 double hit_width[nPMTs];
140 double hit_area[nPMTs];
141 double hit_peak[nPMTs];
142 double hit_phe[nPMTs];
143 
147 
148 double vertex_x;
149 double vertex_y;
150 double vertex_z;
151 
154 
157 
161 
162 art::InputTag photonLabel;
163 art::InputTag chargeLabel;
164 art::InputTag typoLabel;
165 art::InputTag hitLabel;
166 
167 };
168 
169 
170 icarus::TrigInfo::TrigInfo(fhicl::ParameterSet const & p)
171  :
172  EDAnalyzer(p),
173  photonLabel(p.get<art::InputTag>("fottoni", "largeant")),
174  chargeLabel(p.get<art::InputTag>("carconi", "largeant")),
175  typoLabel (p.get<art::InputTag>("tiponi", "generator")),
176  hitLabel (p.get<art::InputTag>("hittoni", "ophit"))
177  // More initializers here.
178 {
179 
180 }
181 
182 
183 void icarus::TrigInfo::analyze(art::Event const & evt)
184 {
185 
186 ////////////////////////////////// Create the LArsoft services and service handle//////////////////////////////
187 
188 art::ServiceHandle<geo::Geometry> geom;
189 
190 std::vector<sim::SimPhotons> const& optical = *(evt.getValidHandle<std::vector<sim::SimPhotons>>(photonLabel));
191 std::vector<sim::SimChannel> const& charge = *(evt.getValidHandle<std::vector<sim::SimChannel>>(chargeLabel));
192 std::vector<recob::OpHit> const& hit = *(evt.getValidHandle<std::vector<recob::OpHit>>(hitLabel));
193 //std::vector<simb::MCTruth> const& type = *(evt.getValidHandle<std::vector<simb::MCTruth>>(typoLabel));
194 
195 ////////////////////////////////// Event number//////////////////////////////
196 
197 event = evt.id().event();
198 
199 //std::vector< art::Handle< std::vector<simb::MCTruth> > > type;
200 //evt.getManyByType(type);
201 auto type = evt.getMany< std::vector<simb::MCTruth> >();
202 
203 for(size_t mcl = 0; mcl < type.size(); ++mcl)
204 {
205  art::Handle< std::vector<simb::MCTruth> > mclistHandle = type[mcl];
206 
207  for(size_t m = 0; m < mclistHandle->size(); ++m)
208  {
209  art::Ptr<simb::MCTruth> mct(mclistHandle, m);
210 // for(int ipart=0;ipart<mct->NParticles();ipart++)
211 // {
212 // int pdg=mct->GetParticle(ipart).PdgCode();
213 // double xx=mct->GetParticle(ipart).Vx();
214 // double yy=mct->GetParticle(ipart).Vy();
215 // double zz=mct->GetParticle(ipart).Vz();
216 
217  event_type=mct->GetParticle(0).PdgCode();
218  vertex_x=mct->GetParticle(0).Vx();
219  vertex_y=mct->GetParticle(0).Vy();
220  vertex_z=mct->GetParticle(0).Vz();
221 
222  if (event_type==12||event_type==-12||event_type==14||event_type==-14||event_type==16||event_type==-16)
223  {
224  is_Neutrino=1;
225  Neutrino_Interaction=mct->GetNeutrino().InteractionType();
226  }
227  else
228  {
229  is_Neutrino=0;
230  Neutrino_Interaction=-9999;
231  }
232 
233 // }
234  }
235 
236 }
237 
238 
239 ////////////////////////////////// Putting at 0 all the variables//////////////////////////////
240 
241 for (int g=0; g<MaxPhotons; g++)
242 {
243  for (int u=0; u<360; u++)
244  {
245  photon_time[u][g]=0;
246  }
247 }
248 
249 true_barycentre_x =0;
250 true_barycentre_y =0;
251 true_barycentre_z =0;
252 
253 total_quenched_energy =0;
254 
255 ////////////////////////////////// Charge part: identify the baricentre of the event //////////////////////////////
256 
257 for (std::size_t chargechannel = 0; chargechannel<charge.size(); ++chargechannel) //loop on SimChannel
258 {
259  auto const& channeltdcide = charge.at(chargechannel).TDCIDEMap();
260 
261  for (std::size_t TDCnu = 0; TDCnu<channeltdcide.size(); ++TDCnu) //loop on TDC
262  {
263 
264  sim::TDCIDE const& tdcide = channeltdcide.at(TDCnu);
265 
266  for (std::size_t IDEnu = 0; IDEnu<tdcide.second.size(); ++IDEnu) //loop on IDE
267  {
268  sim::IDE const& ida = tdcide.second.at(IDEnu);
269 
270 // std::cout << "IDA " << ida.x << '\t' << ida.y << '\t' << ida.z << std::endl;
271 
272  true_barycentre_x = true_barycentre_x + ida.x*ida.energy;
273  true_barycentre_y = true_barycentre_y + ida.y*ida.energy;
274  true_barycentre_z = true_barycentre_z + ida.z*ida.energy;
275  total_quenched_energy = total_quenched_energy + ida.energy;
276 
277  } //loop on IDE
278 
279  } //loop on TDC
280 
281 }//loop on SimChannel
282 
283 true_barycentre_x = true_barycentre_x/total_quenched_energy;
284 true_barycentre_y = true_barycentre_y/total_quenched_energy;
285 true_barycentre_z = true_barycentre_z/total_quenched_energy;
286 
287 total_quenched_energy = total_quenched_energy/3;
288 
289 ////////////////////////////////// Light part //////////////////////////////////////////////////
290 turned_PMT=0;
291 
292 reco_barycentre_y=0;
293 reco_barycentre_z=0;
294 
295 total_coll_photons=0;
296 
297 for (std::size_t channel = 0; channel < optical.size(); ++channel) {
298 
299  sim::SimPhotons const& photon_vec = optical[channel];
300 
301  noPMT[channel] = channel;
302 
303  photons_collected[channel]= photon_vec.size();
304 
305 // double media = photons_collected[channel]*QE;
306 
307 // QE_photons_collected[channel]= Ran.Poisson(media);
308 
309  QE_photons_collected[channel]= 0.06*photons_collected[channel];
310 
311  if (photons_collected[channel]>0){
312 
313  turned_PMT++;
314  }
315 
316  double xyz[3];
317 
318  geom->OpDetGeoFromOpChannel(channel).GetCenter(xyz);
319 
320  PMTx[channel] = xyz[0];
321  PMTy[channel] = xyz[1];
322  PMTz[channel] = xyz[2];
323 
324  reco_barycentre_y = reco_barycentre_y + PMTy[channel]*photons_collected[channel];
325  reco_barycentre_z = reco_barycentre_z + PMTz[channel]*photons_collected[channel];
326  total_coll_photons= total_coll_photons + photons_collected[channel];
327 
328  firstphoton_time[channel] = 100000000;
329 
330  if (photons_collected[channel]>0)
331  {
332  for (size_t i = 0; i<photon_vec.size() && int(i)< MaxPhotons; ++i)
333  {
334  photon_time[channel][i]= photon_vec.at(i).Time;
335 
336  if (photon_time[channel][i]<firstphoton_time[channel])
337  {
338  firstphoton_time[channel]=photon_time[channel][i];
339  }
340  }
341 
342  }
343 
344 
345 // std::cout << PMTx[channel] << '\t' << PMTy[channel] << '\t' << PMTz[channel] << std::endl;
346 
347  if (PMTx[channel]<0){Cryostat[channel]=0;}
348  if (PMTx[channel]>0){Cryostat[channel]=1;}
349 
350  if (PMTx[channel]<-200){TPC[channel]=0;}
351  if (PMTx[channel]>-200 && PMTx[channel]<0){TPC[channel]=1;}
352  if (PMTx[channel]<200 && PMTx[channel]>0){TPC[channel]=2;}
353  if (PMTx[channel]>200){TPC[channel]=3;}
354 
355 }
356 
357 //total_coll_photons = total_coll_photons;
358 
359 //std::cout << " fotoni finale = " <<total_coll_photons <<std::endl;
360 
361 reco_barycentre_y = reco_barycentre_y/total_coll_photons;
362 reco_barycentre_z = reco_barycentre_z/total_coll_photons;
363 
364 
365 PMT_error_y = reco_barycentre_y-true_barycentre_y;
366 PMT_error_z = reco_barycentre_z-true_barycentre_z;
367 PMT_total_error = sqrt((PMT_error_y*PMT_error_y)+(PMT_error_z*PMT_error_z));
368 
369 // optical hit part
370 
371 /*for (int u=0; u<360; u++)
372 {
373 hit_peaktime[u]=-1;
374 hit_width[u]=-1;
375 hit_area[u]=-1;
376 hit_peak[u]=-1;
377 hit_phe[u]=-1;
378 }*/
379 
380 nHit = hit.size();
381 
382 std::cout << "Qua arriva prima del for" << std::endl;
383 
384 for (std::size_t hit_n = 0; hit_n < hit.size(); ++hit_n) {
385 
386  recob::OpHit const& hit_vec = hit[hit_n];
387 
388 
389  std::cout << "apre il vettore numer = " << hit_n << std::endl;
390 
391 
392  noPMT[hit_n] = hit_vec.OpChannel();
393 
394  std::cout << "del canale numer = " << noPMT[hit_n] << std::endl;
395 
396  //int ifhit= noPMT[hit_n];
397 
398  hit_peaktime[hit_n] = hit_vec.PeakTime();
399  hit_width[hit_n] = hit_vec.Width();
400  hit_area[hit_n] = hit_vec.Area();
401  hit_peak[hit_n] = hit_vec.Amplitude();
402  hit_phe[hit_n] = hit_vec.PE();
403 
404  std::cout << "di area uguale a = " << hit_area[hit_n] << std::endl;
405 
406 }
407 
408 fTree->Fill();
409 }
410 
412 {
413 
414 art::ServiceHandle<art::TFileService> tfs;
415 fTree = tfs->make<TTree>("lighttree","tree for the light response");
416 
417 fTree->Branch("event",&event,"event/I");
418 fTree->Branch("event_type",&event_type,"event_type/I");
419 fTree->Branch("is_Neutrino",&is_Neutrino,"is_Neutrino/I");
420 fTree->Branch("Neutrino_Interaction",&Neutrino_Interaction,"Neutrino_Interaction/I");
421 fTree->Branch("total_quenched_energy",&total_quenched_energy,"total_quenched_energy");
422 fTree->Branch("Cryostat",Cryostat,("Cryostat[" + std::to_string(nPMTs) + "]/I").c_str());
423 fTree->Branch("TPC",TPC,("TPC[" + std::to_string(nPMTs) + "]/I").c_str());
424 fTree->Branch("noPMT",noPMT,("noPMT[" + std::to_string(nPMTs) + "]/I").c_str());
425 fTree->Branch("PMTx",PMTx,("PMTx[" + std::to_string(nPMTs) + "]/D").c_str());
426 fTree->Branch("PMTy",PMTy,("PMTy[" + std::to_string(nPMTs) + "]/D").c_str());
427 fTree->Branch("PMTz",PMTz,("PMTz[" + std::to_string(nPMTs) + "]/D").c_str());
428 fTree->Branch("turned_PMT",&turned_PMT,"turned_PMT/I");
429 fTree->Branch("total_coll_photons",&total_coll_photons,"total_coll_photons/I");
430 fTree->Branch("photons_colleted",photons_collected,("photons_collected[" + std::to_string(nPMTs) + "]/F").c_str());
431 fTree->Branch("QE_photons_colleted",QE_photons_collected,("QE_photons_collected[" + std::to_string(nPMTs) + "]/F").c_str());
432 fTree->Branch("firstphoton_time",firstphoton_time,("firstphoton_time[" + std::to_string(nPMTs) + "]/F").c_str());
433 //fTree->Branch("photon_time",&photon_time,"photon_time[360][10000]/F");
434 
435 fTree->Branch("nHit",&nHit,"nHit/I");
436 fTree->Branch("hit_peaktime",hit_peaktime,("hit_peaktime[" + std::to_string(nPMTs) + "]/D").c_str());
437 fTree->Branch("hit_width",hit_width,("hit_width[" + std::to_string(nPMTs) + "]/D").c_str());
438 fTree->Branch("hit_area",hit_area,("hit_area[" + std::to_string(nPMTs) + "]/D").c_str());
439 fTree->Branch("hit_peak",hit_peak,("hit_peak[" + std::to_string(nPMTs) + "]/D").c_str());
440 fTree->Branch("hit_phe",hit_phe,("hit_phe[" + std::to_string(nPMTs) + "]/D").c_str());
441 
442 fTree->Branch("vertex_x",&vertex_x,"vertex_x/D");
443 fTree->Branch("vertex_y",&vertex_y,"vertex_y/D");
444 fTree->Branch("vertex_z",&vertex_z,"vertex_z/D");
445 fTree->Branch("true_barycentre_x",&true_barycentre_x,"true_barycentre_x/F");
446 fTree->Branch("true_barycentre_y",&true_barycentre_y,"true_barycentre_y/F");
447 fTree->Branch("true_barycentre_z",&true_barycentre_z,"true_barycentre_z/F");
448 fTree->Branch("reco_barycentre_y",&reco_barycentre_y,"reco_barycentre_y/F");
449 fTree->Branch("reco_barycentre_z",&reco_barycentre_z,"reco_barycentre_z/F");
450 fTree->Branch("PMT_error_y",&PMT_error_y,"PMT_error_y/F");
451 fTree->Branch("PMT_error_z",&PMT_error_z,"PMT_error_z/F");
452 fTree->Branch("PMT_total_error",&PMT_total_error,"PMT_total_error/F");
453 }
454 DEFINE_ART_MODULE(icarus::TrigInfo)
float z
z position of ionization [cm]
Definition: SimChannel.h:121
art::InputTag hitLabel
double PMTx[nPMTs]
std::pair< unsigned short, std::vector< sim::IDE > > TDCIDE
List of energy deposits at the same time (on this channel)
Definition: SimChannel.h:127
double hit_phe[nPMTs]
float photon_time[nPMTs][MaxPhotons]
Declaration of signal hit object.
float photons_collected[nPMTs]
pdgs p
Definition: selectors.fcl:22
art::InputTag photonLabel
double PMTy[nPMTs]
Class to keep data related to recob::Hit associated with recob::Track.
double PeakTime() const
Definition: OpHit.h:88
process_name hit
Definition: cheaterreco.fcl:51
double hit_peaktime[nPMTs]
BEGIN_PROLOG g
float x
x position of ionization [cm]
Definition: SimChannel.h:119
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
BEGIN_PROLOG TPC
double hit_peak[nPMTs]
void analyze(art::Event const &e) override
Simulation objects for optical detectors.
double Width() const
Definition: OpHit.h:92
double PMTz[nPMTs]
Ionization at a point of the TPC sensitive volume.
Definition: SimChannel.h:86
void beginJob() override
float energy
energy deposited by ionization by this track ID and time [MeV]
Definition: SimChannel.h:118
double Amplitude() const
Definition: OpHit.h:94
float QE_photons_collected[nPMTs]
Declaration of cluster object.
Definition of data types for geometry description.
Provides recob::Track data product.
double PE() const
Definition: OpHit.h:95
float y
y position of ionization [cm]
Definition: SimChannel.h:120
double hit_area[nPMTs]
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
TrigInfo & operator=(TrigInfo const &)=delete
std::string to_string(WindowPattern const &pattern)
art::InputTag chargeLabel
const int MaxPhotons
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
Declaration of basic channel signal object.
double Area() const
Definition: OpHit.h:93
double hit_width[nPMTs]
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8
art::InputTag typoLabel
int OpChannel() const
Definition: OpHit.h:86
Utility functions to extract information from recob::Track
const int nPMTs
Tools and modules for checking out the basics of the Monte Carlo.
float firstphoton_time[nPMTs]
TrigInfo(fhicl::ParameterSet const &p)
art framework interface to geometry description
BEGIN_PROLOG could also be cout